public void CreateDelegate_AttributeForDynamicObject_MatchesExpected()
        {
            var entityDefinition = new DataAnnotationsDefinitionProvider().Resolve <OverriddenColumnNameRow>();
            var databaseContext  = new Mock <IDatabaseContext>();

            databaseContext.Setup(context => context.GetValueMapper(It.IsAny <Type>(), It.IsAny <Type>())).Returns((IValueMapper)null);
            var expected = new OverriddenColumnNameRow
            {
                OverriddenColumnNameId = 12,
                Description            = "my desc",
                EntryTime      = DateTimeOffset.Now,
                Name           = "name",
                RelatedRowId   = 234,
                RelatedRowName = "relatedName"
            };

            using (var dataReader = expected.MockDataReader(entityDefinition.DirectAttributes).Object)
            {
                dataReader.Read();
                var dataRequest = new PocoDataRequest(dataReader, entityDefinition, databaseContext.Object);
                var func        = FlatPocoFactory.CreateDelegate <dynamic>(dataRequest).MappingDelegate as Func <IDataReader, dynamic>;
                Assert.IsNotNull(func);

                var actual = func(dataReader);

                foreach (var definition in entityDefinition.DirectAttributes)
                {
                    Assert.AreEqual(definition.GetValueDelegate.DynamicInvoke(expected), ((IDictionary <string, object>)actual)[definition.ReferenceName]);
                }
            }
        }
        public void CreateDelegate_FlatPocoFactoryForPhysicalNameOverriddenRow_DelegateSetsPocoAsExpected()
        {
            var expected = new OverriddenColumnNameRow
            {
                OverriddenColumnNameId = 43,
                Name           = "OcnName",
                Description    = "OcnDescription",
                EntryTime      = DateTimeOffset.Now,
                RelatedRowId   = 3433,
                RelatedRowName = "RelatedName"
            };

            var entityDefinition = new DataAnnotationsDefinitionProvider().Resolve <OverriddenColumnNameRow>();
            var databaseContext  = new Mock <IDatabaseContext>();

            databaseContext.Setup(context => context.GetValueMapper(It.IsAny <Type>(), It.IsAny <Type>())).Returns((IValueMapper)null);
            Stopwatch stopwatch;

            OverriddenColumnNameRow actual;

            using (var reader = expected.MockDataReader(entityDefinition.ReturnableAttributes).Object)
            {
                reader.Read();
                var pocoDataRequest = new PocoDataRequest(reader, entityDefinition, databaseContext.Object);

                stopwatch = Stopwatch.StartNew();
                var pocoDelegate =
                    FlatPocoFactory.CreateDelegate <OverriddenColumnNameRow>(pocoDataRequest).MappingDelegate as Func <IDataReader, OverriddenColumnNameRow>;

                Trace.TraceInformation($"{stopwatch.Elapsed} Create delegate");
                stopwatch.Reset();

                Assert.IsNotNull(pocoDelegate);

                stopwatch.Start();
                actual = pocoDelegate.Invoke(pocoDataRequest.DataReader);
            }

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

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

            using (var reader = expected.MockDataReader(entityDefinition.ReturnableAttributes).Object)
            {
                reader.Read();
                var pocoDelegate =
                    FlatPocoFactory.CreateDelegate <OverriddenColumnNameRow>(new PocoDataRequest(reader, entityDefinition, databaseContext.Object)).MappingDelegate as
                    Func <IDataReader, OverriddenColumnNameRow>;

                Assert.IsNotNull(pocoDelegate);
                stopwatch.Start();
                pocoDelegate.Invoke(reader);
            }

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

            using (var reader = expected.MockDataReader(entityDefinition.ReturnableAttributes).Object)
            {
                reader.Read();
                var pocoDelegate =
                    FlatPocoFactory.CreateDelegate <OverriddenColumnNameRow>(new PocoDataRequest(reader, entityDefinition, databaseContext.Object)).MappingDelegate as
                    Func <IDataReader, OverriddenColumnNameRow>;

                Assert.IsNotNull(pocoDelegate);
                stopwatch.Start();
                pocoDelegate.Invoke(reader);
            }

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