public void CreateDelegate_RaisedPocoFactoryForRaisedComplexRowWithoutDependentEntity_DelegateSetsPocoAsExpected()
        {
            var expected = Generate.CreateFakeRaisedComplexRow(false);

            var definitionProvider = new DataAnnotationsDefinitionProvider();
            var entityDefinition   = definitionProvider.Resolve <ComplexRaisedRow>();
            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 = Stopwatch.StartNew();
                ComplexRaisedRow actual;

                using (var reader = expected.MockDataReader(entityDefinition.ReturnableAttributes).Object)
                {
                    stopwatch.Start();
                    reader.Read();
                    actual = target.CreatePoco <ComplexRaisedRow>(new PocoDataRequest(reader, entityDefinition, databaseContext.Object));
                    Trace.TraceInformation($"{stopwatch.Elapsed} Invoke delegate #1");
                }

                stopwatch.Reset();

                Assert.IsNotNull(actual);
                Assert.AreEqual(expected.ComplexEntityId, actual.ComplexEntityId);

                Assert.AreEqual(
                    expected.SubEntity,
                    actual.SubEntity,
                    string.Join(Environment.NewLine, expected.SubEntity.GetDifferences(actual.SubEntity)));

                Assert.IsNull(expected.DependentEntity);
                Assert.IsNull(actual.DependentEntity);

                Assert.AreEqual(expected, actual, string.Join(Environment.NewLine, expected.GetDifferences(actual)));

                stopwatch.Start();
                using (var reader = expected.MockDataReader(entityDefinition.ReturnableAttributes).Object)
                {
                    reader.Read();
                    target.CreatePoco <ComplexRaisedRow>(new PocoDataRequest(reader, entityDefinition, databaseContext.Object));
                }

                Trace.TraceInformation($"{stopwatch.Elapsed} Invoke delegate #2");
                stopwatch.Reset();

                stopwatch.Start();
                using (var reader = expected.MockDataReader(entityDefinition.ReturnableAttributes).Object)
                {
                    reader.Read();
                    target.CreatePoco <ComplexRaisedRow>(new PocoDataRequest(reader, entityDefinition, databaseContext.Object));
                }

                Trace.TraceInformation($"{stopwatch.Elapsed} Invoke delegate #3");
                stopwatch.Reset();
            }
        }
        public void CreateDelegate_RaisedPocoFactoryForRaisedComplexRow_IsNotNull()
        {
            var definitionProvider = new DataAnnotationsDefinitionProvider();
            var entityDefinition   = definitionProvider.Resolve <ComplexRaisedRow>();
            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 expected = Generate.CreateFakeRaisedComplexRow(true);

                using (var reader = expected.MockDataReader(entityDefinition.ReturnableAttributes).Object)
                {
                    reader.Read();
                    var pocoDataRequest = new PocoDataRequest(reader, entityDefinition, databaseContext.Object);
                    var actual          = target.CreatePoco <ComplexRaisedRow>(pocoDataRequest);
                    Assert.IsNotNull(actual);
                }
            }
        }
        public void CreateDelegate_RaisedPocoFactoryForRaisedDynamic_DelegateSetsPocoAsExpected()
        {
            var definitionProvider = new DataAnnotationsDefinitionProvider();
            var expected           = Generate.CreateFakeRaisedComplexRow(true);
            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 entityDefinition = definitionProvider.Resolve <ComplexRaisedRow>();

                Expression <Func <ComplexRaisedRow, object> > expression1 = row => row.ComplexEntityId;
                Expression <Func <ComplexRaisedRow, object> > expression2 = row => row.DependentEntity.DependentIntegerValue;
                Expression <Func <ComplexRaisedRow, object> > expression3 = row => row.SubEntity.SubSubEntity.UniqueName;

                var attributes = new[]
                {
                    expression1,
                    expression2,
                    expression3
                }.Select(entityDefinition.Find)
                .ToList();

                dynamic actual;

                using (var reader = expected.MockDataReader(attributes).Object)
                {
                    reader.Read();
                    var pocoDataRequest = new PocoDataRequest(reader, attributes, databaseContext.Object);
                    actual = target.CreatePoco <dynamic>(pocoDataRequest);
                }

                Assert.IsNotNull(actual);
                Assert.AreEqual(expected.ComplexEntityId, actual.ComplexEntityId);
                Assert.AreEqual(expected.DependentEntity.DependentIntegerValue, actual.DependentEntityDependentIntegerValue);
                Assert.AreEqual(expected.SubEntity.SubSubEntity.UniqueName, actual.SubSubEntityUniqueName);
                Assert.ThrowsException <RuntimeBinderException>(() => Assert.IsNull(actual.Description));
            }
        }