Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public void ThrowsExceptionWhenEntityIdNotFound()
        {
            //Arrange
            var suitAlterationRepository = new SuitAlterationRepository(_dbContext);
            var orderId = new SuitAlterationId(Guid.NewGuid());

            //Act
            Func <Task> action = async() => await suitAlterationRepository.GetByIdAsync(orderId);

            //Assert
            action.Should().Throw <EntityNotFoundException>()
            .WithMessage($"Entity with id={orderId} not found");
        }