public void Ctor_DirectoryWithSubDirectories_ReplacesFilesUnderNeath() { //arrange using (var writer = File.CreateText("PageTemplate.ascx")) { writer.Write(@"<%@ Register TagPrefix=""SP"" Namespace=""Subtext.Web.Controls"" Assembly=""Subtext.Web.Controls"" %>"); } var existingCustomSkinFile = new SubtextFile(new FileInfo("PageTemplate.ascx")); var files = new List <IFile> { existingCustomSkinFile }; var sourceDirectory = new Mock <IDirectory>(); var subDirectory = new Mock <IDirectory>(); subDirectory.Setup(s => s.GetFiles()).Returns(files); var directories = new List <IDirectory> { subDirectory.Object }; sourceDirectory.Setup(s => s.GetDirectories()).Returns(directories); var upgrader = new SkinUpgrader(sourceDirectory.Object); // act upgrader.Run(); //assert using (var reader = new StreamReader(File.OpenRead("PageTemplate.ascx"))) { const string expected = @"<%@ Register TagPrefix=""SP"" Namespace=""Subtext.Web.Controls"" Assembly=""Subtext.Web"" %>"; var text = reader.ReadToEnd(); Assert.AreEqual(expected, text); } }
private static IDirectory GetSourceDirectory() { using (var writer = File.CreateText("PageTemplate.ascx")) { writer.Write(@"<%@ Register TagPrefix=""SP"" Namespace=""Subtext.Web.Controls"" Assembly=""Subtext.Web.Controls"" %>"); writer.Write(@"my other content"); } var existingCustomSkinFile = new SubtextFile(new FileInfo("PageTemplate.ascx")); var files = new List <IFile> { existingCustomSkinFile }; var sourceDirectory = new Mock <IDirectory>(); sourceDirectory.Setup(s => s.GetFiles()).Returns(files); return(sourceDirectory.Object); }
public void OpenWrite_OnFileWithContents_ClearsContentsFirst() { // arrange using (var writer = File.CreateText(@"test.txt")) { writer.Write("0123456789"); } var file = new SubtextFile(new FileInfo("test.txt")); // act using (var writer = new StreamWriter(file.OpenWrite())) { writer.Write("abcdef"); } // assert using (var reader = new StreamReader(File.OpenRead("test.txt"))) { string text = reader.ReadToEnd(); Assert.AreEqual("abcdef", text); } }