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); }
public void GivenCustomerIdWhenGetCustomerThenReadFromCache() { // Arrange var opts = Options.Create(new MemoryDistributedCacheOptions()); var cache = new MemoryDistributedCache(opts); var options = new DbContextOptionsBuilder <CustomerDbContext>() .UseInMemoryDatabase(databaseName: "customerdatabse") .Options; var expect = new Customer { City = "Chennai", CustomerId = Guid.NewGuid(), }; cache.Set($"{expect.CustomerId}", expect); var customerDbContext = new CustomerDbContext(options); var customerRedisContext = new CustomerRedisContext(cache, customerDbContext); // Act var response = customerRedisContext.GetCustomer(expect.CustomerId); // Assert Assert.Equal(expect.City, response.City); }