Esempio n. 1
0
            public void InsertBeforeClearTag()
            {
                //arrange
                string configContent  = @"<configuration><system.web><compilation><assemblies><clear /></assemblies></compilation></system.web></configuration>";
                string finalWebConfig = "";
                var    mockFileSystem = new Mock <global::NuGet.IFileSystem>(MockBehavior.Strict);

                mockFileSystem.Setup(fs => fs.FileExists("web.config")).Returns(true);
                mockFileSystem.Setup(fs => fs.Root).Returns("");
                mockFileSystem.Setup(fs => fs.OpenFile("web.config")).Returns(new MemoryStream(System.Text.Encoding.Default.GetBytes(configContent)));
                // and we need to intercept the result when it is saved
                mockFileSystem.Setup(fs => fs.AddFile("web.config", It.IsAny <Stream>()))
                .Callback <string, Stream>((wc, stream) =>
                {
                    finalWebConfig = new StreamReader(stream).ReadToEnd();
                });

                // act
                NuGetWebProjectSystem.AddReferencesToConfig(mockFileSystem.Object, "FooAssembly");

                // assert
                string expected = @"<configuration><system.web><compilation><assemblies><add assembly=""FooAssembly"" /><clear /></assemblies></compilation></system.web></configuration>";

                Assert.Equal <string>(expected, finalWebConfig);
            }
Esempio n. 2
0
            public void EmptyWebConfig()
            {
                //arrange
                string configContent  = @"";
                var    mockFileSystem = new Mock <global::NuGet.IFileSystem>(MockBehavior.Strict);

                mockFileSystem.Setup(fs => fs.FileExists("web.config")).Returns(true);
                mockFileSystem.Setup(fs => fs.Root).Returns("");
                mockFileSystem.Setup(fs => fs.OpenFile("web.config")).Returns(new MemoryStream(System.Text.Encoding.Unicode.GetBytes(configContent)));

                Assert.Throws <XmlException>(() => NuGetWebProjectSystem.AddReferencesToConfig(mockFileSystem.Object, "FooAssembly"));
            }
Esempio n. 3
0
            public void NoChangeIfAssemblyExists()
            {
                //arrange
                string configContent  = @"<configuration><system.web><compilation><assemblies><add assembly=""FooAssembly"" /></assemblies></compilation></system.web></configuration>";
                var    mockFileSystem = new Mock <global::NuGet.IFileSystem>(MockBehavior.Strict);

                mockFileSystem.Setup(fs => fs.FileExists("web.config")).Returns(true);
                mockFileSystem.Setup(fs => fs.Root).Returns("");
                mockFileSystem.Setup(fs => fs.OpenFile("web.config")).Returns(new MemoryStream(System.Text.Encoding.Default.GetBytes(configContent)));

                // act
                // assert: Moq's strict behavior will verify AddFile is not called
                NuGetWebProjectSystem.AddReferencesToConfig(mockFileSystem.Object, "FooAssembly");
            }
Esempio n. 4
0
            public void NoWebConfig()
            {
                string finalWebConfig = "";
                var    mockFileSystem = new Mock <global::NuGet.IFileSystem>(MockBehavior.Strict);

                mockFileSystem.Setup(fs => fs.FileExists("web.config")).Returns(false);
                mockFileSystem.Setup(fs => fs.Root).Returns("");
                mockFileSystem.Setup(fs => fs.AddFile("web.config", It.Is <Stream>((s) => true)))
                .Callback <string, Stream>((wc, stream) =>
                {
                    finalWebConfig = new StreamReader(stream).ReadToEnd();
                });

                NuGetWebProjectSystem.AddReferencesToConfig(mockFileSystem.Object, "FooAssembly");

                string expected = @"<configuration><system.web><compilation><assemblies><add assembly=""FooAssembly"" /></assemblies></compilation></system.web></configuration>";

                Assert.Equal <string>(expected, finalWebConfig);
            }