public async Task GetByIdWithVaidId()
        {
            ApplicationDbContext dbContext = new ApplicationDbContext(new DbContextOptionsBuilder <ApplicationDbContext>()
                                                                      .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options);
            var service = new EmployeesService(new EfDeletableEntityRepository <Employee>(dbContext));
            var date    = DateTime.UtcNow;
            await service.AddAsync(
                "Ivan Ivanov",
                "*****@*****.**",
                "08888888888",
                date,
                "1");

            var employee = await dbContext.Employees.FirstOrDefaultAsync();

            var result = service.GetById <EmployeeViewModel>(employee.Id);

            Assert.Equal(employee.FullName, result.FullName);
            Assert.Equal(employee.Email, result.Email);
            Assert.Equal(employee.PhoneNumber, result.PhoneNumber);
            Assert.Equal(employee.StartWorkDate, result.StartWorkDate);
            Assert.Equal(employee.GamingHallId, result.GamingHallId);
            dbContext.Database.EnsureDeleted();
            dbContext.Dispose();
        }
예제 #2
0
        public async void When_GettingHolidayEmployeeFullName_Expect_ReturnedEmployeeFullNameIsCorrect(int id)
        {
            var retrievedHoliday = await _holidaysService.GetById(id);

            var retrievedEmployee = await _employeesService.GetById(retrievedHoliday.EmployeeId);

            var fullNameExpected = $"{retrievedEmployee.Name} {retrievedEmployee.Surname}";
            var fullNameActual   = retrievedHoliday.EmployeeFullName;

            Assert.True(fullNameExpected.Equals(fullNameActual), "Employee's full name is incorrect.");
        }
예제 #3
0
        public void GetById_ReturnsCorrectEmployee()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;

            using (var dbContext = new ApplicationDbContext(options))
            {
                JobPosition jobPosition = new JobPosition()
                {
                    Name = "newJobPos",
                };
                dbContext.JobPositions.Add(jobPosition);
                dbContext.SaveChanges();

                OperatingLocation operatingLocation = new OperatingLocation()
                {
                    Town     = "Sofia",
                    Address  = "test street",
                    ImageUrl = "kgkkkgk",
                };
                dbContext.OperatingLocations.Add(operatingLocation);
                dbContext.SaveChanges();

                Employee employee = new Employee()
                {
                    FirstName           = "Ivan",
                    MiddleName          = "Ivanov",
                    LastName            = "Ivanov",
                    PhoneNumber         = "0897924218",
                    Email               = "*****@*****.**",
                    Town                = "Sofia",
                    Address             = "address 1",
                    ImageUrl            = "aasdfag",
                    OperatingLocationId = operatingLocation.Id,
                    JobPositionId       = jobPosition.Id,
                };

                dbContext.Employees.Add(employee);
                dbContext.SaveChanges();

                var employeesService = new EmployeesService(dbContext);
                var result           = employeesService.GetById(employee.Id);

                Assert.Equal("Ivan", result.FirstName);
            }
        }
        public async Task GetByIdWithNullId()
        {
            ApplicationDbContext dbContext = new ApplicationDbContext(new DbContextOptionsBuilder <ApplicationDbContext>()
                                                                      .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options);
            var service = new EmployeesService(new EfDeletableEntityRepository <Employee>(dbContext));
            var date    = DateTime.UtcNow;
            await service.AddAsync(
                "Ivan Ivanov",
                "*****@*****.**",
                "08888888888",
                date,
                "1");

            var result = service.GetById <EmployeeViewModel>(null);

            Assert.True(result == null);
            dbContext.Database.EnsureDeleted();
            dbContext.Dispose();
        }