Exemplo n.º 1
0
        [TestMethod] public void Construct()
        {
            // Arrange
            var mockExtractor = new Mock <IFieldExtractor>();

            mockExtractor.Setup(e => e.ExpectedSource).Returns(typeof(string));
            mockExtractor.Setup(e => e.FieldType).Returns(typeof(int));
            var conv = DataConverter.Identity <int>();

            // Act
            var step = new PrimitiveExtractionStep(mockExtractor.Object, conv);

            // Assert
            step.ExpectedSource.Should().Be(typeof(string));
        }
Exemplo n.º 2
0
        [TestMethod] public void ExtractFromNull()
        {
            // Arrange
            var result        = 10;
            var mockExtractor = new Mock <IFieldExtractor>();

            mockExtractor.Setup(e => e.ExpectedSource).Returns(typeof(string));
            mockExtractor.Setup(e => e.FieldType).Returns(typeof(int));
            mockExtractor.Setup(e => e.Execute(It.IsAny <string>())).Returns(result);
            var    conv   = DataConverter.Identity <int>();
            var    step   = new PrimitiveExtractionStep(mockExtractor.Object, conv);
            string?source = null;

            // Act
            var value = step.Execute(source);

            // Assert
            value.Should().BeEquivalentTo(new DBValue[] { DBValue.NULL });
        }
Exemplo n.º 3
0
        [TestMethod] public void ExtractFromDerived()
        {
            // Arrange
            var result        = 10;
            var mockExtractor = new Mock <IFieldExtractor>();

            mockExtractor.Setup(e => e.ExpectedSource).Returns(typeof(Exception));
            mockExtractor.Setup(e => e.FieldType).Returns(typeof(int));
            mockExtractor.Setup(e => e.Execute(It.IsAny <Exception>())).Returns(result);
            var conv   = DataConverter.Identity <int>();
            var step   = new PrimitiveExtractionStep(mockExtractor.Object, conv);
            var source = new NullReferenceException();

            // Act
            var value = step.Execute(source);

            // Assert
            mockExtractor.Verify(e => e.Execute(source), Times.Once);
            value.Should().BeEquivalentTo(new DBValue[] { DBValue.Create(result) });
        }
Exemplo n.º 4
0
        [TestMethod] public void ExtractWithNonIdentityConversion()
        {
            // Arrange
            var result        = 10;
            var mockExtractor = new Mock <IFieldExtractor>();

            mockExtractor.Setup(e => e.ExpectedSource).Returns(typeof(string));
            mockExtractor.Setup(e => e.FieldType).Returns(typeof(int));
            mockExtractor.Setup(e => e.Execute(It.IsAny <string>())).Returns(result);
            var conv   = DataConverter.Create <int, int>(i => i * 2);
            var step   = new PrimitiveExtractionStep(mockExtractor.Object, conv);
            var source = "Detroit";

            // Act
            var value = step.Execute(source);

            // Assert
            mockExtractor.Verify(e => e.Execute(source), Times.Once);
            value.Should().BeEquivalentTo(new DBValue[] { DBValue.Create(conv.Convert(result)) });
        }