public override void WriteAllText(string fileName, string content, string key)
        {
            if (!AllowOverwrite[key])
            {
                return;
            }

            if (RunInMemory[key])
            {
                if (!Exists(fileName, key))
                {
                    if (AllowOverwrite[key])
                    {
                        InMemoryFileSystem.Add(fileName, content);
                    }
                }

                if (AllowOverwrite[key])
                {
                    InMemoryFileSystem[fileName] = content;
                }

                return;
            }

            File.WriteAllText(fileName, content);
        }
예제 #2
0
        public void TestModifyFile_InvokesProcessor()
        {
            const string input = @"{
  ""file"": [ ""test1.html"", ""test2.html"" ],
  ""template"":  [""templates/**.html""],
  ""content"": [""**.html""]
    }
";
            var fileSystem = new InMemoryFileSystem(new[]
            {
                "test1.html", "test2.html", "templates/tmpl1.html", "templates/tmpl2.html"
            });

            const string filePath = "templates/tmpl3.html";
            const string filePath2 = "content.html";
            var result = Project.FromFile(input, fileSystem);

            var processor = new Mock<IProjectObserver>(MockBehavior.Strict);
            processor.Setup(f =>
                f.NotifyItemAdded(result, It.Is<FileProjectItem>(i => i.FileInfo.FilePath.ToString() == filePath && i.Identifier.Kind == "template")));
            processor.Setup(f =>
                f.NotifyItemAdded(result, It.Is<FileProjectItem>(i => i.FileInfo.FilePath.ToString() == filePath && i.Identifier.Kind == "content")));
            processor.Setup(f =>
                f.NotifyItemAdded(result, It.Is<FileProjectItem>(i => i.FileInfo.FilePath.ToString() == filePath2 && i.Identifier.Kind == "content")));

            processor.Setup(f =>
                f.NotifyItemRemoved(result, It.Is<FileProjectItem>(i => i.FileInfo.FilePath.ToString() == filePath2 && i.Identifier.Kind == "content")));

            result.AddObserver(processor.Object);

            fileSystem.Add(filePath);
            // Not included file
            fileSystem.Add("templates/test.json");

            fileSystem.Add(filePath2);

            fileSystem.RemoveFile(PathInfo.Create(filePath2));

            processor.VerifyAll();
        }