Skip to content

How to write a test that checks for insufficient space available? #826

Description

@FroggieFrog

Describe the bug
I need to write a test for some logic that checks if there is enough space available on disk.

To Reproduce

logic to test
privateIFileSystem_fileSystem;//injected in ctor as = new MockFileSystem() in tests | = new FileSystem() in productionvarrequiredSpace=calculateActualSize(filePaths);varavailableFreeSpace=getAvailableFreeSpaceOnDisk(driveName);if(availableFreeSpace<requiredSpace){//throw exception}privatelonggetAvailableFreeSpaceOnDisk(stringdriveName){vardriveInfo=_fileSystem.DriveInfo.FromDriveName(driveName);varresult=driveInfo.AvailableFreeSpace;returnresult;}
test code so far (does not work)
[Fact]publicvoidRequiredSpaceIsInsufficient_ShouldThrow(){// ArrangevarfileSystem=newMockFileSystem();fileSystem.AddDirectory(@"Q:\Destination");fileSystem.AddFile(@"W:\source\test.txt",newMockFileData(newbyte[2]));vardriveInfo=newMockDriveInfo(fileSystem,"Q");driveInfo.AvailableFreeSpace=1;// Act varex=Record.Exception(()=>newClassToTest(fileSystem).MethodToTest());// AssertAssert.IsType<ExpectedExceptionType>(ex);}

Actual behavior
The injected IFileSystem has a DriveInfo with AvailableFreeSpace set to 0.

Expected behavior
The injected IFileSystem has a DriveInfo with AvailableFreeSpace set to 1.

Additional context
I did some search and found a comment on issue #274, but I'm still unable to understand how to write a functioning test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions