public void DetectorResponseToInvalidXml()
        {
            // Arrange
            var d1 = new Mock<IXmlVersionDetector>();
            var detector = new XmlVersionDetector(new[] { d1.Object });

            // Act
            var candidate = detector.DetectSchemaVersion("<test>");

            // Assert
            Assert.AreEqual(string.Empty, candidate);
        }
        public void DetectorReturnsChildEmpty()
        {
            // Arrange
            var mockValidator = new Mock<IXmlVersionDetector>();
            var validator = new XmlVersionDetector(new[] { mockValidator.Object });
            var xml = "<test></test>";

            // Act
            var candidate = validator.DetectSchemaVersion(xml);

            // Assert
            Assert.AreEqual(string.Empty, candidate);
        }
        public void DetectorResponseToNull()
        {
            // Arrange
            var d1 = new Mock<IXmlVersionDetector>(MockBehavior.Strict);
            var detector = new XmlVersionDetector(new[] { d1.Object });

            string result = null;
            d1.Setup(x => x.DetectSchemaVersion(It.IsAny<XElement>())).Returns(result);

            // Act
            var candidate = detector.DetectSchemaVersion(this.sampleXml);

            // Assert
            Assert.AreEqual(string.Empty, candidate);
        }
        public void ChildDetectorDetectsSchema()
        {
            // Arrange
            var mockValidator = new Mock<IXmlVersionDetector>();
            var validator = new XmlVersionDetector(new[] { mockValidator.Object });
            var xml = "<test></test>";

            mockValidator.Setup(x => x.DetectSchemaVersion(It.IsAny<XElement>())).Returns("test");

            // Act
            var candidate = validator.DetectSchemaVersion(xml);

            // Assert
            Assert.AreEqual("test", candidate);
        }
        public void DetectorTranslatesDetectorSchemaUnknown()
        {
            // Arrange
            var mockValidator = new Mock<IXmlVersionDetector>();
            var validator = new XmlVersionDetector(new[] { mockValidator.Object });
            var xml = "<test></test>";

            mockValidator.Setup(x => x.DetectSchemaVersion(It.IsAny<XElement>())).Returns("test.Unknown");

            // Act
            var candidate = validator.DetectSchemaVersion(xml);

            // Assert
            Assert.AreEqual(string.Empty, candidate);
        }
        public void InvalidXmlRaisesException()
        {
            // Arrange
            var mockValidator = new Mock<IXmlVersionDetector>();
            var validator = new XmlVersionDetector(new[] { mockValidator.Object });
            var xml = "<test></tests>";

            // Act
            try
            {
                validator.DetectSchemaVersion(xml);

                throw new NotImplementedException("No exception");
            }
            catch (NotSupportedException)
            {
            }
        }
        public void IgnoreDetectorException()
        {
            // Arrange
            var mockValidator = new Mock<IXmlVersionDetector>();
            var mockValidator2 = new Mock<IXmlVersionDetector>();
            var validator = new XmlVersionDetector(new[] { mockValidator.Object, mockValidator2.Object });
            var xml = "<test></test>";

            mockValidator.Setup(x => x.DetectSchemaVersion(It.IsAny<XElement>())).Throws<NotImplementedException>();
            mockValidator2.Setup(x => x.DetectSchemaVersion(It.IsAny<XElement>())).Returns("test");

            // Act
            var candidate = validator.DetectSchemaVersion(xml);

            // Assert
            Assert.AreEqual("test", candidate);
        }
        public void DetectorResponseToVersion()
        {
            // Arrange
            var d1 = new Mock<IXmlVersionDetector>();
            var detector = new XmlVersionDetector(new[] { d1.Object });

            string result = "Cts.V2_1";
            d1.Setup(x => x.DetectSchemaVersion(It.IsAny<XElement>())).Returns(result);

            // Act
            var candidate = detector.DetectSchemaVersion(this.sampleXml);

            // Assert
            Assert.AreEqual(result, candidate);
        }