public void CreateDelegate_RaisedPocoFactoryForFlatComplexRow_DelegateSetsPocoAsExpected() { var definitionProvider = new DataAnnotationsDefinitionProvider(); var entityDefinition = definitionProvider.Resolve <ComplexFlatRow>(); var databaseContext = new Mock <IDatabaseContext>(); databaseContext.Setup(context => context.GetValueMapper(It.IsAny <Type>(), It.IsAny <Type>())).Returns((IValueMapper)null); using (var target = new RaisedPocoFactory(definitionProvider)) { var stopwatch = new Stopwatch(); var expected = Generate.CreateFakeComplexRow(); ComplexFlatRow actual; using (var reader = expected.MockDataReader(entityDefinition.ReturnableAttributes).Object) { reader.Read(); var pocoDataRequest = new PocoDataRequest(reader, entityDefinition, databaseContext.Object); stopwatch.Start(); actual = target.CreatePoco <ComplexFlatRow>(pocoDataRequest); } Trace.TraceInformation($"{stopwatch.Elapsed} Invoke delegate #1"); stopwatch.Reset(); Assert.IsNotNull(actual); Assert.AreEqual(expected.FakeComplexEntityId, actual.FakeComplexEntityId); Assert.AreEqual(expected, actual, string.Join(Environment.NewLine, expected.GetDifferences(actual))); using (var reader = expected.MockDataReader(entityDefinition.ReturnableAttributes).Object) { reader.Read(); var pocoDataRequest = new PocoDataRequest(reader, entityDefinition, databaseContext.Object); stopwatch.Start(); target.CreatePoco <ComplexFlatRow>(pocoDataRequest); } Trace.TraceInformation($"{stopwatch.Elapsed} Invoke delegate #2"); stopwatch.Reset(); using (var reader = expected.MockDataReader(entityDefinition.ReturnableAttributes).Object) { reader.Read(); var pocoDataRequest = new PocoDataRequest(reader, entityDefinition, databaseContext.Object); stopwatch.Start(); target.CreatePoco <ComplexFlatRow>(pocoDataRequest); } Trace.TraceInformation($"{stopwatch.Elapsed} Invoke delegate #3"); stopwatch.Reset(); } }
public void CreateDelegate_FlatPocoFactoryForComplexRow_IsNotNull() { var fakeComplexRow = Generate.CreateFakeComplexRow(); var entityDefinition = new DataAnnotationsDefinitionProvider().Resolve <ComplexFlatRow>(); var databaseContext = new Mock <IDatabaseContext>(); databaseContext.Setup(context => context.GetValueMapper(It.IsAny <Type>(), It.IsAny <Type>())).Returns((IValueMapper)null); PocoDelegateInfo actual; using (var reader = fakeComplexRow.MockDataReader(entityDefinition.ReturnableAttributes).Object) { reader.Read(); var pocoDataRequest = new PocoDataRequest(reader, entityDefinition, databaseContext.Object); actual = FlatPocoFactory.CreateDelegate <ComplexFlatRow>(pocoDataRequest); } Assert.IsNotNull(actual); }
public void CreateDelegate_FlatPocoFactoryForDynamic_DelegateSetsPocoAsExpected() { var expected = Generate.CreateFakeComplexRow(); var definitionProvider = new DataAnnotationsDefinitionProvider(); var entityDefinition = definitionProvider.Resolve <ComplexFlatRow>(); var databaseContext = new Mock <IDatabaseContext>(); databaseContext.Setup(context => context.GetValueMapper(It.IsAny <Type>(), It.IsAny <Type>())).Returns((IValueMapper)null); Expression <Func <ComplexFlatRow, object> > expression1 = row => row.FakeComplexEntityId; Expression <Func <ComplexFlatRow, object> > expression2 = row => row.FakeDependentEntityDependentIntegerValue; Expression <Func <ComplexFlatRow, object> > expression3 = row => row.FakeSubSubEntityUniqueName; var attributes = new[] { expression1, expression2, expression3 }.Select(entityDefinition.Find) .ToList(); dynamic actual; // Set up the data reader with all attributes to ensure that the process is only getting the ones we want. using (var reader = expected.MockDataReader(attributes).Object) { reader.Read(); var pocoDataRequest = new PocoDataRequest(reader, attributes, databaseContext.Object); var pocoDelegate = FlatPocoFactory.CreateDelegate <dynamic>(pocoDataRequest).MappingDelegate as Func <IDataReader, dynamic>; Assert.IsNotNull(pocoDelegate); actual = pocoDelegate.Invoke(reader); } Assert.IsNotNull(actual); Assert.AreEqual(expected.FakeComplexEntityId, actual.FakeComplexEntityId); Assert.AreEqual(expected.FakeDependentEntityDependentIntegerValue, actual.FakeDependentEntityDependentIntegerValue); Assert.AreEqual(expected.FakeSubSubEntityUniqueName, actual.FakeSubSubEntityUniqueName); Assert.ThrowsException <RuntimeBinderException>(() => Assert.IsNull(actual.Description)); }