public void IsDeletingPass() { var options = new DbContextOptionsBuilder <AppDbContext>() .UseInMemoryDatabase(databaseName: "database_to_delete_pass") .Options; var appDbContext = new AppDbContext(options); appDbContext.UserPermissions.Add(new UserPermission { Id = 1, UserName = "******", IdPrison = 1, Prison = new Prison { Id = 1, PrisonName = "prison_test" } }); var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, "abcd"), })); var passRepository = new PassRepository(appDbContext); var passService = new PassService(passRepository); var loggerRepository = new LoggerRepository(appDbContext); var loggerService = new LoggerService(loggerRepository); var passController = new PassController(passService, _mapper, loggerService) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = user } } }; appDbContext.Passes.Add(new Pass { Id = 1, StartDate = default,
public void IsAddingNewPass() { var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, "abcd"), })); var options = new DbContextOptionsBuilder <AppDbContext>() .UseInMemoryDatabase(databaseName: "database_to_add_pass") .Options; var appDbContext = new AppDbContext(options); appDbContext.UserPermissions.Add(new UserPermission { Id = 1, UserName = "******", IdPrison = 1, Prison = new Prison { Id = 1, PrisonName = "prison_test" } }); var passRepository = new PassRepository(appDbContext); var passService = new PassService(passRepository); var loggerRepository = new LoggerRepository(appDbContext); var loggerService = new LoggerService(loggerRepository); var passController = new PassController(passService, _mapper, loggerService) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = user } } }; appDbContext.SaveChanges(); appDbContext.Prisoners.Add(new Prisoner { Id = 1, Name = "fdsafd", Forname = "dsdsa", Pesel = "12345678910", Address = "dsafa", Pass = false, Behavior = 2, Isolated = false, IdCell = 1, Cell = new Cell(), Isolations = new List <Isolation>(), Punishments = new List <Punishment>() }); appDbContext.SaveChanges(); passController.AddPass(new PassDTO { StartDate = DateTime.Today, EndDate = DateTime.Today.AddDays(1), IdPrisoner = 1 }); Assert.AreEqual(appDbContext.Passes.Count(), 1); }