public void FileExists_ArgNotNullExistingFileName_ReturnsArgument() { const string fileName = @"C:\temp_dir\test.txt"; var mockFileSystem = new MockFileSystemEx( new Dictionary <string, MockFileData> { { fileName, MockFileData.NullObject } }, @"C:\"); mockFileSystem.Install(); // Act var argument = Ensure.Argument(fileName, nameof(fileName)).NotNull().FileExists(); // Assert argument .Should() .BeOfType <ArgumentNotNull <string> >(); argument.Value .Should() .Be(fileName); }
private static void InstallDemoFileSys() { var fileSystem = new MockFileSystemEx(); fileSystem.AddFile(@"c:\temp\data.config", new MockFileData("{\"Text\":\"DemoDataValue\"}")); fileSystem.Install(); }
public void DirectoryExists_NoneExistingDirectory_ThrowsException() { const string fileName = @"C:\temp_dir\test.txt"; var mockFileSystem = new MockFileSystemEx(); mockFileSystem.Install(); Assert.Throws <DirectoryNotFoundException>(() => Ensure.DirectoryExists(Path.GetDirectoryName(fileName))); }
public void FileExists_NoneExistingFile_ThrowsException() { const string fileName = @"C:\temp_dir\test.txt"; var mockFileSystem = new MockFileSystemEx(); mockFileSystem.Install(); Assert.Throws <FileNotFoundException>(() => Ensure.FileExists(fileName)); }
public void Read_WithFileName_ReturnsFileContent() { const string fileContent = "public void Test(){}"; const string fileName = @"c:\temp\test.cs"; var fileSystem = new MockFileSystemEx(); fileSystem.AddFile(fileName, new MockFileData(fileContent)); fileSystem.Install(); var sourceCode = new FileSourceCode(fileName); Assert.Equal(fileContent, sourceCode.Read()); }
public void FileExists_ExistingFile_PassWithoutException() { const string fileName = @"C:\temp_dir\test.txt"; var mockFileSystem = new MockFileSystemEx( new Dictionary <string, MockFileData> { { fileName, MockFileData.NullObject } }, @"C:\"); mockFileSystem.Install(); Ensure.FileExists(fileName); }
public void DirectoryExists_ExistingDirectory_PassWithoutException() { const string dirName = @"C:\temp_dir"; const string fileName = dirName + @"\test.txt"; var mockFileSystem = new MockFileSystemEx( new Dictionary <string, MockFileData> { { fileName, MockFileData.NullObject } }, @"C:\"); mockFileSystem.Install(); Ensure.DirectoryExists(dirName); }
public void FromFilesTest() { var fileSystem = new MockFileSystemEx(); fileSystem.AddFile(@"c:\temp\data0.config", new MockFileData("{\"Text\":\"DemoDataValue0\"}")); fileSystem.AddFile(@"c:\temp\data1.config", new MockFileData("{\"Text\":\"DemoDataValue1\"}")); fileSystem.Install(); var sources = JsonConfigurationSource <DemoSetting> .FromFiles(new[] { @"c:\temp\data0.config", @"c:\temp\data1.config" }).ToArray(); Assert.Equal(2, sources.Length); Assert.Contains("DemoDataValue0", sources.Select(source => (source.GetSettingObject() as DemoSetting)?.Text)); Assert.Contains("DemoDataValue1", sources.Select(source => (source.GetSettingObject() as DemoSetting)?.Text)); }
public void FileExists_ArgNotNullNotExistingFileName_ThrowsException() { const string fileName = @"C:\temp_dir\test.txt"; var mockFileSystem = new MockFileSystemEx( new Dictionary <string, MockFileData>(), @"C:\"); mockFileSystem.Install(); // Act Action act = () => Ensure.Argument(fileName, nameof(fileName)).NotNull().FileExists(); // Assert act .Should() .Throw <FileNotFoundException>(); }
public void DirectoryExists_NullDirectoryName_ThrowsException() { const string?directoryName = null; var mockFileSystem = new MockFileSystemEx( new Dictionary <string, MockFileData>(), @"C:\"); mockFileSystem.Install(); // Act Action act = () => Ensure.Argument(directoryName, nameof(directoryName)).DirectoryExists(); // Assert act .Should() .Throw <ArgumentNullException>(); }
public void DirectoryExists_ArgNotNullNotExistingDirectoryName_ThrowsException() { const string directoryName = @"C:\Temp12"; var mockFileSystem = new MockFileSystemEx( new Dictionary <string, MockFileData>(), @"C:\"); mockFileSystem.Install(); // Act Action act = () => Ensure.Argument(directoryName, nameof(directoryName)).NotNull().DirectoryExists(); // Assert act .Should() .Throw <DirectoryNotFoundException>(); }