public async void FindByIdAsync_When_Called_With_NoneExisting_CustomerId_ie_1Mio_Should_Return_Null() { //Arrange SoftDbContext _context = new SoftDbContext(); var _customerRepository = new CustomerRepository(_context); //Act var customer = await _customerRepository.FindByIdAsync(1000000); //Assert Assert.Null(customer); }
public async void GetEntityLookupAsync_Returns_LookupItems() { //Arrange SoftDbContext _context = new SoftDbContext(); var mockLookupDataServiceCustomer = new MockLookupDataServiceCustomer(() => _context); //Act var result = await mockLookupDataServiceCustomer.GetEntityLookupAsync(); //Assert Assert.NotNull(result); Assert.Equal(3, result.Count()); Assert.Equal(cAnyString, result.FirstOrDefault().DisplayMember); }
public async void FindByIdAsync_When_Called_Should_Return_Customer_including_BankAccounts() { //Arrange SoftDbContext _context = new SoftDbContext(); var _customerRepository = new CustomerRepository(_context); //Act var firstRepositoryCustomer = _context.Customers.FirstOrDefault(); Assert.NotNull(firstRepositoryCustomer); var customer = await _customerRepository.FindByIdAsync(firstRepositoryCustomer.Id); //Assert Assert.NotEmpty(customer.BankAccounts); }
public async void GetByIdAsync_When_Called_Should_Return_Broker_including_Customers() { //Arrange SoftDbContext _context = new SoftDbContext(); var _brokerRepository = new BrokerRepository(_context); //Act var firstBrokerInRepository = _context.Brokers.FirstOrDefault(); Assert.NotNull(firstBrokerInRepository); var broker = await _brokerRepository.FindByIdAsync(firstBrokerInRepository.Id); //Assert Assert.NotEmpty(broker.Customers); }
public async void HasChanges_When_Context_Is_Changed_Should_Return_True() { //Arrange SoftDbContext _context = new SoftDbContext(); var _customerRepository = new CustomerRepository(_context); //Act var anyCustomerFromDatabase = _context.Customers.FirstOrDefault(); Assert.NotNull(anyCustomerFromDatabase); var customer = await _customerRepository.FindByIdAsync(anyCustomerFromDatabase.Id); customer.Name = "New Name"; //Assert Assert.True(_customerRepository.HasChanges()); }
public async void GetHashCode_When_CustomerIsReadFromDbIntoTwoDifferentInstances_Should_ReturnSameHashcodes() { //Arrange SoftDbContext _context = new SoftDbContext(); var _customerRepository = new CustomerRepository(_context); //Act //Get the first customer from the repository var firstRepositoryCustomer = _context.Customers.FirstOrDefault(); Assert.NotNull(firstRepositoryCustomer); //Re-Open the DB-Connection and read the customer from the repository again _context = new SoftDbContext(); _customerRepository = new CustomerRepository(_context); var customer2 = await _customerRepository.FindByIdAsync(firstRepositoryCustomer.Id); //Ensure that the same customer data is stored in 2 different instances Assert.False(ReferenceEquals(firstRepositoryCustomer, customer2)); //Assert that both instances return the same GetHashCode() value Assert.Equal(customer2.GetHashCode(), firstRepositoryCustomer.GetHashCode()); }