/// <summary> /// Processes a save customer order request. /// </summary> /// <param name="request">The save customer order request.</param> /// <returns>The customer order service default response.</returns> private static Response SaveCustomerOrder(SaveCustomerOrderRealtimeRequest request) { if (request == null) { throw new ArgumentNullException("request"); } if (request.SalesTransaction == null) { throw new ArgumentException("SalesTransaction is not set in request", "request"); } if (request.ChannelConfiguration == null) { throw new ArgumentException("ChannelConfiguration is not set in request", "request"); } SalesTransaction salesTransaction = request.SalesTransaction; if (salesTransaction.CustomerOrderMode == CustomerOrderMode.Cancellation) { return(CustomerOrderService.SaveCancellationOrder(request)); } return(SaveCustomerOrderInHeadquarter(request)); }
public void When_SpecialCustomer_Expect_20PercentDiscount() { // A test case body is divided into three sections "AAA" denotes the Arrange, Act, and Assert. //Arrange Customer specialCustomer = new Customer { CustomerId = 1, CustomerName = "Jasmine", CustomerType = CustomerType.SpecialCustomer }; Order order = new Order { OrderId = 2, ProductId = 500, ProductQuantity = 2, Amount = 1000 }; CustomerOrderService customerOrderService = new CustomerOrderService(); //Act customerOrderService.ApplyDiscount(specialCustomer, order); Console.WriteLine(order.Amount); //Assert Assert.AreEqual(order.Amount, 800); }
public void When_PremiumCustomer_Expect_10PercentDiscount() { // A test case body is divided into three sections "AAA" denotes the Arrange, Act, and Assert. //Arrange Customer premiumCustomer = new Customer { CustomerId = 1, CustomerName = "George", CustomerType = CustomerType.Premium }; Order order = new Order { OrderId = 1, ProductId = 212, ProductQuantity = 1, Amount = 400 }; CustomerOrderService customerOrderService = new CustomerOrderService(); //Act customerOrderService.ApplyDiscount(premiumCustomer, order); Console.WriteLine(order.Amount); //Assert Assert.AreEqual(order.Amount, 360); }
public void GetData_Object() { CustomerOrderService service = new CustomerOrderService(); var res = service.getData(1000); Assert.IsInstanceOf <Customer>(res); }
public void When_PremiumCustomer_Expect_10PercentDiscount() { //Arrange Customer premiumCustomer = new Customer { CustomerId = 1, CustomerName = "George", CustomerType = CustomerType.Premium }; Order order = new Order { OrderId = 1, ProductId = 212, ProductQuantity = 1, Amount = 150 }; CustomerOrderService customerOrderService = new CustomerOrderService(); //Act customerOrderService.ApplyDiscount(premiumCustomer, order); Assert.AreEqual(order.Amount, 135); }
public void GetData_100_RetStringData() { CustomerOrderService service = new CustomerOrderService(); var res = service.getData(100); Assert.IsInstanceOf <string>(res); }
public void GetData_200_RetIntegerData() { CustomerOrderService service = new CustomerOrderService(); var res = service.getData(200); Assert.AreEqual(1900, res); }
public void GetCustomer_InvalidId_RetException() { CustomerOrderService service = new CustomerOrderService(); //var res = service.GetCustomer(10); Assert.Throws <CustomerNotFoundException>(() => service.GetCustomer(50)); }
/// <summary>Main entry-point for this application.</summary> /// <param name="args">An array of command-line argument strings.</param> static void Main(string[] args) { CustomerService customerService = new CustomerService(); CustomerOrderService customerOrderService = new CustomerOrderService(); Console.WriteLine("Getting all customers. Please wait."); List <Customer> customers = customerService.GetAll(); DisplayInfoForAllCustomers(customers); Console.WriteLine($"Getting customer by id of {Constants.CUSTOMER_ID}"); Customer customer = customerService.GetById(Constants.CUSTOMER_ID); DisplayInfoForCustomer(customer); Customer newCustomer = CreateNewCustomerAndShowResponse(customerService); UpdateCustomerAndShowResponse(customerService, customers.First()); GetAndDisplayInfoForAllOrders(customerOrderService); CreateNewCustomerOrderAndShowResponse(customerOrderService, newCustomer); Console.ReadLine(); }
public CustomersOrderController(UserManager um, CustomerService cs, CustomerOrderService cos, DictService ds) { this.um = um; this.cs = cs; this.cos = cos; this.ds = ds; }
public void GetCustomer_ValidId_RetCustType() { CustomerOrderService service = new CustomerOrderService(); var res = service.GetCustomer(10); Assert.IsInstanceOf <Customer>(res); }
public void When_PremiumCustomer_Expect_10PercentDiscount() { //Arrange Customer premiumCustomer = new Customer { CustomerId = 1, CustomerName = "Mahesh", CustomerType = CustomerType.Premium }; Order order = new Order { OrderId = 1, ProductId = 212, ProductQuantity = 1, Amount = 300 }; CustomerOrderService customerOrderServiceVar = new CustomerOrderService(); //Act customerOrderServiceVar.ApplyDiscount10Percent(premiumCustomer, order); //Assert //Assert.AreEqual(order.Amount, 270); //Assert.Fail("The test is failed."); if (order.Amount < 280) { Assert.Fail("The test is passed."); } else { Assert.Pass("The test is failed"); } }
/// <summary> /// Cancels a customer order on the headquarters. /// </summary> /// <param name="request">The save customer order request.</param> /// <returns>The customer order service default response.</returns> private static Response SaveCancellationOrder(SaveCustomerOrderRealtimeRequest request) { Response response; SalesTransaction salesTransaction = request.SalesTransaction; ChannelConfiguration channelConfiguration = request.ChannelConfiguration; // Keep all charge line references List <ChargeLine> chargeLines = new List <ChargeLine>(salesTransaction.ChargeLines); if (!string.IsNullOrWhiteSpace(channelConfiguration.CancellationChargeCode)) { // Get all cancellation charges var cancellationChargeLines = salesTransaction.ChargeLines .Where(chargeLine => channelConfiguration.CancellationChargeCode.Equals(chargeLine.ChargeCode, StringComparison.OrdinalIgnoreCase)) .ToArray(); // Remove all non-cancellation charges from header - since AX will blindly use the charges to header as cancellation charges salesTransaction.ChargeLines.Clear(); salesTransaction.ChargeLines.AddRange(cancellationChargeLines); } // Cancels order in headquarters response = CustomerOrderService.SaveCustomerOrderInHeadquarter(request); // Restore charge lines salesTransaction.ChargeLines.Clear(); salesTransaction.ChargeLines.AddRange(chargeLines); return(response); }
public virtual async Task DeleteAsync(string[] ids) { using (var repository = SubscriptionRepositoryFactory()) { var subscriptions = await GetByIdsAsync(ids); if (!subscriptions.IsNullOrEmpty()) { var changedEntries = subscriptions.Select(x => new GenericChangedEntry <Subscription>(x, EntryState.Deleted)); await EventPublisher.Publish(new SubscriptionChangingEvent(changedEntries)); //Remove subscription order prototypes var orderPrototypesIds = repository.Subscriptions.Where(x => ids.Contains(x.Id)).Select(x => x.CustomerOrderPrototypeId).ToArray(); await CustomerOrderService.DeleteAsync(orderPrototypesIds); await repository.RemoveSubscriptionsByIdsAsync(ids); await repository.UnitOfWork.CommitAsync(); await EventPublisher.Publish(new SubscriptionChangedEvent(changedEntries)); ClearCacheFor(subscriptions); } } }
protected override async Task OnInitializedAsync() { IsLoading = true; var result = await CustomerOrderService.GetOrder(Id); Order = result.Data; IsLoading = false; }
// // GET: /Coupons/ public ActionResult Index() { var customerOrderService = new CustomerOrderService(); var customerName = customerOrderService.GetCustomerName(lastName: "Mason"); var model = customerOrderService.GetCustomerOrderItems(5); return(View()); }
public virtual async Task SaveSubscriptionsAsync(Subscription[] subscriptions) { var pkMap = new PrimaryKeyResolvingMap(); var changedEntries = new List <GenericChangedEntry <Subscription> >(); using (var repository = SubscriptionRepositoryFactory()) { var existEntities = await repository.GetSubscriptionsByIdsAsync(subscriptions.Where(x => !x.IsTransient()).Select(x => x.Id).ToArray()); foreach (var subscription in subscriptions) { //Generate numbers for new subscriptions if (string.IsNullOrEmpty(subscription.Number)) { var store = await StoreService.GetByIdAsync(subscription.StoreId); var numberTemplate = store.Settings.GetSettingValue("Subscription.SubscriptionNewNumberTemplate", "SU{0:yyMMdd}-{1:D5}"); subscription.Number = UniqueNumberGenerator.GenerateNumber(numberTemplate); } //Save subscription order prototype with same as subscription Number if (subscription.CustomerOrderPrototype != null) { subscription.CustomerOrderPrototype.Number = subscription.Number; subscription.CustomerOrderPrototype.IsPrototype = true; await CustomerOrderService.SaveChangesAsync(new[] { subscription.CustomerOrderPrototype }); } var originalEntity = existEntities.FirstOrDefault(x => x.Id == subscription.Id); var originalSubscription = originalEntity != null?originalEntity.ToModel(AbstractTypeFactory <Subscription> .TryCreateInstance()) : subscription; var modifiedEntity = AbstractTypeFactory <SubscriptionEntity> .TryCreateInstance().FromModel(subscription, pkMap); if (originalEntity != null) { changedEntries.Add(new GenericChangedEntry <Subscription>(subscription, originalEntity.ToModel(AbstractTypeFactory <Subscription> .TryCreateInstance()), EntryState.Modified)); modifiedEntity.Patch(originalEntity); //force the subscription.ModifiedDate update, because the subscription object may not have any changes in its properties originalEntity.ModifiedDate = DateTime.UtcNow; } else { repository.Add(modifiedEntity); changedEntries.Add(new GenericChangedEntry <Subscription>(subscription, EntryState.Added)); } } //Raise domain events await EventPublisher.Publish(new SubscriptionChangingEvent(changedEntries)); await repository.UnitOfWork.CommitAsync(); pkMap.ResolvePrimaryKeys(); await EventPublisher.Publish(new SubscriptionChangedEvent(changedEntries)); } ClearCacheFor(subscriptions); }
private async Task GetOrders() { IsLoading = true; Uri uri = NavigationManager.ToAbsoluteUri(NavigationManager.Uri); PagedResponse = await CustomerOrderService.GetOrders(uri.Query); IsLoading = false; }
public async Task <JsonResult> COGet() { try { var oid = Guid.Parse(Request.Form["id"]); var uid = Guid.Parse(Request.Form["uid"]); var iS = Boolean.Parse(Request.Form["iS"]); var data = CustomerOrderService.GetByOIDUID(oid, uid, iS); var vms = CustomerOrderService.SetSubDatas(data); return(Success(vms)); } catch { return(Failed(MessageUtilityService.ServerError())); } }
public void GetDiscount_CustomBasic_RetTenPerDiscount() { //Arrange Customer cust = new Customer(10, "Mukta", "P", CustomerType.SpecialCustomer); Order order = new Order(10, 10, 10, 1000); CustomerOrderService service = new CustomerOrderService(); //Act var result = service.GetDiscount(cust, order); //Assert Assert.AreEqual(500, result); }
protected override async Task OnInitializedAsync() { IsLoading = true; var result = await CustomerOrderService.GetOrder(Id); Order = result.Data; OrderUpdate = new CustomerOrderForUpdateDto() { Status = Order.Status }; IsLoading = false; }
public void GetDiscount_CustomerPremium_RetThirtyPerCentDiscount() { //Arrange Customer cust = new Customer(10, "Sachin", "T", CustomerType.Premium); Order order = new Order(10, 10, 10, 1000); CustomerOrderService service = new CustomerOrderService(); //Act var result = service.GetDiscount(cust, order); //Assert Assert.AreEqual(700, result); }
public void GetDiscount_CustomerNormal_RetFiftyPerCentDiscount() { //Arrange Customer cust = new Customer(10, "Sachin", "T", CustomerType.SpecialCustomer); Order order = new Order(10, 10, 10, 1000); CustomerOrderService service = new CustomerOrderService(); //Act var result = service.GetDiscount(cust, order); //Assert Assert.AreEqual(500, result); }
protected async Task HandleFormSubmit() { var result = await CustomerOrderService.CreateOrder(Order); if (result != null) { ToastService.ShowSuccess($"Užsakymas '{result.Id}' yra sėkmingai sukurtas"); NavigationManager.NavigateTo("/orders"); } else { ToastService.ShowError("Nepavyko sukurti užsakymo"); } }
protected async Task HandleFormSubmit() { var result = await CustomerOrderService.EditOrder(Id, OrderUpdate); if (result != null) { ToastService.ShowSuccess($"Gamybos užsakyms '{Order.Id}' yra sėkmnigai atnaujintas"); NavigationManager.NavigateTo("/orders"); } else { ToastService.ShowError("Nepavyko atnaujinti gamybos užsakymo"); } }
public void GetDiscount_CustomerBasic_RetTenPerCentDiscount() { //Arrange Customer cust = new Customer(10, "Sachin", "T", CustomerType.Basic); Order order = new Order(10, 10, 10, 1000); CustomerOrderService service = new CustomerOrderService(); //Act var result = service.GetDiscount(cust, order); //Assert Assert.AreEqual(900, result); //Assert.LessOrEqual(900, result); //Assert.GreaterOrEqual(900, result); }
public void GetCoupon() { //Arrange Customer cust = new Customer(10, "Sachin", "T", CustomerType.Basic); Order order = new Order(10, 10, 10, 1000); CustomerOrderService service = new CustomerOrderService(); //Act var res = service.GetCouponCode(cust, order); //Assert StringAssert.StartsWith("BasicA", res); //StringAssert.Contains("BasicA", res); //StringAssert.IsMatch("BasicA*.*", res); //StringAssert.AreEqualIgnoringCase("nunit", "Nunit"); }
public async Task <JsonResult> COnsert() { try { var id = Guid.Parse(Request.Form["id"]); var uid = Guid.Parse(Request.Form["uid"]); var oid = Guid.Parse(Request.Form["oid"]); var aid = Guid.Parse(Request.Form["aid"]); var dtid = Guid.Parse(Request.Form["dtid"]); var iS = Boolean.Parse(Request.Form["iS"]); var tc = float.Parse(Request.Form["tc"]); if (CustomerOrderService.Insert(id, uid, oid, aid, dtid, iS, tc)) { return(Success(id.ToString())); } return(Failed(MessageUtilityService.FailedInsert("Customer Order"))); } catch { return(Failed(MessageUtilityService.ServerError())); } }
public void IsApplicableToDiscount_BasicCustomer_False() { //Arrange : DO the arrangement for calling unit under Test Customer cust = new Customer(10, "Sachin", "T", CustomerType.Basic); CustomerOrderService service = new CustomerOrderService(); //Act //Call method under Test var Result = service.IsApplicableToDiscount(cust); //Assert: Check Actual output with excpected output //Assert.IsFalse(Result); Assert.AreEqual(false, Result); }
// GET api/customerorder/5 /// <summary> /// Get method for customer order based on customer id parameter /// </summary> /// <param name="id"></param> /// <returns>A collection of customer order as JSON format (default)</returns> public HttpResponseMessage Get(int id) { try { var dbRepository = new CE_DB_ServiceRepository(); var customerOrderService = new CustomerOrderService(dbRepository); var customerOrderData = customerOrderService.GetCustomerOrder(id); return(Request.CreateResponse(HttpStatusCode.OK, customerOrderData)); } catch (Exception ex) { // TODO - log the exception so the app won't miss the error. throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError) { ReasonPhrase = "Error has occured" }); } }