Пример #1
0
        public async Task UpdateAsyncShouldUpdateCustomer()
        {
            var db       = DbInfrastructure.GetDatabase();
            var customer = await DbInfrastructure.SeedCustomer(db);

            var serviceProviderMock = new Mock <IServiceProvider>();
            var customerService     = new CustomerService(db, new SortStrategyParser(serviceProviderMock.Object));

            const string UpdatedFirstName  = "Teodora";
            const string UpdatedLastName   = "Ivanova";
            const string UpdatedPhoneNumer = "08 888 555";

            await customerService.UpdateAsync(customer.Id, UpdatedFirstName, UpdatedLastName, UpdatedPhoneNumer, Status.Inactive);

            var actualCustomer = await db.Customers.FirstOrDefaultAsync();

            actualCustomer
            .Should()
            .Match <Customer>(c => c.FirstName == UpdatedFirstName)
            .And
            .Match <Customer>(c => c.LastName == UpdatedLastName)
            .And
            .Match <Customer>(c => c.PhoneNumber == UpdatedPhoneNumer)
            .And
            .Match <Customer>(c => c.Status == Status.Inactive);
        }
Пример #2
0
        public async Task AllAsyncShouldReturnCorrectCustomersSortedByDescription()
        {
            var db = DbInfrastructure.GetDatabase();
            var serviceProviderMock = new Mock <IServiceProvider>();
            var customer            = await DbInfrastructure.SeedCustomer(db);

            await DbInfrastructure.SeedCustomers(100, 10, db);

            var orderService = new PurchaseOrderService(db, new SortStrategyParser(serviceProviderMock.Object));

            await DbInfrastructure.SeedOrdersByCustomer(db, customer);

            const string Description = "description";

            for (var i = 1; i <= 8; i++)
            {
                var orders = await orderService.AllAsync <OrderViewModel>(i, customer.Id, Description);

                orders
                .Should()
                .HaveCount(WebConstants.OrdersPerPage);

                orders
                .Should()
                .BeInAscendingOrder(c => c.Description);

                orders
                .Should()
                .NotContain(c => c.Status == Status.Deleted);
            }
        }
Пример #3
0
        public async Task UpdateAsyncShouldUpdateOrder()
        {
            var db       = DbInfrastructure.GetDatabase();
            var customer = await DbInfrastructure.SeedCustomer(db);

            var serviceProviderMock = new Mock <IServiceProvider>();
            var orderService        = new PurchaseOrderService(db, new SortStrategyParser(serviceProviderMock.Object));
            var order = await SeedOrderByCustomer(db, customer);

            const string  UpdatedDescription = "Updated Description!";
            const decimal UpdatedPrice       = 999.999M;
            const int     UpdatedQuantity    = 5;

            await orderService.UpdateAsync(order.Id, UpdatedDescription, UpdatedPrice, UpdatedQuantity, Status.Inactive);

            var actualOrder = await db.Purchases.FirstOrDefaultAsync();

            actualOrder
            .Should()
            .Match <PurchaseOrder>(po => po.Description == UpdatedDescription)
            .And
            .Match <PurchaseOrder>(po => po.Price == UpdatedPrice)
            .And
            .Match <PurchaseOrder>(po => po.Quantity == UpdatedQuantity)
            .And
            .Match <PurchaseOrder>(po => po.Status == Status.Inactive);
        }
Пример #4
0
        public async Task GetByIdAsyncShouldReturnCorrectOrder()
        {
            var db       = DbInfrastructure.GetDatabase();
            var customer = await DbInfrastructure.SeedCustomer(db);

            var serviceProviderMock = new Mock <IServiceProvider>();
            var orderService        = new PurchaseOrderService(db, new SortStrategyParser(serviceProviderMock.Object));
            var order = await SeedOrderByCustomer(db, customer);

            var actualOrder = await orderService.GetByIdAsync(order.Id);

            actualOrder
            .Should()
            .Match <PurchaseOrder>(po => po.CustomerId == customer.Id)
            .And
            .Match <PurchaseOrder>(po => po.Status == Status.Active)
            .And
            .Match <PurchaseOrder>(po => po.Description == Constants.Description)
            .And
            .Match <PurchaseOrder>(po => po.Price == Constants.Price)
            .And
            .Match <PurchaseOrder>(po => po.Quantity == Constants.Quantity)
            .And
            .Match <PurchaseOrder>(po => po.TotalAmount == Constants.Price * Constants.Quantity);
        }
Пример #5
0
        public async Task DeleteAsyncShouldMarkOrderAsDeleted()
        {
            var db       = DbInfrastructure.GetDatabase();
            var customer = await DbInfrastructure.SeedCustomer(db);

            await DbInfrastructure.SeedOrdersByCustomer(db, customer);

            var serviceProviderMock = new Mock <IServiceProvider>();
            var orderService        = new PurchaseOrderService(db, new SortStrategyParser(serviceProviderMock.Object));

            IEnumerable <OrderViewModel> orders;

            for (var i = 1; i <= 10; i++)
            {
                orders = await orderService.AllAsync <OrderViewModel>(i, customer.Id, string.Empty);

                await orderService.DeleteAsync(orders.First().Id);
            }

            for (var i = 1; i <= 9; i++)
            {
                orders = await orderService.AllAsync <OrderViewModel>(i, customer.Id, string.Empty);

                orders
                .Should()
                .HaveCount(WebConstants.OrdersPerPage);
            }
        }
Пример #6
0
        public async Task CountByCustomerAsyncShouldReturnCorrectCount()
        {
            var db = DbInfrastructure.GetDatabase();
            var serviceProviderMock = new Mock <IServiceProvider>();
            var customer            = await DbInfrastructure.SeedCustomer(db);

            await DbInfrastructure.SeedCustomers(100, 10, db);

            var orderService = new PurchaseOrderService(db, new SortStrategyParser(serviceProviderMock.Object));

            await DbInfrastructure.SeedOrdersByCustomer(db, customer);

            var ordersCountByCustomer = await orderService.CountByCustomerAsync(customer.Id);

            ordersCountByCustomer
            .Should()
            .Be(150);
        }
Пример #7
0
        public async Task GetByIdAsyncShouldReturnCorrectCustomer()
        {
            var db       = DbInfrastructure.GetDatabase();
            var customer = await DbInfrastructure.SeedCustomer(db);

            var serviceProviderMock = new Mock <IServiceProvider>();
            var customerService     = new CustomerService(db, new SortStrategyParser(serviceProviderMock.Object));
            var actualCustomer      = await customerService.GetByIdAsync(customer.Id);

            actualCustomer
            .Should()
            .Match <Customer>(c => c.FirstName == Constants.FirstName)
            .And
            .Match <Customer>(c => c.LastName == Constants.LastName)
            .And
            .Match <Customer>(c => c.IsMale == Constants.IsMale)
            .And
            .Match <Customer>(c => c.PhoneNumber == Constants.PhoneNumber)
            .And
            .Match <Customer>(c => c.Status == Status.Active);
        }
Пример #8
0
        public async Task CreateAsyncShouldCreateAndSaveOrderInDatabase()
        {
            var db = DbInfrastructure.GetDatabase();
            var serviceProviderMock = new Mock <IServiceProvider>();
            var orderService        = new PurchaseOrderService(db, new SortStrategyParser(serviceProviderMock.Object));
            var customer            = await DbInfrastructure.SeedCustomer(db);

            await orderService.CreateAsync(Constants.Description, Constants.Price, Constants.Quantity, customer.Id);

            var order = await db.Purchases.FirstOrDefaultAsync(po => po.CustomerId == customer.Id);

            order
            .Should()
            .Match <PurchaseOrder>(po => po.Description == Constants.Description)
            .And
            .Match <PurchaseOrder>(po => po.Price == Constants.Price)
            .And
            .Match <PurchaseOrder>(po => po.Quantity == Constants.Quantity)
            .And
            .Match <PurchaseOrder>(po => po.Status == Status.Active);
        }