public void GetEmployeeDetailsAsyncTest()
        {
            var options = SetupWithEmployeeAndDependent();

            using (var context = new BenefitContext(options))
            {
                var benefitRepository = new BenefitRepository(context);

                var employeeDetails = benefitRepository.GetEmployeeDetailsAsync(1).Result;

                Assert.AreEqual("Rick", employeeDetails.FirstName);

                context.Database.EnsureDeleted();
            }
        }
        public void GetAllEmployeesAsyncTest()
        {
            var options = SetupWithEmployeeAndDependent();

            using (var context = new BenefitContext(options))
            {
                var benefitRepository = new BenefitRepository(context);

                var employees = benefitRepository.GetAllEmployeesAsync().Result;

                Assert.IsNotNull(employees);

                context.Database.EnsureDeleted();
            }
        }
        public void EditEmployeeTest()
        {
            var options = SetupWithEmployeeAndDependent();

            using (var context = new BenefitContext(options))
            {
                var benefitRepository = new BenefitRepository(context);

                var employeeToEdit = benefitRepository.GetEmployeeToEdit(1).Result;

                employeeToEdit.FirstName = "RickX";


                var employeeThatHadEditSaved = benefitRepository.EditEmployee(employeeToEdit).Result;

                Assert.AreEqual("RickX", employeeThatHadEditSaved.FirstName);

                context.Database.EnsureDeleted();
            }
        }
        public DbContextOptions <BenefitContext> SetupWithEmployeeAndDependent()
        {
            var options = new DbContextOptionsBuilder <BenefitContext>()
                          .UseInMemoryDatabase(databaseName: "PaylocityDb")
                          .Options;

            using (var context = new BenefitContext(options))
            {
                var dependentList = new List <Dependent>();

                var newDependent = new Dependent
                {
                    EmployeeId  = 1,
                    FirstName   = "Carl",
                    LastName    = "Grimes",
                    DependentId = 1,
                    CreatedOn   = DateTime.UtcNow,
                    UpdatedOn   = DateTime.UtcNow
                };

                dependentList.Add(newDependent);

                var employee = new Employee
                {
                    FirstName  = "Rick",
                    LastName   = "Grimes",
                    EmployeeId = 1,
                    Dependents = dependentList,
                    CreatedOn  = DateTime.UtcNow,
                    UpdatedOn  = DateTime.UtcNow
                };

                context.Add(employee);
                context.SaveChanges();
            }

            return(options);
        }
        public void CreateNewEmployeeTest()
        {
            var options = SetupDbContextOnly();

            var newEmployee = new Employee
            {
                FirstName  = "Test",
                LastName   = "User",
                EmployeeId = 2,
                CreatedOn  = DateTime.UtcNow,
                UpdatedOn  = DateTime.UtcNow
            };

            using (var context = new BenefitContext(options))
            {
                var benefitRepository = new BenefitRepository(context);

                var employee = benefitRepository.CreateNewEmployee(newEmployee).Result;

                Assert.AreEqual("Test", employee.FirstName);

                context.Database.EnsureDeleted();
            }
        }