private void SetupContext() { DBContextOptions = new DbContextOptionsBuilder <AndrewSandboxContext>() .UseInMemoryDatabase(databaseName: "database") .Options; using (var context = new AndrewSandboxContext(DBContextOptions)) { for (int x = 0; x < NumberOfUsersToCreateInContext; x++) { context.Users.Add(new EmployeeManagement.Web.Models.User { Id = x, GenderId = 1, FirstName = $"User{x}", AddressId = 1 }); } context.Addresses.Add(new EmployeeManagement.Web.Models.Address { Id = 1, City = "City1" }); context.Genders.Add(new Gender { Id = 1, Name = "Female" }); context.Genders.Add(new Gender { Id = 2, Name = "Male" }); context.SaveChanges(); } }
public void UknownUserReturnsNull() { using (var context = new AndrewSandboxContext(Config.DBContextOptions)) { var mockUserRepository = new UserRepository(context); var returnedUserShouldBeNull = mockUserRepository.GetByIDAsync(5150).Result; Assert.IsNull(returnedUserShouldBeNull); } }
public void KnownNumberOfUsersAreReturned() { using (var context = new AndrewSandboxContext(Config.DBContextOptions)) { var mockUserRepository = new UserRepository(context); var returnedUsers = mockUserRepository.GetAllAsync().Result; Assert.AreEqual(Config.NumberOfUsersToCreateInContext, returnedUsers.Count); } }
public void KnownUserIsReturned() { using (var context = new AndrewSandboxContext(Config.DBContextOptions)) { var mockUserRepository = new UserRepository(context); var returnedUser0 = mockUserRepository.GetByIDAsync(0).Result; var returnedUser1 = mockUserRepository.GetByIDAsync(1).Result; Assert.NotNull(returnedUser0); Assert.NotNull(returnedUser1); Assert.AreEqual(0, returnedUser0.Id); Assert.AreEqual(1, returnedUser1.Id); } }
//public HomeController(ILogger<HomeController> logger) //{ // _logger = logger; //} public HomeController(ILogger <HomeController> logger, AndrewSandboxContext andrewSandboxContext) { _logger = logger; //_dbContext = andrewSandboxContext; }