Ejemplo n.º 1
0
        public async Task<CreateBrandResponse> CreateBrandAsync(CreateBrandCommand cmd)
        {
            using (var client = new HttpClient())
            {
                var url = new Uri(string.Format("{0}/brands", BaseServiceUrl));
                var response = await client.PostAsync<CreateBrandCommand>(url, cmd, new JsonMediaTypeFormatter());
                if (response.StatusCode != HttpStatusCode.Created)
                {
                    var responseMessage = response.Content.ReadAsStringAsync();

                    var cleanResponse = responseMessage.Result.Replace("\\r\\n", "<br/>");

                    string exceptionJson = "{ \"FriendlyMessage\": \"There was an error creating a new Brand.\", \"Data\": " + cleanResponse + "}";
                    
                    throw new ApplicationException(exceptionJson);
                }

                var result = await response.Content.ReadAsStringAsync();
                var dto = JsonConvert.DeserializeObject<CreateBrandResponse>(result);
                return dto;
            }
        }
Ejemplo n.º 2
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);
        }
 public async Task <IActionResult> Post(CreateBrandCommand command)
 {
     return(Ok(await _mediator.Send(command)));
 }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Post([FromBody] CreateBrandCommand command)
        {
            var result = await Mediator.Send(command);

            return(Ok(new { result }));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Add(CreateBrandCommand command)
        {
            var brands = await _mediator.Send(command);

            return(Ok(brands));
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        public async Task ShouldThrowOrderNotShippedException()
        {
            // 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 cancelOrderCommand = new CancelOrderCommand {
                OrderId = orderId
            };

            await SendAsync(cancelOrderCommand);

            var deliverOrderCommand = new DeliverOrderCommand {
                OrderId = orderId
            };

            // Assert

            // Shipp Order Command
            FluentActions.Invoking(() => SendAsync(deliverOrderCommand)).Should().Throw <OrderNotShippedException>();
        }
Ejemplo n.º 9
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)
                                                     );
        }