public async Task GetAllUnprocessed_ReturnsCorectly()
        {
            MapperInitializer.InitializeMapper();
            var context         = ApplicationDbContextInMemoryFactory.InitializeContext();
            var orderRepository = new EfDeletableEntityRepository <Order>(context);
            var orderService    = this.GetOrderService(orderRepository, context);
            var orderTestSeeder = new OrderTestSeeder();

            await orderTestSeeder.SeedOneUnprocessedOrder(context);

            var result = orderService.GetAllUnprocessed <OrderUnprocessedViewModel>();

            Assert.Single(result);
        }
        public async Task UserOrders_WorksCorectly()
        {
            MapperInitializer.InitializeMapper();
            var context         = ApplicationDbContextInMemoryFactory.InitializeContext();
            var orderRepository = new EfDeletableEntityRepository <Order>(context);
            var orderService    = this.GetOrderService(orderRepository, context);
            var orderTestSeeder = new OrderTestSeeder();

            await orderTestSeeder.SeedOneUnprocessedOrder(context);

            var userOrders = await orderService.UserOrders <OrderDetailsViewModel>("UserId1");

            Assert.Single(userOrders);

            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await orderService.UserOrders <OrderDetailsViewModel>("invalid");
            });
        }
        public async Task DetailsAdmin_WorksCorectly()
        {
            MapperInitializer.InitializeMapper();
            var context         = ApplicationDbContextInMemoryFactory.InitializeContext();
            var orderRepository = new EfDeletableEntityRepository <Order>(context);
            var orderService    = this.GetOrderService(orderRepository, context);
            var orderTestSeeder = new OrderTestSeeder();

            await orderTestSeeder.SeedOneUnprocessedOrder(context);

            var result = orderService.DetailsAdmin <OrderDetailsViewModel>("OrderId1");

            Assert.NotNull(result);

            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await orderService.DetailsAdmin <OrderDisplayInputModel>(null);
            });
        }
        public async Task Cancel_WorksCorectly()
        {
            var context         = ApplicationDbContextInMemoryFactory.InitializeContext();
            var orderRepository = new EfDeletableEntityRepository <Order>(context);
            var orderService    = this.GetOrderService(orderRepository, context);
            var orderTestSeeder = new OrderTestSeeder();

            await orderTestSeeder.SeedOneUnprocessedOrder(context);

            var order = context.Orders.FirstOrDefault();

            await orderService.Cancel(order.Id);

            Assert.Equal(OrderStatus.Canceled, order.OrderStatus);

            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await orderService.Cancel("invalid");
            });
        }
        public async Task Delete_WorksCorectly()
        {
            var context         = ApplicationDbContextInMemoryFactory.InitializeContext();
            var orderRepository = new EfDeletableEntityRepository <Order>(context);
            var orderService    = this.GetOrderService(orderRepository, context);
            var orderTestSeeder = new OrderTestSeeder();

            await orderTestSeeder.SeedOneUnprocessedOrder(context);

            var unProcessed = context.Orders.First(x => x.Recipient == "UnProcessed");

            await orderTestSeeder.SeedOneProcessedOrder(context);

            var processed = context.Orders.First(x => x.Recipient == "Processed");

            await orderTestSeeder.SeedOneDeliveredOrder(context);

            var delivered = context.Orders.First(x => x.Recipient == "Delivered");


            await orderService.Delete(unProcessed.Id);

            await orderService.Delete(processed.Id);

            await orderService.Delete(delivered.Id);

            var orders = context.Orders.Count();

            Assert.True(delivered.IsDeleted);

            Assert.Equal(0, orders);

            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await orderService.Delete("invalid");
            });
        }