public async Task GetList_ReturnSize(int size) { List <User> items = GetUserDB(size); DbContextOptions <DemoContext> options = SqliteInMemory.CreateOptions <DemoContext>(); using DemoContext context = new DemoContext(options); await ContextConfig.InitializeDatabaseContextSeed(context); await ContextConfig.AddDatabaseContext(context, items); IUserService userService = InjectUserService(context); List <DtoUserGet> result = await userService.GetList(); result.Should().HaveCount(size); }
public async Task Add_User_ReturnId_ReturnException(string userName, int yearsOld, string email, string password, bool active, int idRol) { List <User> items = GetUsersDb(10); DbContextOptions <DemoContext> options = SqliteInMemory.CreateOptions <DemoContext>(); using DemoContext context = new DemoContext(options); await ContextConfig.InitializeDatabaseContextSedd(context); await ContextConfig.AddDatabaseContext(context, items); IUserService userService = InjectUserService(context); if (email == null) { await Assert.ThrowsAnyAsync <DbUpdateException>(() => userService.AddAsync(new DtoUserAdd { UserName = userName, YearsOld = yearsOld, Email = email, Password = password, Active = active, IdRol = idRol })); } else { int?id = await userService.AddAsync(new DtoUserAdd { UserName = userName, YearsOld = yearsOld, Email = email, Password = password, Active = active, IdRol = idRol }); id.Should().NotBeNull(); } }
public async Task Add_ReturnNotBeNullAndException(string name, string email, string password, bool isActive, int idRol) { List <User> items = GetUserDB(20); DbContextOptions <DemoContext> options = SqliteInMemory.CreateOptions <DemoContext>(); using DemoContext context = new DemoContext(options); await ContextConfig.InitializeDatabaseContextSeed(context); await ContextConfig.AddDatabaseContext(context, items); IUserService userService = InjectUserService(context); if (email == null) { await Assert.ThrowsAsync <DbUpdateException>(async() => await userService.Add(new DtoUserAdd { Name = name, Email = email, Password = password, IsActive = isActive, IdRol = idRol })); } else { int?id = await userService.Add(new DtoUserAdd { Name = name, Email = email, Password = password, IsActive = isActive, IdRol = idRol }); id.Should().NotBeNull(); } }
public async Task Update_ReturnPasswordAndBeNull(int id, string password) { List <User> items = GetUserDB(2); DbContextOptions <DemoContext> options = SqliteInMemory.CreateOptions <DemoContext>(); using DemoContext context = new DemoContext(options); await ContextConfig.InitializeDatabaseContextSeed(context); await ContextConfig.AddDatabaseContext(context, items); IUserService userService = InjectUserService(context); int? result = await userService.Update(new DtoUserUpdate { Id = id, Password = password }); if (id == 0) { result.Should().BeNull(); } else { context.User.Find(id).Password.Should().Be(password); } }
public async Task Get_ReturnIdItemAndBeNull(int id) { List <User> items = GetUserDB(20); DbContextOptions <DemoContext> options = SqliteInMemory.CreateOptions <DemoContext>(); using DemoContext context = new DemoContext(options); await ContextConfig.InitializeDatabaseContextSeed(context); await ContextConfig.AddDatabaseContext(context, items); IUserService userService = InjectUserService(context); DtoUserGet result = await userService.Get(id); if (id == 0) { result.ShouldBeNull(); } else { result.Id.Should().Be(id); } }
public async Task Delete_ReturnNotBeNullAndBeNull(int id) { List <User> items = GetUserDB(2); DbContextOptions <DemoContext> options = SqliteInMemory.CreateOptions <DemoContext>(); using DemoContext context = new DemoContext(options); await ContextConfig.InitializeDatabaseContextSeed(context); await ContextConfig.AddDatabaseContext(context, items); IUserService userService = InjectUserService(context); int?rowsAffected = await userService.Delete(id); if (id == 0) { rowsAffected.Should().BeNull(); } else { rowsAffected.Should().NotBeNull(); } }