示例#1
0
        public async Task DeleteCustomerTaskOk()
        {
            // Arrange

            DeleteCustomerCommandHandler commandHandler = new DeleteCustomerCommandHandler(_unitOfWork, _bus, _notifications);
            Guid customerId = new Guid("43A38AC8-EAA9-4DF0-981F-2685882C7C45");
            DeleteCustomerCommand command = new DeleteCustomerCommand()
            {
                Id = customerId
            };

            _validator.Validate(command).IsValid.ShouldBeTrue();
            // Act
            Unit responseUnit = await commandHandler.Handle(command, CancellationToken.None);

            Customer customer = _unitOfWork.Repository.CustomerRepository.SingleOrDefault(e => e.Id == customerId);

            // Assert
            customer.ShouldNotBeNull();
            customer.Id.ShouldBe(customerId);
            customer.IsEnabled.ShouldBe(false);
        }
示例#2
0
        public void ItShouldFailIfCustomerDoesNotExist()
        {
            Customer customer  = null;
            var      readStore = new Mock <ICustomerRepository>();

            readStore.Setup(_ => _.GetCustomerById(It.IsAny <int>())).ReturnsAsync(customer);

            var sut    = new DeleteCustomerCommandValidator(readStore.Object);
            var result = sut.Validate(new DeleteCustomerCommand {
                Id = 1
            });

            result.IsValid.ShouldBe(false);
            result.Errors[0].ErrorMessage.ShouldBe("Customer must exist to delete");
        }
示例#3
0
        public void ItShouldDeleteIfExistingCustomer()
        {
            var customer = new Customer {
                CustomerId = 1
            };
            var readStore = new Mock <ICustomerRepository>();

            readStore.Setup(_ => _.GetCustomerById(It.IsAny <int>())).ReturnsAsync(customer);

            var sut    = new DeleteCustomerCommandValidator(readStore.Object);
            var result = sut.Validate(new DeleteCustomerCommand {
                Id = 1
            });

            result.IsValid.ShouldBe(true);
        }