[TestMethod] public void ExtractFromNull() { // Arrange var v = 100; var value = DBValue.Create(v); var mockExtractor = new Mock <IFieldExtractor>(); mockExtractor.Setup(e => e.ExpectedSource).Returns(typeof(string)); mockExtractor.Setup(e => e.FieldType).Returns(typeof(Exception)); mockExtractor.Setup(e => e.Execute(null)).Returns(null); var mockDecomp = new Mock <IExtractionStep>(); mockDecomp.Setup(d => d.ExpectedSource).Returns(typeof(Exception)); mockDecomp.Setup(d => d.Execute(It.IsAny <int>())).Returns(new DBValue[] { value, value }); mockDecomp.Setup(d => d.Execute(null)).Returns(new DBValue[] { DBValue.NULL, DBValue.NULL }); var decomps = new IExtractionStep[] { mockDecomp.Object }; var step = new DecomposingExtractionStep(mockExtractor.Object, decomps); string?source = null; // Act var values = step.Execute(source); // Assert values.Should().BeEquivalentTo(new DBValue[] { DBValue.NULL, DBValue.NULL }); }
[TestMethod] public void DecomposeWithMultipleSteps() { // Arrange var v = 100; var value0 = DBValue.Create(v); var value1 = DBValue.Create(v * 10); var mockExtractor = new Mock <IFieldExtractor>(); mockExtractor.Setup(e => e.ExpectedSource).Returns(typeof(string)); mockExtractor.Setup(e => e.FieldType).Returns(typeof(Exception)); mockExtractor.Setup(e => e.Execute(It.IsAny <string>())).Returns(v); var mockDecomp0 = new Mock <IExtractionStep>(); mockDecomp0.Setup(d => d.ExpectedSource).Returns(typeof(Exception)); mockDecomp0.Setup(d => d.Execute(It.IsAny <int>())).Returns(new DBValue[] { value0 }); var mockDecomp1 = new Mock <IExtractionStep>(); mockDecomp1.Setup(d => d.ExpectedSource).Returns(typeof(Exception)); mockDecomp1.Setup(d => d.Execute(It.IsAny <int>())).Returns(new DBValue[] { value1, value0 }); var decomps = new IExtractionStep[] { mockDecomp0.Object, mockDecomp1.Object }; var step = new DecomposingExtractionStep(mockExtractor.Object, decomps); var source = "Albany"; // Act var values = step.Execute(source); // Assert mockExtractor.Verify(e => e.Execute(source), Times.Once); mockDecomp0.Verify(d => d.Execute(v), Times.Once); mockDecomp1.Verify(d => d.Execute(v), Times.Once); values.Should().BeEquivalentTo(new DBValue[] { value0, value1, value0 }); }
[TestMethod] public void Construct() { // Arrange var mockExtractor = new Mock <IExtractionStep>(); mockExtractor.Setup(e => e.ExpectedSource).Returns(typeof(string)); mockExtractor.Setup(e => e.Execute(It.IsAny <string>())).Returns(Array.Empty <DBValue>()); var converter = DataConverter.Identity <int>(); // Act var extractors = new IExtractionStep[] { mockExtractor.Object }; var converters = new DataConverter[] { converter }; var plan = new EntityExtractionPlan(extractors, converters); // Assert plan.ExpectedSource.Should().Be(typeof(string)); }
[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(Exception)); var mockDecomp = new Mock <IExtractionStep>(); mockDecomp.Setup(d => d.ExpectedSource).Returns(typeof(Exception)); var decomps = new IExtractionStep[] { mockDecomp.Object }; // Act var step = new DecomposingExtractionStep(mockExtractor.Object, decomps); // Assert step.ExpectedSource.Should().Be(typeof(string)); }
[TestMethod] public void Execute() { // Arrange var year = DBValue.Create(2012); var month = DBValue.Create(12); var day = DBValue.Create(31); var ymd = new Mock <IExtractionStep>(); ymd.Setup(e => e.ExpectedSource).Returns(typeof(DateTime)); ymd.Setup(e => e.Execute(It.IsAny <DateTime>())).Returns(new DBValue[] { year, month, day }); var hour = DBValue.Create(23); var minute = DBValue.Create(59); var second = DBValue.Create(59); var hms = new Mock <IExtractionStep>(); hms.Setup(e => e.ExpectedSource).Returns(typeof(DateTime)); hms.Setup(e => e.Execute(It.IsAny <DateTime>())).Returns(new DBValue[] { hour, minute, second }); var offsetCnv = DataConverter.Create <int, int>(i => i - 1); var identityCnv = DataConverter.Identity <int>(); var extractors = new IExtractionStep[] { ymd.Object, hms.Object }; var converters = Enumerable.Repeat(offsetCnv, 3).Concat(Enumerable.Repeat(identityCnv, 3)); var plan = new EntityExtractionPlan(extractors, converters); var source = DateTime.Now; // Act var values = plan.Execute(source); // Assert values.Should().HaveCount(6); values[0].Should().Be(DBValue.Create((int)year.Datum - 1)); values[1].Should().Be(DBValue.Create((int)month.Datum - 1)); values[2].Should().Be(DBValue.Create((int)day.Datum - 1)); values[3].Should().Be(hour); values[4].Should().Be(minute); values[5].Should().Be(second); ymd.Verify(e => e.Execute(source)); hms.Verify(e => e.Execute(source)); }