public void ShouldConvertJsonToSpecifiedFormat() { string jsonFromDb = "{\"numero_pedido\":\"OR1234\",\"comprador\":{\"aniversario\":\"1991-05-20T00:00:00\",\"documento\":\"12345678900\",\"email\":\"[email protected]\",\"telefone\":\"552122225555\",\"celular\":\"5521999995555\",\"nome\":\"Fulano Silva\",\"tipo\":\"pessoa_fisica\",\"endereco\":{\"cidade\":\"Rio de Janeiro\",\"complemento\":\"Apto 1011\",\"pais\":\"Brazil\",\"bairro\":\"Centro\",\"numero\":\"123\",\"estado\":\"RJ\",\"logradouro\":\"Rua Souza\",\"cep\":\"23021130\"}},\"pagamento\":{\"valor\":210,\"parcelas\":\"5\",\"endereco_cobranca\":{\"cidade\":\"Rio de Janeiro\",\"complemento\":\"Apto 1011\",\"pais\":\"Brazil\",\"bairro\":\"Centro\",\"numero\":\"123\",\"estado\":\"RJ\",\"logradouro\":\"Rua Souza\",\"cep\":\"23021130\"},\"cartao\":{\"bandeira\":\"Visa\",\"numero_cartao\":\"4000000000000010\",\"mes_vencimento\":\"10\",\"ano_vencimento\":\"2022\",\"nome_cartao\":\"FULANO SILVA\",\"cvv\":\"321\"}},\"entrega\":{\"endereco_entrega\":{\"cidade\":\"Rio de Janeiro\",\"complemento\":\"Apto 1011\",\"pais\":\"Brazil\",\"bairro\":\"Centro\",\"numero\":\"123\",\"estado\":\"RJ\",\"logradouro\":\"Rua Souza\",\"cep\":\"23021130\"},\"frete\":10,\"shipping_company\":\"Correios\"},\"carriinho\":{\"items\":[{\"produto\":\"Discos Vinil\",\"quantidade\":10,\"valor_unit\":10},{\"produto\":\"Toca Viniil\",\"quantidade\":1,\"valor_unit\":100}]}}"; string jsonFromRequest = "{\"numero_pedido\":\"OR1235\",\"comprador\":{\"aniversario\":\"1991-05-20T00:00:00\",\"documento\":\"12345678900\",\"email\":\"[email protected]\",\"telefone\":\"552122225555\",\"celular\":\"5521999995555\",\"nome\":\"Fulano Silva\",\"tipo\":\"pessoa_fisica\",\"endereco\":{\"cidade\":\"Rio de Janeiro\",\"complemento\":\"Apto 1011\",\"pais\":\"Brazil\",\"bairro\":\"Centro\",\"numero\":\"123\",\"estado\":\"RJ\",\"logradouro\":\"Rua Souza\",\"cep\":\"23021130\"}},\"pagamento\":{\"valor\":210,\"parcelas\":\"5\",\"endereco_cobranca\":{\"cidade\":\"Rio de Janeiro\",\"complemento\":\"Apto 1011\",\"pais\":\"Brazil\",\"bairro\":\"Centro\",\"numero\":\"123\",\"estado\":\"RJ\",\"logradouro\":\"Rua Souza\",\"cep\":\"23021130\"},\"cartao\":{\"bandeira\":\"Visa\",\"numero_cartao\":\"4000000000000010\",\"mes_vencimento\":\"10\",\"ano_vencimento\":\"2022\",\"nome_cartao\":\"FULANO SILVA\",\"cvv\":\"321\"}},\"entrega\":{\"endereco_entrega\":{\"cidade\":\"Rio de Janeiro\",\"complemento\":\"Apto 1011\",\"pais\":\"Brazil\",\"bairro\":\"Centro\",\"numero\":\"123\",\"estado\":\"RJ\",\"logradouro\":\"Rua Souza\",\"cep\":\"23021130\"},\"frete\":10,\"shipping_company\":\"Correios\"},\"carriinho\":{\"items\":[{\"produto\":\"Discos Vinil\",\"quantidade\":10,\"valor_unit\":10},{\"produto\":\"Toca Viniil\",\"quantidade\":1,\"valor_unit\":100}]}}"; //string jsonFromRequest = "{\"numero_pedido\":\"OR1234\",\"comprador\":{\"aniversario\":\"1991-05-20T00:00:00\",\"documento\":\"12345678900\",\"email\":\"[email protected]\",\"telefone\":\"552122225555\",\"celular\":\"5521999995555\",\"nome\":\"Fulano Silva\",\"tipo\":\"pessoa_fisica\",\"endereco\":{\"cidade\":\"Rio de Janeiro\",\"complemento\":\"Apto 1011\",\"pais\":\"BR\",\"bairro\":\"Centro\",\"numero\":\"123\",\"estado\":\"RJ\",\"logradouro\":\"Rua Souza\",\"cep\":\"23021130\"}},\"pagamento\":{\"valor\":210,\"parcelas\":\"5\",\"endereco_cobranca\":{\"cidade\":\"Rio de Janeiro\",\"complemento\":\"Apto 1011\",\"pais\":\"BR\",\"bairro\":\"Centro\",\"numero\":\"123\",\"estado\":\"RJ\",\"logradouro\":\"Rua Souza\",\"cep\":\"23021130\"},\"cartao\":{\"bandeira\":\"Visa\",\"numero_cartao\":\"4000000000000010\",\"mes_vencimento\":\"10\",\"ano_vencimento\":\"2022\",\"nome_cartao\":\"FULANO SILVA\",\"cvv\":\"321\"}},\"entrega\":{\"endereco_entrega\":{\"cidade\":\"Rio de Janeiro\",\"complemento\":\"Apto 1011\",\"pais\":\"BR\",\"bairro\":\"Centro\",\"numero\":\"123\",\"estado\":\"RJ\",\"logradouro\":\"Rua Souza\",\"cep\":\"23021130\"},\"frete\":10,\"shipping_company\":\"Correios\"},\"carriniho\":{\"items\":[{\"produto\":\"Discos Vinil\",\"quantidade\":10,\"valor_unit\":10},{\"produto\":\"Toca Viniil\",\"quantidade\":1,\"valor_unit\":100}]}}"; Assert.True(jsonFromRequest.HasSameKeys(jsonFromDb)); var jsonDataDictionary = jsonFromRequest.GetKeyAndValuesToDictionary(); Assert.True(jsonDataDictionary.CanBeMappedTo(_customerPropertyMappings)); Assert.True(jsonDataDictionary.CanBeMappedTo(_itemPropertyMappings)); Assert.True(jsonDataDictionary.CanBeMappedTo(_paymentPropertyMappings)); var mundiPaggOrder = new MundiPaggOrder(); var payment = PaymentFactory.Create(jsonDataDictionary, _paymentPropertyMappings); mundiPaggOrder.Payments.Add(payment); var customer = CustomerFactory.Create(jsonDataDictionary, _customerPropertyMappings); mundiPaggOrder.Customer = customer; var itens = ItensFactory.CreateList(jsonDataDictionary, _itemPropertyMappings); mundiPaggOrder.Items = itens; Assert.True(mundiPaggOrder.Items.Any() && mundiPaggOrder.Payments.Any() && !string.IsNullOrEmpty(mundiPaggOrder.Customer.Name)); }
public void PlaceOrder_WhenAtLeastOneProductIsAdded_IsSuccessful() { // Arrange var customer = CustomerFactory.Create(); var orderProductsData = new List <OrderProductData>(); orderProductsData.Add(new OrderProductData(SampleProducts.Product1Id, 2)); var allProductPrices = new List <ProductPriceData> { SampleProductPrices.Product1EUR, SampleProductPrices.Product1USD }; const string currency = "Rial"; var conversionRates = GetConversionRates(); // Act customer.PlaceOrder( orderProductsData, allProductPrices, currency, conversionRates); // Assert var orderPlaced = AssertPublishedDomainEvent <OrderPlacedEvent>(customer); Assert.That(orderPlaced.Value, Is.EqualTo(MoneyValue.Of(200, "Rial"))); }
public void PlaceOrder_WhenNoProductIsAdded_BreaksOrderMustHaveAtLeastOneProductRule() { // Arrange var customer = CustomerFactory.Create(); var orderProductsData = new List <OrderProductData>(); var allProductPrices = new List <ProductPriceData> { SampleProductPrices.Product1EUR, SampleProductPrices.Product1USD }; const string currency = "Rial"; var conversionRates = GetConversionRates(); // Assert AssertBrokenRule <OrderMustHaveAtLeastOneProductRule>(() => { // Act customer.PlaceOrder( orderProductsData, allProductPrices, currency, conversionRates); }); }
public async Task <IActionResult> RegisterCustomer([FromBody] string Customer) { try { if (!ModelState.IsValid && string.IsNullOrEmpty(Customer)) { return(BadRequest()); } JsonResult jsonCustomer = Json(Customer); string brandName = jsonCustomer.Value.ToString(); var obj = CustomerFactory.Create(brandName); if (obj != null) { dbContext.Add(obj); await dbContext.SaveChangesAsync(); } return(new OkObjectResult(Response.StatusCode)); } catch (Exception) { throw; } }
public void Test_CustomerFactory_Should_Create_Sale() { var result = _factory.Create(_customerModel); Assert.That(result.CustomerId, Is.EqualTo(CustomerId)); Assert.That(result.ContactName, Is.EqualTo(ContactName)); Assert.That(result.CompanyName, Is.EqualTo(CompanyName)); }
public async Task <int> AddAsync(CustomerAddModel model) { var customer = CustomerFactory.Create(model, _userId); await _customerRepository.AddAsync(customer); await _unitOfWork.SaveChangesAsync(); return(customer.Id); }
public CustomerEntity GetCustomer(int custNo) { AspnetAppCustomers Appcustomer = checkNetDbContext.AspnetAppCustomers.Find(custNo); CustomerEntity customerEntity = CustomerFactory.Create(custNo, Appcustomer.Address1, Appcustomer.Address2, Appcustomer.Name, Appcustomer.City, Appcustomer.State, Appcustomer.ZipCode, Appcustomer.PhoneNo, Appcustomer.StatusCode, Appcustomer.LastUpdatedBy, Appcustomer.LastUpdateDate); return(customerEntity); }
public void CreateTest() { var r = GetRandom.Object <CustomersData>(); var o = CustomerFactory.Create(r.ID, r.Name, r.ValidFrom, r.ValidTo); Assert.AreEqual(r.Name, o.Data.Name); Assert.AreEqual(r.ID, o.Data.ID); Assert.AreEqual(r.ValidFrom, o.Data.ValidFrom); Assert.AreEqual(r.ValidTo, o.Data.ValidTo); }
private void AddButton_Click(object sender, EventArgs e) { ICustomer icust = null; icust = CustomerFactory.Create(CustomerTypeComboBox.SelectedIndex); icust.CustomerName = CustomerNameTextBox.Text; icust.Address = AdressTextBox.Text; icust.PhoneNumber = PhoneNumberTextBox.Text; icust.BillDate = Convert.ToDateTime(BillDateTextBox.Text); icust.BillAmount = Convert.ToDecimal(BillAmountTextBox.Text); }
public List <CustomerEntity> GetCustomers() { //Debug.WriteLine(checkNetDbContext.AspnetAppCustomers); List <AspnetAppCustomers> AppCustomers = checkNetDbContext.AspnetAppCustomers.ToList(); List <CustomerEntity> customerEntities = new List <CustomerEntity>(); foreach (AspnetAppCustomers appCust in AppCustomers) { CustomerEntity customerEntity = CustomerFactory.Create(appCust.CustNo, appCust.Address1, appCust.Address2, appCust.Name, appCust.City, appCust.State, appCust.ZipCode, appCust.PhoneNo, appCust.StatusCode, appCust.LastUpdatedBy, appCust.LastUpdateDate); customerEntities.Add(customerEntity); } return(customerEntities); }
public void Order() { var customer = CustomerFactory.Create("Luke", "Skywalker", "*****@*****.**"); var product = ProductFactory.Create("Millennium Falcon", 500_000_000); var item = OrderItemFactory.Create(product, 1); var order = OrderFactory.Create(customer); order.AddItem(item); var discount = new DiscountService().Calculate(order.Total, DiscountType.Large); order.ApplyDiscount(discount); Assert.AreEqual(250_000_000, order.Total.Value); }
public void PlaceOrder_GivenTwoOrdersInThatDayAlreadyMade_BreaksCustomerCannotOrderMoreThan2OrdersOnTheSameDayRule() { // Arrange var customer = CustomerFactory.Create(); var orderProductsData = new List <OrderProductData>(); orderProductsData.Add(new OrderProductData(SampleProducts.Product1Id, 2)); var allProductPrices = new List <ProductPriceData> { SampleProductPrices.Product1EUR, SampleProductPrices.Product1USD }; const string currency = "Rial"; var conversionRates = GetConversionRates(); SystemClock.Set(new DateTime(2020, 1, 10, 11, 0, 0)); customer.PlaceOrder( orderProductsData, allProductPrices, currency, conversionRates); SystemClock.Set(new DateTime(2020, 1, 10, 11, 30, 0)); customer.PlaceOrder( orderProductsData, allProductPrices, currency, conversionRates); SystemClock.Set(new DateTime(2020, 1, 10, 12, 00, 0)); // Assert AssertBrokenRule <CustomerCannotOrderMoreThan2OrdersOnTheSameDayRule>(() => { // Act customer.PlaceOrder( orderProductsData, allProductPrices, currency, conversionRates); }); }
public async Task HandleAsync(CreateCustomerForUserCommand command) { var user = new User { Id = Id.From(command.UserId), Address = command.Address, FirstName = command.FirstName, LastName = command.LastName, Country = command.Country, Email = command.Email, PostalCode = command.PostalCode, City = command.City, }; var customerId = Id.From(command.CustomerId); var customer = _factory.Create(customerId, user); await _repository.Save(customer); await EventBus.Current.PublishAsync(new CustomerCreatedEvent(customerId)); }
public async Task DomainModelBase_FactoryCreate_Success() { await RunWithTelemetryAsync( totalOfExecutions : 1, runInParallel : false, handler : async execution => { #region Arrange var customerFactory = new CustomerFactory(); #endregion #region Act var customer = customerFactory.Create(); #endregion #region Assert return(await Task.FromResult(customer != null).ConfigureAwait(false)); #endregion }); }
public async Task DomainModelBase_FactoryCreateWithValidationResult_Success() { await RunWithTelemetryAsync( totalOfExecutions : 1, runInParallel : false, handler : async execution => { #region Arrange var customerFactory = new CustomerFactory(); var validationResult = new ValidationResult(); validationResult.AddInformationMessage("MCB", "MCB_SPEC", "Marcelo Castelo"); #endregion #region Act var customer = customerFactory.Create(validationResult); #endregion #region Assert return(await Task.FromResult(customer?.ValidationResult?.MessageCollection?.Any(q => q?.Code == "MCB") == true).ConfigureAwait(false)); #endregion }); }
public async Task <ServiceResponse <CustomerOrderListVM> > GetOrdersByCustomerAsync(string customerId) { var response = new ServiceResponse <CustomerOrderListVM>(); try { if (string.IsNullOrWhiteSpace(customerId)) { response.AddNotification("customerId is required"); return(response); } var customer = await _customerClient.GetCustomerByIdAsync(customerId); var orders = await _orderClient.GetOrdersByCustomerAsync(customerId); if (customer is null) { response.AddNotification($"customer {customerId} not found"); return(response); } response.Data = new CustomerOrderListVM { Orders = orders?.Select(p => OrderFactory.Create(p))?.ToList(), Customer = CustomerFactory.Create(customer) }; } catch (Exception ex) { _logger.LogError(ex, ex.Message); response.AddNotification("unexpected error"); } return(response); }
protected override Customer createObject(CustomersData r) => CustomerFactory.Create(r);
/// <summary> /// 得意先マスタリストを更新します。 /// </summary> /// <param name="input">得意先マスタリストの更新対象。</param> public Task <HttpStatusCode> Put(IEnumerable <CustomerInputModel> input) { return(Task.Run(() => { var addedCustomers = input.GetAdded(); var modifiedCustomers = input.GetModified(); var deletedCustomers = input.GetDeleted(); var updateDateTime = DateTime.Now; var updateUserId = "Stub"; // 追加 foreach (var customer in addedCustomers) { var addedBrand = DataBase.Customers.FirstOrDefault(c => c.CustomerId.Equals(customer.CustomerId)); if (addedBrand == null) { DataBase.Customers.Add(CustomerFactory.Create( customerId: customer.CustomerId, customerName: customer.CustomerName, customerKanaName: customer.CustomerKanaName, customerShortName: customer.CustomerShortName, establishmentDate: customer.EstablishmentDate, ceo: customer.Ceo, postalCode: customer.PostalCode, address: customer.Address, tel: customer.Tel, fax: customer.Fax, mail: customer.Mail, hp: customer.Hp, cutoffDateType: customer.CutoffDateType, cutoffDate: customer.CutoffDate, collectionDateType: customer.CollectionDateType, collectionDate: customer.CollectionDate, taxType: customer.TaxType, taxCalcType: customer.TaxCalcType, taxRoundType: customer.TaxRoundType, note: customer.Note, updateDateTime: updateDateTime, updateUserId: updateUserId )); } } // 更新 foreach (var customer in modifiedCustomers) { var modifiedCustomer = DataBase.Customers.FirstOrDefault(c => c.CustomerId.Equals(customer.CustomerId)); if (modifiedCustomer == null) { continue; } modifiedCustomer.CustomerName = customer.CustomerName; modifiedCustomer.CustomerKanaName = customer.CustomerKanaName; modifiedCustomer.CustomerShortName = customer.CustomerShortName; modifiedCustomer.EstablishmentDate = customer.EstablishmentDate; modifiedCustomer.Ceo = customer.Ceo; modifiedCustomer.PostalCode = customer.PostalCode; modifiedCustomer.Address = customer.Address; modifiedCustomer.Tel = customer.Tel; modifiedCustomer.Fax = customer.Fax; modifiedCustomer.Mail = customer.Mail; modifiedCustomer.Hp = customer.Hp; modifiedCustomer.CutoffDateType = customer.CutoffDateType; modifiedCustomer.CutoffDate = customer.CutoffDate; modifiedCustomer.CollectionDateType = customer.CollectionDateType; modifiedCustomer.CollectionDate = customer.CollectionDate; modifiedCustomer.TaxType = customer.TaxType; modifiedCustomer.TaxCalcType = customer.TaxCalcType; modifiedCustomer.TaxRoundType = customer.TaxRoundType; modifiedCustomer.Note = customer.Note; modifiedCustomer.UpdateDateTime = updateDateTime; modifiedCustomer.UpdateUserId = updateUserId; } // 削除 foreach (var customer in deletedCustomers) { var deletedCustomer = DataBase.Customers.FirstOrDefault(c => c.CustomerId.Equals(customer.CustomerId)); if (deletedCustomer == null) { continue; } DataBase.Customers.Remove(deletedCustomer); } return HttpStatusCode.OK; })); }
public async Task AddCustomer(AddCustomerInput input) { var customer = _customerFactory.Create(input.Name, input.Mobile, input.Labels.ToList()); await _customerRepository.InsertAsync(customer); }
/// <inheritdoc/> public ICustomersPutOutputDto Put(ICustomersPutInputDto input) { using var dataAccessContext = this.GetRepository.CreateDataAccessContext(); this.GetRepository.DataAccessContext = dataAccessContext; this.PutRepository.DataAccessContext = dataAccessContext; // トランザクション開始 dataAccessContext.BeginTransaction(); // 取得 var entites = this.GetRepository.Get(); // 更新 foreach (var changedInput in input.ChangedDtos) { var entity = entites.FirstOrDefault(e => e.CustomerId == changedInput.CustomerId); if (entity == null) { continue; } entity.CustomerName = changedInput.CustomerName; entity.CustomerKanaName = changedInput.CustomerKanaName; entity.CustomerShortName = changedInput.CustomerShortName; entity.EstablishmentDate = changedInput.EstablishmentDate; entity.Ceo = changedInput.Ceo; entity.PostalCode = changedInput.PostalCode; entity.Address = changedInput.Address; entity.Tel = changedInput.Tel; entity.Fax = changedInput.Fax; entity.Mail = changedInput.Mail; entity.Hp = changedInput.Hp; entity.CutoffDateType = changedInput.CutoffDateType; entity.CutoffDate = changedInput.CutoffDate; entity.CollectionDateType = changedInput.CollectionDateType; entity.CollectionDate = changedInput.CollectionDate; entity.TaxType = changedInput.TaxType; entity.TaxCalcType = changedInput.TaxCalcType; entity.TaxRoundType = changedInput.TaxRoundType; entity.Note = changedInput.Note; entity.UpdateDateTime = this.Executor.ExecuteDateTime; entity.UpdateUserId = this.Executor.UserId; entity.EntityState |= EntityStateOptions.Modified; } // 削除 foreach (var deletedInput in input.DeletedDtos) { var entity = entites.FirstOrDefault(e => e.CustomerId == deletedInput.CustomerId); if (entity == null) { continue; } entity.UpdateDateTime = this.Executor.ExecuteDateTime; entity.UpdateUserId = this.Executor.UserId; entity.EntityState |= EntityStateOptions.Deleted; } // 作成 foreach (var addedInput in input.AddedDtos) { var entity = CustomerFactory.Create( customerId: addedInput.CustomerId, customerName: addedInput.CustomerName, customerKanaName: addedInput.CustomerKanaName, customerShortName: addedInput.CustomerShortName, establishmentDate: addedInput.EstablishmentDate, ceo: addedInput.Ceo, postalCode: addedInput.PostalCode, address: addedInput.Address, tel: addedInput.Tel, fax: addedInput.Fax, mail: addedInput.Mail, hp: addedInput.Hp, cutoffDateType: addedInput.CutoffDateType, cutoffDate: addedInput.CutoffDate, collectionDateType: addedInput.CollectionDateType, collectionDate: addedInput.CollectionDate, taxType: addedInput.TaxType, taxCalcType: addedInput.TaxCalcType, taxRoundType: addedInput.TaxRoundType, note: addedInput.Note, updateDateTime: this.Executor.ExecuteDateTime, updateUserId: this.Executor.UserId ); entites.Add(entity); } // マスタ更新 this.PutRepository.Put(entites); // コミット dataAccessContext.CommitTransaction(); return(this.Output); }
public void CreateWithNullTest() { var o = CustomerFactory.Create(null); Assert.IsNotNull(o); }
public void Context() { var factory = new CustomerFactory(); _customer = factory.Create(); }