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)); }); }
void Update() { timerSeconds += Time.deltaTime; if (timerSeconds >= duration) { timerSeconds = 0f; string targetCity = roads[UnityEngine.Random.Range(0, roads.Count)]; last = targetCity; Peasant p = Units.Create("UnarmedPeasant").GetComponent <Peasant>(); p.transform.position = transform.position; p.Initialize(paths[targetCity]); } }
public void CreatesProductList() { var productDto = buildProductDto(); var result = Product.Create(new List <Product.Dto> { productDto }.AsReadOnly()); result.IsSuccess.Should().BeTrue(); result.IfSuccess(products => { products.Count.Should().Be(1); var expectedLink = Link.Create(productDto.Link).IfFail(() => null); products.First().Link.Should().Be(expectedLink); var expectedUnits = Units.Create(productDto.Units).IfFail(() => null); products.First().Units.Should().Be(expectedUnits); products.First().AdditionalInformation.IsSome.Should().BeTrue(); var expectedAdditionalInformation = AdditionalInformation.Create(productDto.AdditionalInformation).IfFail(() => null); products.First().AdditionalInformation.IfSome(x => x.Should().Be(expectedAdditionalInformation)); var expectedPromotionCode = PromotionCode.Create(productDto.PromotionCode).IfFail(() => null); products.First().PromotionCode.IsSome.Should().BeTrue(); products.First().PromotionCode.IfSome(x => x.Should().Be(expectedPromotionCode)); }); }
public void CreatesUnits() { var result = Units.Create("1"); result.IsSuccess.Should().BeTrue(); }
IReadOnlyList <Product> > Create(IReadOnlyList <Dto> productsDto) { if (productsDto.Count == 0) { return(new ValidationError <GenericValidationErrorCode>( fieldId: PluralizationProvider.Pluralize(nameof(Product)), errorCode: GenericValidationErrorCode.Required)); } var validationErrors = new Seq <ValidationError <GenericValidationErrorCode> >(); var products = new List <Product>(); productsDto .Select((productDto, index) => new { Value = productDto, Index = index }) .ToList() .ForEach(productDto => { var link = Link.Create(productDto.Value.Link); var units = Units.Create(productDto.Value.Units); var additionalInformation = productDto.Value.AdditionalInformation .Map(x => ValueObjects.AdditionalInformation.Create(x)); var promotionCode = productDto.Value.PromotionCode .Map(x => ValueObjects.PromotionCode.Create(x)); if (link.IsFail || units.IsFail || additionalInformation.Match(None: () => false, Some: x => x.IsFail) || promotionCode.Match(None: () => false, Some: x => x.IsFail)) { link.IfFail(errors => validationErrors = validationErrors.Concat(MapLinkValidationErrors(errors, productDto.Index))); units.IfFail(errors => validationErrors = validationErrors.Concat(MapUnitsValidationErrors(errors, productDto.Index))); additionalInformation.IfSome(result => result.IfFail(errors => validationErrors = validationErrors.Concat(MapAdditionalInformationValidationErrors(errors, productDto.Index)))); promotionCode.IfSome(result => result.IfFail(errors => validationErrors = validationErrors.Concat(MapPromotionCodeValidationErrors(errors, productDto.Index)))); } else { var product = new Product( id: Id.Create(), link: link.IfFail(() => throw new InvalidOperationException()), units: units.IfFail(() => throw new InvalidOperationException()), additionalInformation: additionalInformation.Match( None: () => null, Some: x => x.IfFail(() => throw new InvalidOperationException())), promotionCode: promotionCode.Match( None: () => null, Some: x => x.IfFail(() => throw new InvalidOperationException()))); products.Add(product); } }); if (validationErrors.Count > 0) { return(validationErrors); } return(products.ToList().AsReadOnly()); Seq <ValidationError <GenericValidationErrorCode> > MapLinkValidationErrors( Seq <ValidationError <GenericValidationErrorCode> > validationErrors, int index) { return(validationErrors.Map(validationError => new ValidationError <GenericValidationErrorCode>( fieldId: $"{nameof(Product)}[{index}].{nameof(Link)}", errorCode: validationError.ErrorCode))); } Seq <ValidationError <GenericValidationErrorCode> > MapUnitsValidationErrors( Seq <ValidationError <GenericValidationErrorCode> > validationErrors, int index) { return(validationErrors.Map(validationError => new ValidationError <GenericValidationErrorCode>( fieldId: $"{nameof(Product)}[{index}].{nameof(Units)}", errorCode: validationError.ErrorCode))); } Seq <ValidationError <GenericValidationErrorCode> > MapAdditionalInformationValidationErrors( Seq <ValidationError <GenericValidationErrorCode> > validationErrors, int index) { return(validationErrors.Map(validationError => new ValidationError <GenericValidationErrorCode>( fieldId: $"{nameof(Product)}[{index}].{nameof(AdditionalInformation)}", errorCode: validationError.ErrorCode))); } Seq <ValidationError <GenericValidationErrorCode> > MapPromotionCodeValidationErrors( Seq <ValidationError <GenericValidationErrorCode> > validationErrors, int index) { return(validationErrors.Map(validationError => new ValidationError <GenericValidationErrorCode>( fieldId: $"{nameof(Product)}[{index}].{nameof(PromotionCode)}", errorCode: validationError.ErrorCode))); } }
public void CreatesPurchaseApplication() { var request = BuildPurchaseApplicationRequest(); createPurchaseApplicationCommandHandler .Setup(x => x.Create(It.IsAny <CreatePurchaseApplicationCommand>())) .Returns(() => PurchaseApplicationBuilder.Build()); var response = controller.Create(request) as StatusCodeResult; response.StatusCode.Should().Be(StatusCodes.Status200OK); createPurchaseApplicationCommandHandler .Verify(x => x.Create(It.Is <CreatePurchaseApplicationCommand>(y => y.Products.Count == request.Products.Count && y.Products.First().Link == Link.Create(request.Products.First().Link).IfFail(() => null) && y.Products.First().Units == Units.Create(request.Products.First().Units).IfFail(() => null) && y.Products.First().AdditionalInformation == AdditionalInformation.Create(request.Products.First().AdditionalInformation).IfFail(() => null) && y.Products.First().PromotionCode == PromotionCode.Create(request.Products.First().PromotionCode).IfFail(() => null) && y.ClientProp.Email == Email.Create(request.Client.Email).IfFail(() => null) && y.ClientProp.PhoneNumber == PhoneNumber.Create(request.Client.PhoneNumber).IfFail(() => null) && y.ClientProp.Name == Name.Create(request.Client.Name).IfFail(() => null) && y.AdditionalInformation == AdditionalInformation.Create(request.AdditionalInformation).IfFail(() => null))), Times.Once); }