public void isValidForCreation_givenAnId_thenNotValidForCreation() { Assert.False(new CustomerValidator() .IsValidForCreation(CustomerTestBuilder.ACustomer() .WithId(Guid.NewGuid()) .Build())); }
public void GenerateId_GivenCustomerWithoutId_WhenGeneratingId_ThenGenerateId() { Entity customer = CustomerTestBuilder.ACustomer().Build(); customer.GenerateId(); Assert.NotEqual(Guid.Empty, customer.Id); }
public void Get() { var savedCustomer = _repository.Save(CustomerTestBuilder.ACustomer().Build()); var actualCustomer = _repository.Get(savedCustomer.Id); Assert.Equal(actualCustomer, savedCustomer); }
public void Save() { var customerToSave = CustomerTestBuilder.ACustomer().Build(); var savedCustomer = _repository.Save(customerToSave); Assert.NotEqual(Guid.Empty, savedCustomer.Id); Assert.Equal(savedCustomer, _repository.Get(savedCustomer.Id)); }
public void isValidForCreation_givenSomeMissingValues_thenNotValidForCreation() { Assert.False(new CustomerValidator() .IsValidForCreation(CustomerTestBuilder.ACustomer() .WithId(Guid.NewGuid()) .WithFirstname("") .WithLastname(null) .WithEmail(null) .Build())); }
public void CreateCustomer_HappyPath() { Customer customer = CustomerTestBuilder.ACustomer().Build(); Customer createdCustomer = _customerService.CreateCustomer(customer); Assert.NotNull(createdCustomer); Assert.Equal(JsonConvert.SerializeObject(customer), JsonConvert.SerializeObject(_customerRepository.Get(createdCustomer.Id))); }
public void GetAll() { var customer1 = _repository.Save(CustomerTestBuilder.ACustomer().Build()); var customer2 = _repository.Save(CustomerTestBuilder.ACustomer().Build()); var customers = _repository.GetAll(); //Assert.IsType<Customer>(_repository.get) Assert.Contains(customer1, customers); Assert.Contains(customer2, customers); }
public void CreateCustomer() { Customer customerToCreate = CustomerTestBuilder.ACustomer().Build(); Customer createdCustomer = _customerService.CreateCustomer(customerToCreate); var customer = _customerRepository.Get(customerToCreate.Id); Assert.Equal(JsonConvert.SerializeObject(customerToCreate), JsonConvert.SerializeObject(customer)); Assert.Equal(JsonConvert.SerializeObject(createdCustomer), JsonConvert.SerializeObject(customer)); }
public void generateId_givenCustomerWithId_whenGeneratingId_thenThrowException() { var id = Guid.NewGuid(); Entity customer = CustomerTestBuilder.ACustomer() .WithId(id) .Build(); Exception ex = Assert.Throws <Exception>(() => customer.GenerateId()); Assert.Equal("Generating an ID for a customer that already has an ID (" + id + ") is not allowed.", ex.Message); }
public void GetAllCustomers() { Customer customer1 = _customerService.CreateCustomer(CustomerTestBuilder.ACustomer().Build()); Customer customer2 = _customerService.CreateCustomer(CustomerTestBuilder.ACustomer().Build()); Customer customer3 = _customerService.CreateCustomer(CustomerTestBuilder.ACustomer().Build()); var allCustomers = _customerService.GetAllCustomers().ToList(); Assert.Contains(JsonConvert.SerializeObject(customer1), JsonConvert.SerializeObject(allCustomers)); Assert.Contains(JsonConvert.SerializeObject(customer2), JsonConvert.SerializeObject(allCustomers)); Assert.Contains(JsonConvert.SerializeObject(customer3), JsonConvert.SerializeObject(allCustomers)); }
public void CreateCustomer_HappyPath() { Customer customer = CustomerTestBuilder.ACustomer().Build(); _customerRepository.Save(customer).Returns(customer); Customer createdCustomer = _customerService.CreateCustomer(customer); _customerRepository.Get(createdCustomer.Id).Returns(customer); Assert.NotNull(createdCustomer); Assert.Equal(customer, _customerRepository.Get(createdCustomer.Id)); }
public void CreateCustomer_GivenCustomerThatIsNotValidForCreation_ThenThrowException() { Customer customer = CustomerTestBuilder.AnEmptyCustomer().Build(); Exception ex = Assert.Throws <InvalidOperationException>(() => _customerService.CreateCustomer(customer)); Assert.Equal("Invalid Customer provided for creation. Provided object: Customer{id='" + customer.Id.ToString("N") + "', firstname='" + customer.FirstName + "', lastname='" + customer.LastName + "', email=" + customer.Email + ", address=" + customer.Address + ", phoneNumber=" + customer.PhoneNumber + "}", ex.Message); }
public void GetCustomer() { _customerService.CreateCustomer(CustomerTestBuilder.ACustomer().Build()); Customer customerToFind = _customerService.CreateCustomer(CustomerTestBuilder.ACustomer().Build()); _customerService.CreateCustomer(CustomerTestBuilder.ACustomer().Build()); Customer foundCustomer = _customerService.GetCustomer(customerToFind.Id); Assert .Equal( JsonConvert.SerializeObject(customerToFind), JsonConvert.SerializeObject(foundCustomer)); }
public void Update() { var customerToSave = CustomerTestBuilder.ACustomer() .WithFirstname("Jo") .WithLastname("Jorissen") .Build(); var count = _repository.GetAll().Count; var savedCustomer = _repository.Save(customerToSave); var updatedCustomer = _repository.Update(CustomerTestBuilder.ACustomer() .WithId(savedCustomer.Id) .WithFirstname("Joske") .WithLastname("Jorissen") .Build()); Assert.NotEqual(Guid.Empty, savedCustomer.Id); Assert.Equal(savedCustomer.Id, updatedCustomer.Id); Assert.Equal("Joske", updatedCustomer.FirstName); Assert.Equal("Jorissen", updatedCustomer.LastName); Assert.Equal(count + 1, _repository.GetAll().Count); }
public void isValidForCreation_happyPath() { Assert.True(new CustomerValidator() .IsValidForCreation(CustomerTestBuilder.ACustomer() .Build())); }