public async Task ThrowsExceptionWhenOrderStatusIsPaidAndWeTriesToSetTheSameStatusAgain() { //Arrange var customerRepository = new CustomerRepository(_dbContext); var suitAlterationRepository = new SuitAlterationRepository(_dbContext); var customer = CreateNewCustomer(); await customerRepository.AddAsync(customer); customer.PlaceOrder(5, 5, 5, 5); await _unitOfWork.CommitAsync(CancellationToken.None); //Act var order = customer.SuitAlterations.Single(); var markOrderAsPaidCommandHandler = new MarkOrderAsPaidCommandHandler(suitAlterationRepository); await markOrderAsPaidCommandHandler.Handle(new MarkOrderAsPaidCommand(order.Id), CancellationToken.None); await _unitOfWork.CommitAsync(CancellationToken.None); //Pre-assert order.DomainEvents.Should().ContainEquivalentOf(new OrderPaidDomainEvent(order.Id)); //imagine that we got OrderPaidNotification second time Func <Task> action = async() => await markOrderAsPaidCommandHandler.Handle(new MarkOrderAsPaidCommand(order.Id), CancellationToken.None); //Assert action.Should().Throw <BusinessRuleValidationException>().WithMessage( $"Order has inconsistent status to be marked as paid. Status - {order.Status.ToString()}"); order.DomainEvents.Count.Should().Be(2); }
public async Task UpdatesCustomerOrderStatusToPaidAfterTheReceivingOfOrderPaidNotification() { //Arrange var customerRepository = new CustomerRepository(_dbContext); var suitAlterationRepository = new SuitAlterationRepository(_dbContext); var customer = CreateNewCustomer(); await customerRepository.AddAsync(customer); customer.PlaceOrder(5, 5, 5, 5); await _unitOfWork.CommitAsync(CancellationToken.None); //Pre-assert var order = customer.SuitAlterations.Single(); order.Status.Should().Be(SuitAlterationStatus.Created); //Act var markOrderAsPaidCommandHandler = new MarkOrderAsPaidCommandHandler(suitAlterationRepository); await markOrderAsPaidCommandHandler.Handle(new MarkOrderAsPaidCommand(order.Id), CancellationToken.None); await _unitOfWork.CommitAsync(CancellationToken.None); //Assert SuitAlteration paidOrder = await suitAlterationRepository.GetByIdAsync(order.Id); order.DomainEvents.Should().ContainEquivalentOf(new OrderPaidDomainEvent(order.Id)); paidOrder.Status.Should().Be(SuitAlterationStatus.Paid); order.DomainEvents.Count.Should().Be(2); }