< Summary

Information
Line coverage
100%
Covered lines: 5
Uncovered lines: 0
Coverable lines: 5
Total lines: 47
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
HasEnoughSpace(...)100%44100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.IO/Extensions/DriveExtensions.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="DriveExtensions.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System.IO;
 8
 9#pragma warning disable IDE0130 // Namespace does not match folder structure
 10namespace MyNet.IO;
 11#pragma warning restore IDE0130 // Namespace does not match folder structure
 12
 13/// <summary>
 14/// Result codes used by disk drive checks.
 15/// </summary>
 16public enum DiskDriveInfo
 17{
 18    /// <summary>No error detected.</summary>
 19    NoError,
 20
 21    /// <summary>Drive is not found or not ready.</summary>
 22    DiskNotFound,
 23
 24    /// <summary>Drive has not enough free space for requested operation.</summary>
 25    InsufficientSpace
 26}
 27
 28/// <summary>
 29/// Extension methods for <see cref="DriveInfo"/>.
 30/// </summary>
 31public static class DriveExtensions
 32{
 33    extension(DriveInfo driveInfo)
 34    {
 35        /// <summary>
 36        /// Checks whether the drive has at least the requested amount of free space.
 37        /// </summary>
 38        /// <param name="space">Minimum required free space in bytes.</param>
 39        /// <returns>A <see cref="DiskDriveInfo"/> value describing the result.</returns>
 1540        public DiskDriveInfo HasEnoughSpace(double space) => !driveInfo.IsReady
 1541            ? DiskDriveInfo.DiskNotFound
 1542            : driveInfo.TotalFreeSpace >= space
 1543                ? DiskDriveInfo.NoError
 1544                : DiskDriveInfo.InsufficientSpace;
 45    }
 46}
 47