Exemplo n.º 1
0
 public bool SetCustomer(Customer customer)
 {
     customerDbContext.Customers.Add(customer);
     customerDbContext.SaveChanges();
     cache.Set($"{customer.CustomerId}", customer);
     return(true);
 }
Exemplo n.º 2
0
        public void GivenCustomerIdWhenGetCustomerThenReadFromDatabase()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <CustomerDbContext>()
                          .UseInMemoryDatabase(databaseName: "customerdatabse")
                          .Options;
            var expect = new Customer
            {
                Age        = 35,
                City       = "Chennai",
                Country    = "India",
                Name       = "Mark",
                State      = "Tamil Nadu",
                CustomerId = Guid.NewGuid(),
            };
            var cache             = A.Fake <IDistributedCache>();
            var customerDbContext = new CustomerDbContext(options);

            customerDbContext.Customers.Add(expect);
            customerDbContext.SaveChanges();
            var customerRedisContext = new CustomerRedisContext(cache, customerDbContext);

            // Act
            var response = customerRedisContext.GetCustomer(expect.CustomerId);

            // Assert
            Assert.Equal(expect.City, response.City);
        }