Esempio n. 1
0
            public void WhenMergeFile_IfOverrideNull_ShouldThrow()
            {
                // Arrange
                var xmlHelper = new XmlHelper();

                // Act       
                // Assert
                Assert.Throws<ArgumentNullException>(() => xmlHelper.MergeXmlFiles(@"somefilepath", null));
            }
Esempio n. 2
0
            public void WhenMergeFile_IfSourceNull_ShouldThrow()
            {
                // Arrange
                var xmlHelper = new XmlHelper();

                // Act       
                // Assert
                Assert.Throws<ArgumentNullException>(() => xmlHelper.MergeXmlFiles(null, null));
            }
Esempio n. 3
0
            public void VerifyMergeStringXml(string sourceXml, string overrideXml, string[] collectionElementNames,
                                    string expectedXml)
            {
                // Arrange 
                // Act 
                var xmlHelper = new XmlHelper();
                var actualXml = xmlHelper.MergeXml(sourceXml, overrideXml, collectionElementNames);

                // Assert
                Assert.Equal(expectedXml, actualXml);
            }
Esempio n. 4
0
            public void WhenMergeFile_IfSourceNotExist_ShouldThrow()
            {
                // Arrange
                var mockFileSystem = new Mock<IFileSystem>(MockBehavior.Strict);
                mockFileSystem.Setup(m => m.FileExists(@"somefilepath")).Returns(false);

                var xmlHelper = new XmlHelper(mockFileSystem.Object);

                // Act       
                // Assert
                var exception = Assert.Throws<FileNotFoundException>(
                        () => xmlHelper.MergeXmlFiles(@"somefilepath", @"overridefilepath")); 
                Assert.Equal("File does not exist 'somefilepath'.", exception.Message);
            }
        internal static void AddReferencesToConfig(IFileSystem fileSystem, string referenceName)
        {
            var webConfigPath = Path.Combine(fileSystem.Root, "web.config");

            XmlHelper xmlHelper = new XmlHelper();
            string assemblyXpath = String.Format(@"/configuration/system.web/compilation/assemblies/add[@assembly=""{0}""]", referenceName);

            string document;
            bool existingAssembly = false;
            if (fileSystem.FileExists(webConfigPath))
            {
                document = ReadDocument(fileSystem, webConfigPath);
                existingAssembly = xmlHelper.XmlContainsElement(document, assemblyXpath);
            }
            else
            {
                document = "<configuration />";
            }

            if (!existingAssembly)
            {
                var newDocument = String.Format(@"<configuration>
    <system.web>
        <compilation>
            <assemblies>
                <add assembly=""{0}"" />
            </assemblies>
        </compilation>
    </system.web>
</configuration>", referenceName);

                string combinedConfig = xmlHelper.MergeXml(newDocument, document);

                SaveDocument(fileSystem, webConfigPath, combinedConfig);
            }
        }
Esempio n. 6
0
            public void XpathQueryInvalid_ShouldThrow()
            {
                var xmlHelper = new XmlHelper();

                Assert.Throws<XPathException>(() => xmlHelper.XmlContainsElement("<root />", "////"));
            }
Esempio n. 7
0
            public void XpathQueryNull_ShouldThrow()
            {
                var xmlHelper = new XmlHelper();

                Assert.Throws<ArgumentNullException>(() => xmlHelper.XmlContainsElement("<root />", null));
            }
Esempio n. 8
0
            public void XmlIsInvalid_ShouldThrow()
            {
                var xmlHelper = new XmlHelper();

                Assert.Throws<XmlException>(() => xmlHelper.XmlContainsElement("<root>", ""));
            }
Esempio n. 9
0
            public void XmlIsEmpty_ShouldThrow()
            {
                var xmlHelper = new XmlHelper();

                Assert.Throws<XmlException>(() => xmlHelper.XmlContainsElement("", ""));
            }
Esempio n. 10
0
            public void XmlIsNull_ShouldThrow()
            {
                var xmlHelper = new XmlHelper();

                Assert.Throws<ArgumentNullException>(() => xmlHelper.XmlContainsElement(null, ""));
            }
Esempio n. 11
0
            public void FileDoesNotExist_ShouldThrow()
            {
                var xmlHelper = new XmlHelper();

                Assert.Throws<FileNotFoundException>(() => xmlHelper.FileContainsElement("dummy.xml", ""));
            }
Esempio n. 12
0
            public void VerifyContainsElement(string xml, string element, bool expected)
            {
                var xmlHelper = new XmlHelper();

                var result = xmlHelper.XmlContainsElement(xml, element);

                Assert.Equal(expected, result);
            }