public void ShouldReturnFalseIfOrderStateIsNull() { // Arrange Order order = new Order(); // Act bool result = this.orderSecurity.CanCancel(order); // Assert result.Should().Be(false); }
public void ShouldManageOrderSecurityAccordingToOrderStateCode(string code, bool expected) { // Arrange Order order = new Order { State = new State { Code = code } }; // Act bool result = this.orderSecurity.CanCancel(order); // Assert result.Should().Be(expected); }
/// <summary> /// Determines whether this instance can cancel the specified order. /// The decision is made according to the value of the Order.State.Code. /// When it equals 'New', 'Open', 'InProcess' cancellation is allowed. /// Otherwise not. /// </summary> /// <param name="order">The order.</param> /// <returns> /// <c>true</c> if this instance can cancel the specified order; otherwise, <c>false</c>. /// </returns> public override bool CanCancel(Order order) { if (order.State != null) { if ((order.State.Code == OrderStateCode.New) || (order.State.Code == OrderStateCode.Open) || (order.State.Code == OrderStateCode.InProcess)) { return true; } } return false; }
public void ShouldSetOrderStateNameToCancelled() { // Arrange var strategy = new SampleOrderCancelationStrategy(); var order = new Order { State = new State { Name = OrderStateCode.New } }; // Act strategy.Process(order); // Assert order.State.Name.Should().Be(OrderStateCode.Cancelled); }
/// <summary> /// Creates this instance. /// </summary> /// <returns>New order.</returns> public Order Create() { var orderId = this.idGenerator.Generate(); var state = this.stateConfiguration.GetStates().SingleOrDefault(s => s.Code == OrderStateCode.New); var currency = this.currencyProvider.Get(this.shopContext.GeneralSettings.DisplayCurrency); Assert.IsNotNull(state, "Unable to create the order. State was not found."); var order = new Order { OrderId = orderId, ShopContext = this.shopContext.InnerSite.Name, PricingCurrencyCode = currency.Code, State = state, PaymentMeans = new PaymentMeans { PaymentChannelCode = this.paymentChannelCode } }; order.PaymentMeans.PaymentDueDate = order.IssueDate; var endDate = order.IssueDate.AddDays(7); var delivery = new Delivery { LatestDeliveryDate = endDate, LatestDeliveryTime = order.IssueTime, RequestedDeliveryPeriod = new Period { StartDate = order.IssueDate, EndDate = endDate, StartTime = order.IssueTime, EndTime = order.IssueTime }, DeliveryLocation = new Location { ValidityPeriod = new Period { StartDate = order.IssueDate, EndDate = endDate, StartTime = order.IssueTime, EndTime = order.IssueTime } } }; order.Delivery = new Collection <Delivery> { delivery }; return(order); }
/// <summary> /// Gets logging entry for success. /// </summary> /// <param name="order">The order.</param> /// <returns> /// Logging Entry. /// </returns> public override LogEntry GetLogEntryForSuccess(Order order) { Assert.ArgumentNotNull(order, "order"); var max = order.OrderLines.Max(ol => ol.LineItem.Quantity); var orderLine = order.OrderLines.First(ol => ol.LineItem.Quantity == max); var name = orderLine.LineItem.Item.Name; var code = orderLine.LineItem.Item.Code; var quantity = orderLine.LineItem.Quantity; string filledTemplate = string.Format(Constants.MarkedAsSuspiciousSuccessfully, name, code, quantity); return this.GetLogEntry(order, filledTemplate, Constants.ApprovedResult); }
/// <summary> /// Initializes a new instance of the <see cref="CancelOrderPresenterTest" /> class. /// </summary> public CancelOrderPresenterTest() { this.view = Substitute.For<ICancelOrderView>(); this.orderProcessor = Substitute.For<VisitorOrderProcessorBase>(); this.orderManager = Substitute.For<VisitorOrderManager, IUserAware>(); this.httpContext = Substitute.For<HttpContextBase>(); new CancelOrderPresenter(this.view, this.orderManager, this.orderProcessor) { HttpContext = this.httpContext }; this.httpContext.Request.QueryString.Returns(new NameValueCollection { { "id", "yyy" }, { "user", "111" } }); this.order = new Order { OrderId = "yyy", BuyerCustomerParty = new CustomerParty { SupplierAssignedAccountID = "111" } }; this.orders = new Collection<Order> { this.order }.AsQueryable(); this.orderManager.GetAll().Returns(this.orders); }
/// <summary> /// Initializes a new instance of the <see cref="OrdersPresenterTest" /> class. /// </summary> public OrdersPresenterTest() { this.orderManager = Substitute.For<VisitorOrderManager, IUserAware>(); this.coreOrderManager = Substitute.For<SampleOrderManager>(Substitute.For<CoreOrderStateConfiguration>(), Substitute.For<Repository<Order>>()); var order1 = new Order { OrderId = "first", BuyerCustomerParty = new CustomerParty { SupplierAssignedAccountID = "111" } }; var order2 = new Order { OrderId = "second", BuyerCustomerParty = new CustomerParty { SupplierAssignedAccountID = "111" } }; this.orders = new Collection<Order> { order1, order2 }.AsQueryable(); this.orderManager.GetAll().Returns(this.orders); this.coreOrderManager.GetAllOrders(Arg.Any<Expression<Func<Order, bool>>>()).Returns(this.orders); this.view = Substitute.For<IOrdersView>(); this.httpContext = Substitute.For<HttpContextBase>(); new OrdersPresenter(this.view, this.orderManager, this.coreOrderManager) { HttpContext = this.httpContext }; this.httpContext.Request.QueryString.Returns(new NameValueCollection { { "user", "111" } }); }
/// <summary> /// Gets the logging entry. /// </summary> /// <param name="order">The order.</param> /// <param name="template">The template.</param> /// <param name="result">The result.</param> /// <returns> /// The logging entry. /// </returns> internal override LogEntry GetLogEntry(Order order, string template, string result) { Assert.ArgumentNotNull(order, "order"); Assert.ArgumentNotNull(template, "template"); Assert.ArgumentNotNull(result, "result"); return new LogEntry { Details = new LogEntryDetails(template), Action = Constants.MarkAsSuspicious, EntityID = order.OrderId, EntityType = Constants.OrderEntityType, LevelCode = Constants.UserLevel, Result = result }; }
/// <summary> /// Saves the single order. /// </summary> /// <param name="order">The order.</param> public virtual void SaveSingleOrder(Order order) { // this.SaveOrder(order); }
public override void Create(Order order) { Assert.ArgumentNotNull(order, "order"); Assert.IsTrue(order.ID == Guid.Empty, "Unable to create the order. Order ID must be empty."); if (!this.stateConfiguration.IsValid(order.State)) { throw new InvalidStateConfigurationException(); } this.calculationStrategy.ApplyCalculations(order); this.innerRepository.Save(new[] { order }); }
/// <summary> /// Applies the calculations to the order. /// </summary> /// <param name="order">The order.</param> public void ApplyCalculations(Order order) { new ProcessingOrder(order).ApplyCalculations(); }
/// <summary> /// Performs fail processing. /// </summary> /// <param name="order">The order.</param> /// <param name="parameters">The parameters.</param> /// <returns> /// Gets logging entry for fail. /// </returns> public override LogEntry GetLogEntryForFail(Order order, params object[] parameters) { return this.GetLogEntry(order, Constants.FailedToMarkAsSuspicious, Constants.DeniedResult); }
/// <summary> /// Creates this instance. /// </summary> /// <returns>New order.</returns> public Order Create() { var orderId = this.idGenerator.Generate(); var state = this.stateConfiguration.GetStates().SingleOrDefault(s => s.Code == OrderStateCode.New); var currency = this.currencyProvider.Get(this.shopContext.GeneralSettings.DisplayCurrency); Assert.IsNotNull(state, "Unable to create the order. State was not found."); var order = new Order { OrderId = orderId, ShopContext = this.shopContext.InnerSite.Name, PricingCurrencyCode = currency.Code, State = state, PaymentMeans = new PaymentMeans { PaymentChannelCode = this.paymentChannelCode } }; order.PaymentMeans.PaymentDueDate = order.IssueDate; var endDate = order.IssueDate.AddDays(7); var delivery = new Delivery { LatestDeliveryDate = endDate, LatestDeliveryTime = order.IssueTime, RequestedDeliveryPeriod = new Period { StartDate = order.IssueDate, EndDate = endDate, StartTime = order.IssueTime, EndTime = order.IssueTime }, DeliveryLocation = new Location { ValidityPeriod = new Period { StartDate = order.IssueDate, EndDate = endDate, StartTime = order.IssueTime, EndTime = order.IssueTime } } }; order.Delivery = new Collection<Delivery> { delivery }; return order; }