public void Accessing_a_readonly_file_should_work_as_expected() { /* Arrange */ var doc = new XDocument(); string fileName = "testro.xml"; string newFileName = "testronew.xml"; TestConfigFactory.CreateXmlFile(fileName, "<configuration />", true); TestConfigFactory.CreateXmlFile(newFileName, "<configuration />", true); var p = new FileConfigProvider(fileName); /* Act */ Action a1 = () => p.DeleteConfig(); Action a2 = () => p.SaveConfig(doc); /* Assert */ p.CanDelete.Should().BeFalse(); p.IsReadOnly.Should().BeTrue(); p.ModifiedSinceLoad.Should().BeFalse(); a1.ShouldThrow<InvalidOperationException>(); a2.ShouldThrow<UnauthorizedAccessException>(); }
public void Deleting_a_writable_file_should_wok() { /* Arrange */ string fileName = "testdel.xml"; TestConfigFactory.CreateXmlFile(fileName, "<configuration />", false); var p = new FileConfigProvider(fileName); /* Act */ bool existsPre = File.Exists(fileName); p.DeleteConfig(); bool existsPost = File.Exists(fileName); /* Assert */ existsPre.Should().BeTrue(); existsPost.Should().BeFalse(); }