Ejemplo n.º 1
0
        public async Task TestAddTeacher()
        {
            DbContextOptions <ApplicationDbContext> options = new DbContextOptionsBuilder <ApplicationDbContext>()
                                                              .UseInMemoryDatabase(databaseName: "TestAddTeachersDb").Options;

            using var dbContext = new ApplicationDbContext(options);
            dbContext.Database.EnsureDeleted();
            using var repository = new EfDeletableEntityRepository <Teacher>(dbContext);
            var service = new UsersService(repository, null, null);

            dbContext.Teachers.Add(new Teacher()
            {
                Id = 1, ApplicationUserId = "one"
            });
            dbContext.Teachers.Add(new Teacher()
            {
                Id = 2, ApplicationUserId = "two"
            });
            dbContext.Teachers.Add(new Teacher()
            {
                Id = 3, ApplicationUserId = "three"
            });
            await dbContext.SaveChangesAsync();

            await service.AddTeacher(new ApplicationUser()
            {
                Id = "newUser"
            });

            Assert.Equal(4, dbContext.Teachers.Count());
        }