Ejemplo n.º 1
0
        public async Task GetNotHiredAsyncReturnsCorrect()
        {
            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: "GetNotHiredAsyncReturnsCorrect")
                          .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 actual = await service.GetNotHiredUserAsync(id);

            Assert.Equal(id, actual.Id);
        }