public async Task GetByIdAsyncShouldWorkCorrectly() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; var dbContext = new ApplicationDbContext(options); var userRepo = new EfDeletableEntityRepository <ApplicationUser>(dbContext); var service = new EmployeesService(userRepo); await userRepo.AddAsync(new ApplicationUser { FirstName = "ivan", LastName = "ivanov", MiddleName = "ivanov", EGN = "1234567890", }); await userRepo.SaveChangesAsync(); var customerId = (await userRepo.AllAsNoTracking() .FirstOrDefaultAsync()).Id; var customer = await service.GetByIdAsync <EmployeeModel>(customerId); Assert.Equal("ivan", customer.FirstName); Assert.Equal("1234567890", customer.EGN); Assert.Equal("ivanov", customer.LastName); }
public async Task GetByIdAsyncReturnsCorrect() { var id = Guid.NewGuid().ToString(); var user = new CarpetUser { Id = id, FirstName = "Иван", LastName = "Иванов", PhoneNumber = "0888777444", Email = "*****@*****.**", UserName = "******", }; var roleAdminId = Guid.NewGuid().ToString(); var role = new CarpetRole { Id = roleAdminId, Name = GlobalConstants.AdministratorRoleName }; var roleOperatorId = Guid.NewGuid().ToString(); var roleOperator = new CarpetRole { Id = roleOperatorId, Name = GlobalConstants.OperatorRoleName }; var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "GetByIdAsyncReturnsCorrect") .Options; var dbContext = new ApplicationDbContext(options); dbContext.Users.Add(user); dbContext.Roles.Add(role); dbContext.Roles.Add(roleOperator); await dbContext.SaveChangesAsync(); var repository = new EfDeletableEntityRepository <Employee>(dbContext); var service = new EmployeesService(repository, dbContext); var employee = new EmployeeCreateInputModel { Id = id, FirstName = "Иван", LastName = "Иванов", PhoneNumber = "0888777444", Salary = 1000m, RoleName = GlobalConstants.OperatorRoleName, }; var result = await service.CreateAsync(employee, string.Empty); var actual = await service.GetByIdAsync <EmployeeIndexViewModel>(result.Id); var employees = await service.GetAllAsync <EmployeeIndexViewModel>().ToListAsync(); Assert.Equal(result.Id, actual.Id); Assert.Single(employees); }