public void CreatesCommand()
        {
            var commandDto = BuildCreatePurchaseApplicationCommandDto();

            var result = CreatePurchaseApplicationCommand.Create(commandDto);

            result.IsSuccess.Should().BeTrue();
            result.IfSuccess(command =>
            {
                command.Products.Count.Should().Be(commandDto.Products.Count);
                var expectedLink = Link.Create(commandDto.Products.First().Link.ValueUnsafe()).IfFail(() => null);
                command.Products.First().Link.Should().Be(expectedLink);
                var expectedUnits = Units.Create(commandDto.Products.First().Units).IfFail(() => null);
                command.Products.First().Units.Should().Be(expectedUnits);
                var expectedAdditionalInformation = AdditionalInformation.Create(commandDto.Products.First().AdditionalInformation).IfFail(() => null);
                command.Products.First().AdditionalInformation.IsSome.Should().BeTrue();
                command.Products.First().AdditionalInformation.IfSome(x => x.Should().Be(expectedAdditionalInformation));
                var expectedPromotionCode = PromotionCode.Create(commandDto.Products.First().PromotionCode).IfFail(() => null);
                command.Products.First().PromotionCode.IsSome.Should().BeTrue();
                command.Products.First().PromotionCode.IfSome(x => x.Should().Be(expectedPromotionCode));
                var expectedClientName = Name.Create(commandDto.Client.Email).IfFail(() => null);
                command.ClientProp.Name.Should().Be(expectedClientName);
                var expectedClientPhoneNumber = PhoneNumber.Create(commandDto.Client.PhoneNumber).IfFail(() => null);
                command.ClientProp.PhoneNumber.Should().Be(expectedClientPhoneNumber);
                var expectedClientEmail = Email.Create(commandDto.Client.Email).IfFail(() => null);
                command.ClientProp.Email.Should().Be(expectedClientEmail);
                var expectedPurchaseApplicationAdditionalInformation = AdditionalInformation.Create(commandDto.AdditionalInformation).IfFail(() => null);
                command.AdditionalInformation.IsSome.Should().BeTrue();
                command.AdditionalInformation.IfSome(x => x.Should().Be(expectedPurchaseApplicationAdditionalInformation));
            });
        }
        public void DoesNotCreateCommandWhenAdditionalInformationHasValidationErrors()
        {
            var commandDto = BuildCreatePurchaseApplicationCommandDto(additionalInformation: new string('a', 1001));

            var result = CreatePurchaseApplicationCommand.Create(commandDto);

            result.IsFail.Should().BeTrue();
        }
        public void DoesNotCreateCommandWhenClientHasValidationErrors()
        {
            var commandDto = BuildCreatePurchaseApplicationCommandDto(clientName: null);

            var result = CreatePurchaseApplicationCommand.Create(commandDto);

            result.IsFail.Should().BeTrue();
        }
        public void DoesNotCreateCommandWhenProductsHaveValidationErrors()
        {
            var commandDto = BuildCreatePurchaseApplicationCommandDto(isProductListEmpty: true);

            var result = CreatePurchaseApplicationCommand.Create(commandDto);

            result.IsFail.Should().BeTrue();
        }
            CreatePurchaseApplicationCommand> BuildCreatePurchaseApplicationCommand(PurchaseApplicationCreationRequest creationRequest)
        {
            var commandDto = new CreatePurchaseApplicationCommand.Dto(
                products: creationRequest.Products.Map(product =>
                                                       new CanaryDeliveries.PurchaseApplication.Domain.Entities.Product.Dto(
                                                           link: product.Link,
                                                           units: product.Units,
                                                           additionalInformation: product.AdditionalInformation,
                                                           promotionCode: product.PromotionCode)).ToList(),
                client: new CanaryDeliveries.PurchaseApplication.Domain.Entities.Client.Dto(
                    name: creationRequest.Client.Name,
                    phoneNumber: creationRequest.Client.PhoneNumber,
                    email: creationRequest.Client.Email),
                additionalInformation: creationRequest.AdditionalInformation);

            return(CreatePurchaseApplicationCommand.Create(commandDto));
        }
        private static CreatePurchaseApplicationCommand BuildCreatePurchaseApplicationCommand()
        {
            var requestDto = new CreatePurchaseApplicationCommand.Dto(
                products: new List <Product.Dto>
            {
                new Product.Dto(
                    link: "https://addidas.com/any/product",
                    units: "1",
                    additionalInformation: "Product additional product",
                    promotionCode: "ADDIDAS-123")
            },
                client: new Client.Dto(
                    name: "Alfredo",
                    phoneNumber: "123123123",
                    email: "*****@*****.**"),
                additionalInformation: "Purchase application additional information");

            return(CreatePurchaseApplicationCommand
                   .Create(requestDto)
                   .IfFail(() => throw new InvalidOperationException()));
        }
 private ActionResult ExecuteCommandHandler(CreatePurchaseApplicationCommand comm)
 {
     commandHandler.Create(comm);
     return(Ok());
 }