public void AddUnitCommand_Adds_Unit()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddDbContext <PeSportsTrackingContext>(o => o.UseInMemoryDatabase("test"), ServiceLifetime.Transient);
            var provider = serviceCollection.BuildServiceProvider();

            var addUnitCommandHandler = new AddUnitCommand.AddUnitCommandHandler(provider.GetService <PeSportsTrackingContext>());
            var command = new AddUnitCommand
            {
                Name = "name"
            };

            // Act
            var result = addUnitCommandHandler.Handle(command);
            var unit   = provider.GetService <PeSportsTrackingContext>().Units.FirstOrDefault();

            // Assert
            Assert.That(result.IsSuccess, Is.True);
            Assert.That(unit.Name, Is.EqualTo("name"));
        }
示例#2
0
        internal void OnClickMapCell(CellComponent cellComponent, float xPercent, float yPercent)
        {
            if (model.GetSelectionState().SelectionType == typeof(ZRTSModel.Tile))
            {
                TileFactory           tf      = TileFactory.Instance;
                ZRTSModel.Tile        tile    = tf.GetImprovedTile(model.GetSelectionState().SelectedTileType);
                ChangeCellTileCommand command = new ChangeCellTileCommand(cellComponent, tile);

                if (command.CanBeDone())
                {
                    model.GetCommandStack().ExecuteCommand(command);
                }
            }
            else if (model.GetSelectionState().SelectionType == typeof(UnitComponent))
            {
                UnitFactory   uf   = UnitFactory.Instance;
                UnitComponent unit = uf.Create(model.GetSelectionState().SelectedUnitType);
                //unit.PointLocation = new PointF((float)cellComponent.X + xPercent, (float)cellComponent.Y + yPercent);
                PlayerComponent player  = model.GetScenario().GetGameWorld().GetPlayerList().GetPlayerByName(model.GetSelectionState().SelectedPlayer);
                AddUnitCommand  command = new AddUnitCommand(unit, player, cellComponent);

                if (command.CanBeDone())
                {
                    model.GetCommandStack().ExecuteCommand(command);
                }
            }
            else if (model.GetSelectionState().SelectionType == typeof(Building))
            {
                BuildingFactory bf       = BuildingFactory.Instance;
                Building        building = bf.Build(model.GetSelectionState().SelectedBuildingType, true);
                //building.PointLocation = new PointF((float)cellComponent.X + xPercent, (float)cellComponent.Y + yPercent);
                PlayerComponent    player  = model.GetScenario().GetGameWorld().GetPlayerList().GetPlayerByName(model.GetSelectionState().SelectedPlayer);
                AddBuildingCommand command = new AddBuildingCommand(building, player, cellComponent);

                if (command.CanBeDone())
                {
                    model.GetCommandStack().ExecuteCommand(command);
                }
            }
        }
示例#3
0
        public void ShouldThrowProductNotFoundException()
        {
            // Arrange

            // Add unit to product
            var addUnitToCommand = new AddUnitCommand
            {
                // random product Id
                ProductId    = Guid.NewGuid().ToString(),
                SellingPrice = 92,
                ContentCount = 2,
                Price        = 33,
                Count        = 6,
                IsAvailable  = true,
                Name         = "Test Unit",
                Weight       = 44
            };

            // Act
            var results = FluentActions.Invoking(() => SendAsync(addUnitToCommand));

            // Assert
            results.Should().Throw <ProductNotFoundException>();
        }
示例#4
0
        public async Task ShouldListAllOrders()
        {
            // Arrange
            var accountId = await RunAsDefaultUserAsync();

            var createCustomerCommand = new CreateCustomerCommand
            {
                AccountId     = accountId,
                ShopName      = "Test Shop Name",
                ShopAddress   = "Test Shop address",
                LocationOnMap = "Test LocationOnMap"
            };

            await SendAsync(createCustomerCommand);

            // Create product brand
            var brandCommand = new CreateBrandCommand {
                Name = "Test Brand"
            };
            var brandId = await SendAsync(brandCommand);

            // Create product category
            var productCategoryCommand = new CreateProductCategoryCommand {
                Name = "Test Product Category"
            };
            var productCategoryId = await SendAsync(productCategoryCommand);

            // Create product
            var createProductCommand = new CreateProductCommand
            {
                AvailableToSell = true,
                // created brand id
                BrandId = brandId,
                // created product category id
                ProductCategoryId = productCategoryId,
                Name     = "Test Product",
                PhotoUrl = "Test Product",
                Barcode  = "Test Product"
            };

            var productId = await SendAsync(createProductCommand);

            // Add unit to product
            var addUnitToCommand = new AddUnitCommand
            {
                ProductId    = productId,
                SellingPrice = 92,
                ContentCount = 2,
                Price        = 33,
                Count        = 6,
                IsAvailable  = true,
                Name         = "Test Unit",
                Weight       = 44
            };

            var unitId = await SendAsync(addUnitToCommand);

            // AddItem To Shopping Van
            var addItemToVanCommand = new AddItemToVanCommand
            {
                ProductId = productId,
                UnitId    = unitId
            };

            await SendAsync(addItemToVanCommand);
            await SendAsync(addItemToVanCommand);

            // Place Order Command
            var placeOrderCommand = new PlaceOrderCommand();

            await SendAsync(placeOrderCommand);

            // Act

            // Get Order By Id Query
            var listOrdersQuery = new ListOrdersQuery {
                OrderStatuses = new List <OrderStatus> {
                    OrderStatus.Placed
                }
            };
            var listOrders = await SendAsync(listOrdersQuery);

            // Assert
            listOrders.Data.Should().NotBeNull();
            listOrders.Data.Count.Should().Be(1);
        }
示例#5
0
        public async Task ShouldThrowCancelConfirmedOrderException()
        {
            // Arrange
            var accountId = await RunAsDefaultUserAsync();

            var createCustomerCommand = new CreateCustomerCommand
            {
                AccountId     = accountId,
                ShopName      = "Test Shop Name",
                ShopAddress   = "Test Shop address",
                LocationOnMap = "Test LocationOnMap"
            };

            await SendAsync(createCustomerCommand);

            // Create product brand
            var brandCommand = new CreateBrandCommand {
                Name = "Test Brand"
            };
            var brandId = await SendAsync(brandCommand);

            // Create product category
            var productCategoryCommand = new CreateProductCategoryCommand {
                Name = "Test Product Category"
            };
            var productCategoryId = await SendAsync(productCategoryCommand);

            // Create product
            var createProductCommand = new CreateProductCommand
            {
                AvailableToSell = true,
                // created brand id
                BrandId = brandId,
                // created product category id
                ProductCategoryId = productCategoryId,
                Name     = "Test Product",
                PhotoUrl = "Test Product",
                Barcode  = "Test Product"
            };

            var productId = await SendAsync(createProductCommand);

            // Add unit to product
            var addUnitToCommand = new AddUnitCommand
            {
                ProductId    = productId,
                SellingPrice = 92,
                ContentCount = 2,
                Price        = 33,
                Count        = 6,
                IsAvailable  = true,
                Name         = "Test Unit",
                Weight       = 44
            };

            var unitId = await SendAsync(addUnitToCommand);

            // AddItem To Shopping Van
            var addItemToVanCommand = new AddItemToVanCommand
            {
                ProductId = productId,
                UnitId    = unitId
            };

            await SendAsync(addItemToVanCommand);
            await SendAsync(addItemToVanCommand);

            // Place Order Command
            var placeOrderCommand = new PlaceOrderCommand();
            var orderId           = await SendAsync(placeOrderCommand);

            // Act
            var confirmOrderCommand = new ConfirmOrderCommand {
                OrderId = orderId
            };

            await SendAsync(confirmOrderCommand);

            var cancelOrderCommand = new CancelOrderCommand {
                OrderId = orderId
            };

            // Assert

            // Cancel Order Command
            FluentActions.Invoking(() => SendAsync(cancelOrderCommand)).Should().Throw <CancelConfirmedOrderException>();
        }
示例#6
0
        public async Task ShouldGetCurrentCustomerVan()
        {
            // Arrange
            var currentCustomerId = await RunAsDefaultUserAsync();

            // Create product brand
            var brandCommand = new CreateBrandCommand {
                Name = "Test Brand"
            };
            var brandId = await SendAsync(brandCommand);

            // Create product category
            var productCategoryCommand = new CreateProductCategoryCommand {
                Name = "Test Product Category"
            };
            var productCategoryId = await SendAsync(productCategoryCommand);

            // Create product
            var createProductCommand = new CreateProductCommand
            {
                AvailableToSell = true,
                // created brand id
                BrandId = brandId,
                // created product category id
                ProductCategoryId = productCategoryId,
                Name     = "Test Product",
                PhotoUrl = "Test Product",
                Barcode  = "Test Product"
            };

            var productId = await SendAsync(createProductCommand);

            // Add unit to product
            var addUnitToCommand = new AddUnitCommand
            {
                ProductId    = productId,
                SellingPrice = 92,
                ContentCount = 2,
                Price        = 33,
                Count        = 6,
                IsAvailable  = true,
                Name         = "Test Unit",
                Weight       = 44
            };

            var unitId = await SendAsync(addUnitToCommand);

            // AddItem To Shopping Van
            var command = new AddItemToVanCommand
            {
                ProductId = productId,
                UnitId    = unitId
            };

            await SendAsync(command);

            // Act

            var getCurrentCustomerVanQuery = new CurrentCustomerVanQuery();
            var currentCustomerVan         = await SendAsync(getCurrentCustomerVanQuery);

            // Assert
            currentCustomerVan.TotalItemsCount.Should().Be(1);
            currentCustomerVan.TotalPrice.Should().Be(addUnitToCommand.SellingPrice + (addUnitToCommand.SellingPrice * 0.14f));
            currentCustomerVan.CustomerId.Should().Be(currentCustomerId);
        }
示例#7
0
 Task OnAddUnit(AddUnitCommand cmd)
 {
     return(AddFragment($"New unit: {cmd.Id} ({cmd.Descriptor})"));
 }
示例#8
0
        public async Task ShouldDeleteUnitFromProduct()
        {
            // Arrange

            // Create product brand
            var brandCommand = new CreateBrandCommand {
                Name = "Test Brand"
            };
            var brandId = await SendAsync(brandCommand);

            // Create product category
            var productCategoryCommand = new CreateProductCategoryCommand {
                Name = "Test Product Category"
            };
            var productCategoryId = await SendAsync(productCategoryCommand);

            // Create product
            var createProductCommand = new CreateProductCommand
            {
                AvailableToSell = true,
                // created brand id
                BrandId = brandId,
                // created product category id
                ProductCategoryId = productCategoryId,
                Name     = "Test Product",
                PhotoUrl = "Test Product",
                Barcode  = "Test Product"
            };

            var productId = await SendAsync(createProductCommand);

            // Add unit to product
            var addUnitToCommand = new AddUnitCommand
            {
                ProductId    = productId,
                SellingPrice = 92,
                ContentCount = 2,
                Price        = 33,
                Count        = 6,
                IsAvailable  = true,
                Name         = "Test Unit",
                Weight       = 44
            };

            var unitId = await SendAsync(addUnitToCommand);

            var deleteProductUnitCommand = new DeleteUnitCommand
            {
                ProductId = productId,
                UnitId    = unitId
            };

            await SendAsync(deleteProductUnitCommand);

            var listProductsUnitsQuery = new ListUnitsByProductsIdsQuery
            {
                ProductsIds = new List <string> {
                    productId
                }
            };

            var currentProductUnits = await SendAsync(listProductsUnitsQuery);

            currentProductUnits.Should().NotContain(x =>
                                                    x.Id == unitId &&
                                                    x.ProductId == addUnitToCommand.ProductId);
        }
示例#9
0
        public async Task ShouldAddItemToVan()
        {
            // Arrange
            await RunAsDefaultUserAsync();

            // Create product brand
            var brandCommand = new CreateBrandCommand {
                Name = "Test Brand"
            };
            var brandId = await SendAsync(brandCommand);

            // Create product category
            var productCategoryCommand = new CreateProductCategoryCommand {
                Name = "Test Product Category"
            };
            var productCategoryId = await SendAsync(productCategoryCommand);

            // Create product
            var createProductCommand = new CreateProductCommand
            {
                AvailableToSell = true,
                // created brand id
                BrandId = brandId,
                // created product category id
                ProductCategoryId = productCategoryId,
                Name     = "Test Product",
                PhotoUrl = "Test Product",
                Barcode  = "Test Product"
            };

            var productId = await SendAsync(createProductCommand);

            // Add unit to product
            var addUnitToCommand = new AddUnitCommand
            {
                ProductId    = productId,
                SellingPrice = 92,
                ContentCount = 2,
                Price        = 33,
                Count        = 6,
                IsAvailable  = true,
                Name         = "Test Unit",
                Weight       = 44
            };

            var unitId = await SendAsync(addUnitToCommand);

            // AddItem To Shopping Van
            var command = new AddItemToVanCommand
            {
                ProductId = productId,
                UnitId    = unitId
            };

            // Act
            await SendAsync(command);

            var shoppingVanItemCount = await SendAsync(command);

            // Assert
            shoppingVanItemCount.Should().Be(2);
        }
示例#10
0
        public async Task <IActionResult> AddUnit([FromBody] AddUnitCommand command)
        {
            var result = await Mediator.Send(command);

            return(Ok(new { result }));
        }
示例#11
0
        public async Task ShouldUpdateOrder()
        {
            // Arrange
            var accountId = await RunAsDefaultUserAsync();

            var createCustomerCommand = new CreateCustomerCommand
            {
                AccountId     = accountId,
                ShopName      = "Test Shop Name",
                ShopAddress   = "Test Shop address",
                LocationOnMap = "Test LocationOnMap"
            };

            await SendAsync(createCustomerCommand);

            // Create product brand
            var brandCommand = new CreateBrandCommand {
                Name = "Test Brand"
            };
            var brandId = await SendAsync(brandCommand);

            // Create product category
            var productCategoryCommand = new CreateProductCategoryCommand {
                Name = "Test Product Category"
            };
            var productCategoryId = await SendAsync(productCategoryCommand);

            // Create product
            var createProductCommand = new CreateProductCommand
            {
                AvailableToSell = true,
                // created brand id
                BrandId = brandId,
                // created product category id
                ProductCategoryId = productCategoryId,
                Name     = "Test Product",
                PhotoUrl = "Test Product",
                Barcode  = "Test Product"
            };

            var productId = await SendAsync(createProductCommand);

            // Add first unit to product
            var addFirstUnitCommand = new AddUnitCommand
            {
                ProductId    = productId,
                SellingPrice = 92,
                ContentCount = 2,
                Price        = 33,
                Count        = 6,
                IsAvailable  = true,
                Name         = "Test First Unit",
                Weight       = 44
            };

            var firstUnitId = await SendAsync(addFirstUnitCommand);

            // Add first unit to product
            var addSecondUnitCommand = new AddUnitCommand
            {
                ProductId    = productId,
                SellingPrice = 342,
                ContentCount = 24,
                Price        = 323,
                Count        = 64,
                IsAvailable  = true,
                Name         = "Test Second Unit",
                Weight       = 94
            };

            var secondUnitId = await SendAsync(addSecondUnitCommand);

            // AddItem To Shopping Van
            var addItemToVanCommand = new AddItemToVanCommand
            {
                ProductId = productId,
                UnitId    = firstUnitId
            };

            await SendAsync(addItemToVanCommand);
            await SendAsync(addItemToVanCommand);

            // Place Order Command
            var placeOrderCommand = new PlaceOrderCommand();
            var orderId           = await SendAsync(placeOrderCommand);

            // Get Order By Id Query
            var orderByIdQuery = new OrderByIdQuery {
                OrderId = orderId
            };
            var order = await SendAsync(orderByIdQuery);

            // Act

            var updateOrderCommand = new UpdateOrderCommand
            {
                OrderId     = orderId,
                OrderItemId = order.OrderItems.FirstOrDefault(x => x.UnitId == firstUnitId).Id,
                UnitId      = secondUnitId,
                UnitCount   = 10,
                UnitName    = addSecondUnitCommand.Name
            };

            await SendAsync(updateOrderCommand);

            // Get Order By Id Query
            var orderAfterUpdate = await SendAsync(orderByIdQuery);


            // Assert
            order.Should().NotBeNull();
            order.OrderItems.Count.Should().Be(1);
            order.OrderItems.FirstOrDefault(x => x.UnitId == firstUnitId).UnitName.Should().Be(addFirstUnitCommand.Name);
            orderAfterUpdate.OrderItems.FirstOrDefault(x => x.UnitId == secondUnitId).UnitName.Should().Be(addSecondUnitCommand.Name);
        }
示例#12
0
        public async Task ShouldListUnitsByProductsIds()
        {
            // Arrange

            // Create product brand
            var brandCommand = new CreateBrandCommand {
                Name = "Test Brand"
            };
            var brandId = await SendAsync(brandCommand);

            // Create product category
            var productCategoryCommand = new CreateProductCategoryCommand {
                Name = "Test Product Category"
            };
            var productCategoryId = await SendAsync(productCategoryCommand);

            // Create First product
            var createFirstProductCommand = new CreateProductCommand
            {
                AvailableToSell = true,
                // created brand id
                BrandId = brandId,
                // created product category id
                ProductCategoryId = productCategoryId,
                Name     = "Test Product",
                PhotoUrl = "Test Product",
                Barcode  = "Test Product"
            };

            // Create Second product
            var createSecondProductCommand = new CreateProductCommand
            {
                AvailableToSell = true,
                // created brand id
                BrandId = brandId,
                // created product category id
                ProductCategoryId = productCategoryId,
                Name     = "Test Product",
                PhotoUrl = "Test Product",
                Barcode  = "Test Product"
            };


            var firstProductId = await SendAsync(createFirstProductCommand);

            var secondProductId = await SendAsync(createSecondProductCommand);

            // Add unit to first product
            var addFirstUnitCommand = new AddUnitCommand
            {
                ProductId    = firstProductId,
                SellingPrice = 92,
                ContentCount = 2,
                Price        = 33,
                Count        = 6,
                IsAvailable  = true,
                Name         = "Test Unit",
                Weight       = 44
            };

            // Add unit to second product
            var addSecondUnitCommand = new AddUnitCommand
            {
                ProductId    = secondProductId,
                SellingPrice = 92,
                ContentCount = 2,
                Price        = 33,
                Count        = 6,
                IsAvailable  = true,
                Name         = "Test Unit",
                Weight       = 44
            };

            var firstUnitId = await SendAsync(addFirstUnitCommand);

            var secondUnitId = await SendAsync(addSecondUnitCommand);



            var listUnitsByProductsIdsQuery = new ListUnitsByProductsIdsQuery {
                ProductsIds = new List <string> {
                    firstProductId, secondProductId
                }
            };
            var productsUnits = await SendAsync(listUnitsByProductsIdsQuery);

            productsUnits.Should().NotBeNull();
            productsUnits.Should().HaveCount(2);
            productsUnits.Should().Contain(x => x.Id == firstUnitId);
            productsUnits.Should().Contain(x => x.Id == secondUnitId);
        }
示例#13
0
        public async Task ShouldDeliverOrder()
        {
            // Arrange
            var accountId = await RunAsDefaultUserAsync();

            var createCustomerCommand = new CreateCustomerCommand
            {
                AccountId     = accountId,
                ShopName      = "Test Shop Name",
                ShopAddress   = "Test Shop address",
                LocationOnMap = "Test LocationOnMap"
            };

            await SendAsync(createCustomerCommand);

            // Create product brand
            var brandCommand = new CreateBrandCommand {
                Name = "Test Brand"
            };
            var brandId = await SendAsync(brandCommand);

            // Create product category
            var productCategoryCommand = new CreateProductCategoryCommand {
                Name = "Test Product Category"
            };
            var productCategoryId = await SendAsync(productCategoryCommand);

            // Create product
            var createProductCommand = new CreateProductCommand
            {
                AvailableToSell = true,
                // created brand id
                BrandId = brandId,
                // created product category id
                ProductCategoryId = productCategoryId,
                Name     = "Test Product",
                PhotoUrl = "Test Product",
                Barcode  = "Test Product"
            };

            var productId = await SendAsync(createProductCommand);

            // Add unit to product
            var addUnitToCommand = new AddUnitCommand
            {
                ProductId    = productId,
                SellingPrice = 92,
                ContentCount = 2,
                Price        = 33,
                Count        = 6,
                IsAvailable  = true,
                Name         = "Test Unit",
                Weight       = 44
            };

            var unitId = await SendAsync(addUnitToCommand);

            // AddItem To Shopping Van
            var addItemToVanCommand = new AddItemToVanCommand
            {
                ProductId = productId,
                UnitId    = unitId
            };

            await SendAsync(addItemToVanCommand);
            await SendAsync(addItemToVanCommand);

            // Place Order Command
            var placeOrderCommand = new PlaceOrderCommand();
            var orderId           = await SendAsync(placeOrderCommand);

            // Confirm Order Command
            var confirmOrderCommand = new ConfirmOrderCommand {
                OrderId = orderId
            };

            await SendAsync(confirmOrderCommand);

            // Shipp Order Command
            var shippOrderCommand = new ShippOrderCommand {
                OrderId = orderId
            };

            await SendAsync(shippOrderCommand);

            // Act

            // Deliver Order Command
            var deliverOrderCommand = new DeliverOrderCommand {
                OrderId = orderId
            };

            await SendAsync(deliverOrderCommand);

            // Get Order By Id Query
            var orderByIdQuery = new OrderByIdQuery {
                OrderId = orderId
            };
            var order = await SendAsync(orderByIdQuery);

            // Assert
            order.Should().NotBeNull();
            order.OrderStatus.Should().Be(OrderStatus.Delivered);
        }
示例#14
0
        public async Task ShouldUpdateProductUnit()
        {
            // Arrange

            // Create product brand
            var brandCommand = new CreateBrandCommand {
                Name = "Test Brand"
            };
            var brandId = await SendAsync(brandCommand);

            // Create product category
            var productCategoryCommand = new CreateProductCategoryCommand {
                Name = "Test Product Category"
            };
            var productCategoryId = await SendAsync(productCategoryCommand);

            // Create product
            var createProductCommand = new CreateProductCommand
            {
                AvailableToSell = true,
                // created brand id
                BrandId = brandId,
                // created product category id
                ProductCategoryId = productCategoryId,
                Name     = "Test Product",
                PhotoUrl = "Test Product",
                Barcode  = "Test Product"
            };

            var productId = await SendAsync(createProductCommand);

            // Add unit to product
            var addUnitToCommand = new AddUnitCommand
            {
                ProductId    = productId,
                SellingPrice = 92,
                ContentCount = 2,
                Price        = 33,
                Count        = 6,
                IsAvailable  = true,
                Name         = "Test Unit",
                Weight       = 44
            };

            var unitId = await SendAsync(addUnitToCommand);

            // update product unit
            var updateProductUnitCommand = new UpdateUnitCommand
            {
                ProductId    = productId,
                SellingPrice = 992,
                ContentCount = 25,
                Price        = 333,
                Count        = 65,
                IsAvailable  = false,
                Name         = "Test Unit Update",
                Weight       = 4,
                Id           = unitId
            };

            await SendAsync(updateProductUnitCommand);

            var listProductsUnitsQuery = new ListUnitsByProductsIdsQuery
            {
                ProductsIds = new List <string> {
                    productId
                }
            };


            var currentProductUnits = await SendAsync(listProductsUnitsQuery);

            currentProductUnits.Should().OnlyContain(x =>
                                                     x.Id == unitId &&
                                                     x.ProductId == updateProductUnitCommand.ProductId &&
                                                     x.SellingPrice.Equals(updateProductUnitCommand.SellingPrice) &&
                                                     x.ContentCount == updateProductUnitCommand.ContentCount &&
                                                     x.Price.Equals(updateProductUnitCommand.Price) &&
                                                     x.Count == updateProductUnitCommand.Count &&
                                                     x.IsAvailable == updateProductUnitCommand.IsAvailable &&
                                                     x.Name == updateProductUnitCommand.Name &&
                                                     x.Weight.Equals(updateProductUnitCommand.Weight)
                                                     );
        }