Esempio n. 1
0
        public async Task CreateCustomerTaskOk()
        {
            // Arrange

            CreateCustomerCommandHandler commandHandler = new CreateCustomerCommandHandler(_unitOfWork, _bus, _notifications);
            CreateCustomerCommand        command        = new CreateCustomerCommand()
            {
                FirstName      = "Franky",
                LastName       = "Quintero",
                Telephone      = "573004436932",
                Company        = "UPC",
                Email          = "*****@*****.**",
                AddressCity    = "La Jagua de Ibirico",
                AddressZipCode = "203020",
                AddressLine1   = "B.Santander",
                AddressLine2   = "",
                CountryId      = new Guid("32BB805F-40A4-4C37-AA96-B7945C8C385C")
            };

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

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

            // Assert
            customer.ShouldNotBeNull();
            customer.Id.ShouldBe(customerId);
            customer.FirstName.ShouldBe("Franky");
            customer.LastName.ShouldBe("Quintero");
            customer.Telephone.ShouldBe("573004436932");
            customer.Company.ShouldBe("UPC");
            customer.Email.ShouldBe("*****@*****.**");
            customer.Address.City.ShouldBe("La Jagua de Ibirico");
            customer.Address.ZipCode.ShouldBe("203020");
            customer.Address.AddressLine1.ShouldBe("B.Santander");
            customer.Address.AddressLine2.ShouldBe("");
            customer.CountryId.ShouldBe(new Guid("32BB805F-40A4-4C37-AA96-B7945C8C385C"));
        }
Esempio n. 2
0
        public void ShouldContainNoErrors()
        {
            // Arrange
            var command = new CreateCustomerCommand("Code", "Name", "Source");

            // Act
            var validationResult = _validator.Validate(command);
            var exists           = validationResult.Errors.Count > 0;

            // Assert
            exists.Should().BeFalse();
        }
        public void FailsIfEmailInvalid(string email, bool expectedValid)
        {
            var command = new CreateCustomerCommand
            {
                FirstName    = "Herbert",
                LastName     = "Scrackle",
                EmailAddress = email
            };

            var sut = new CreateCustomerCommandValidator();

            var result = sut.Validate(command);

            result.IsValid.Should().Be(expectedValid);
        }
        public void FailsIfLastNameNotProvided(string lastName, bool expectedValid)
        {
            var command = new CreateCustomerCommand
            {
                FirstName    = "Herbert",
                LastName     = lastName,
                EmailAddress = "*****@*****.**"
            };

            var sut = new CreateCustomerCommandValidator();

            var result = sut.Validate(command);

            result.IsValid.Should().Be(expectedValid);
        }
        public void ItShouldCreateIfNewCustomer()
        {
            Customer customer  = null;
            var      readStore = new Mock <ICustomerRepository>();

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

            var sut    = new CreateCustomerCommandValidator(readStore.Object);
            var result = sut.Validate(new CreateCustomerCommand
            {
                Id        = 1,
                FirstName = "first",
                LastName  = "last",
            });

            result.IsValid.ShouldBe(true);
        }
        public void ItShouldNotCreateIfExists()
        {
            var customer = new Customer {
                CustomerId = 1
            };
            var readStore = new Mock <ICustomerRepository>();

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

            var sut    = new CreateCustomerCommandValidator(readStore.Object);
            var result = sut.Validate(new CreateCustomerCommand
            {
                Id        = 1,
                FirstName = "first",
                LastName  = "last",
            });

            result.IsValid.ShouldBe(false);
            result.Errors[0].ErrorMessage.ShouldBe("Customer already exists");
        }