public void TestChangeDeliverDateOk() { //SETUP var options = SqliteInMemory.CreateOptions <EfCoreContext>(); using (var context = new EfCoreContext(options)) { context.Database.EnsureCreated(); context.SeedDatabaseFourBooks(); context.SeedDummyOrder(); var service = new ChangeDeliveryAction(new ChangeDeliverDbAccess(context)); var newDeliverDate = DateTime.Today.AddDays(2); if (newDeliverDate.DayOfWeek == DayOfWeek.Sunday) { newDeliverDate = newDeliverDate.AddDays(1); } var dto = new BizChangeDeliverDto { UserId = DddEfTestData.DummyUserId, OrderId = context.Orders.Single().OrderId, NewDeliveryDate = newDeliverDate }; //ATTEMPT service.BizAction(dto); //VERIFY service.HasErrors.ShouldBeFalse(); context.Orders.Single().ExpectedDeliveryDate.ShouldEqual(newDeliverDate); } }
public void BizAction(BizChangeDeliverDto dto) { var order = _dbAccess.GetOrder(dto.OrderId); if (order == null) { throw new NullReferenceException("Could not find the order. Someone entering illegal ids?"); } var status = order.ChangeDeliveryDate(dto.UserId, dto.NewDeliveryDate); CombineStatuses(status); Message = $"Your new delivery date is {dto.NewDeliveryDate.ToShortDateString()}."; }
public void BizAction(BizChangeDeliverDto dto) { var order = _repo.GetOrder(dto.OrderId); if (order == null) { throw new NullReferenceException("Could not find the order. Someone entering illegal ids?"); } var status = order.ChangeDeliveryDate(dto.UserId, dto.NewDeliveryDate); CombineStatuses(status); if (!status.HasErrors && _repo.ChangeOrderDeliveryDate(order.OrderId, order.ExpectedDeliveryDate)) { Message = $"Your new delivery date is {dto.NewDeliveryDate.ToShortDateString()}."; } else { AddError("Fail to change delivery date."); } }
public void BizAction(BizChangeDeliverDto dto) { var order = _dbAccess.GetOrder(dto.OrderId); if (order == null) { throw new NullReferenceException("Could not find the order. Someone entering illegal ids?"); } if (order.CustomerName != dto.UserId) { AddError("I'm sorry, but that order does not belong to you"); //Log a security issue return; } if (order.HasBeenDelivered) { AddError("I'm sorry, but that order has been delivered."); return; } if (dto.NewDeliveryDate < DateTime.Today.AddDays(1)) { AddError("I'm sorry, we cannot get the order to you that quickly. Please choose a new date.", "NewDeliveryDate"); return; } if (dto.NewDeliveryDate.DayOfWeek == DayOfWeek.Sunday) { AddError("I'm sorry, we don't deliver on Sunday. Please choose a new date.", "NewDeliveryDate"); return; } //All Ok order.ExpectedDeliveryDate = dto.NewDeliveryDate; Message = $"Your new delivery date is {dto.NewDeliveryDate.ToShortDateString()}."; }