public static MockedDbContext <T> GetMockedDbContext <T>() where T : DbContext
        {
            var instance = new MockedDbContext <T>();

            instance.MockTables();
            return(instance);
        }
        public static void MockTables <T>(this MockedDbContext <T> mockedContext) where T : DbContext
        {
            var contextType = typeof(T);

            var dbSetProperties = contextType.GetProperties().Where(prop =>
                                                                    prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(DbSet <>));

            foreach (var prop in dbSetProperties)
            {
                var dbSetGenericType = prop.PropertyType.GetGenericArguments()[0];
                var listType         = typeof(List <>).MakeGenericType(dbSetGenericType);

                var listForFakeTable = Activator.CreateInstance(listType);
                var parameter        = Expression.Parameter(contextType);
                var body             = Expression.PropertyOrField(parameter, prop.Name);
                var lambdaExpression = Expression.Lambda <Func <T, object> >(body, parameter);
                var method           = typeof(EntityFrameworkMockHelper).GetMethod("MockDbSet")
                                       ?.MakeGenericMethod(dbSetGenericType);

                if (method == null)
                {
                    throw new InvalidOperationException();
                }

                mockedContext.Setup(lambdaExpression).Returns(method.Invoke(null, new[] { listForFakeTable }));
                mockedContext.Tables.Add(prop.Name, listForFakeTable);
            }
        }
        public OrderHandlerTests()
        {
            eventContext = new EventProvider();

            var mockOrderContext = new MockedDbContext <OrderContext>();

            projectionContext = new ProjectionProvider();

            mockOrderContext.MockTables();

            orderContext = mockOrderContext.Object;

            var mappingConfig = new MappingConfig();

            orderHandler      = new OrderHandler(mappingConfig.Mapper, mockOrderContext.Object, eventContext, projectionContext);
            mappingTestConfig = new MappingTestConfig();
        }