Esempio n. 1
0
        public void test_employee_repository_mocking_add()
        {
            var employee = new Employee()
            {
                Id = 0,
                Name = "Sunil Samuel    ",
                Position = "Developer"
            };

            Mock<IEmployeeRepository> mockEmployeeRepository = new Mock<IEmployeeRepository>();
            mockEmployeeRepository.Setup(obj => obj.Add(employee)).Returns(employee);
            var repositoryTest = new RepositoryTestClass(mockEmployeeRepository.Object);
            var airlineList = repositoryTest.AddEmployee(employee);
            Assert.IsTrue(airlineList != null);
        }
Esempio n. 2
0
 public Employee AddEmployee(Employee employee)
 {
     _employeeRepository.Add(employee);
     return employee;
 }
Esempio n. 3
0
        public HttpResponseMessage AddEmployee(HttpRequestMessage request, [FromBody]EmployeeDetailModel model)
        {
            return GetHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                IEmployeeRepository employeeRepository = _dataRepositoryFactory.GetDataRepository<IEmployeeRepository>();

                if (model.Id == 0)
                {
                    var employee = new Employee()
                                   {
                                       Id = 0,
                                       Name = model.Name,
                                       UserName = model.UserName,
                                       Position = model.Position,
                                       PassportNumber = model.PassportNumber,
                                       PassportExpiry = String.IsNullOrEmpty(model.PassportExpiry) ? (DateTime?)null : DateTime.ParseExact(model.PassportExpiry, "dd/MM/yyyy", null),
                                       EmiratesID = model.EmiratesID,
                                       EmiratesIDExpiry = String.IsNullOrEmpty(model.EmiratesIDExpiry) ? (DateTime?)null : DateTime.ParseExact(model.EmiratesIDExpiry, "dd/MM/yyyy", null),
                                       VisaNumber = model.VisaNumber,
                                       VisaExpiry = String.IsNullOrEmpty(model.VisaExpiry) ? (DateTime?)null : DateTime.ParseExact(model.VisaExpiry, "dd/MM/yyyy", null),
                                       InsuranceNumber = model.InsuranceNumber,
                                       InsuranceExpiry = String.IsNullOrEmpty(model.InsuranceExpiry) ? (DateTime?)null : DateTime.ParseExact(model.InsuranceExpiry, "dd/MM/yyyy", null),
                                       BasicSalary = model.BasicSalary,
                                       JoiningDate = String.IsNullOrEmpty(model.JoiningDate) ? (DateTime?)null : DateTime.ParseExact(model.JoiningDate, "dd/MM/yyyy", null),
                                       Allowance = model.Allowance,
                                       ModifiedBy = User.Identity.Name,
                                       AddedTime = DateTime.UtcNow
                                   };

                    if (!WebSecurity.Initialized)
                        WebSecurity.InitializeDatabaseConnection("GulfRuby", "Account", "AccountId", "UserName", autoCreateTables: true);
                    if (!_securityAdapter.UserExists(model.UserName))
                    {
                        _securityAdapter.Register(model.UserName, "GulfRubyPassword00971", null);
                        employeeRepository.Add(employee);
                        response = request.CreateResponse(HttpStatusCode.OK);

                    }
                    else
                        response = request.CreateResponse<string[]>(HttpStatusCode.BadRequest, new List<string>() { "An account is already registered with this email address." }.ToArray());
                }
                else
                {

                    var employee = new Employee()
                                   {
                                       Id = model.Id,
                                       Name = model.Name,
                                       UserName = model.UserName,
                                       Position = model.Position,
                                       PassportNumber = model.PassportNumber,
                                       PassportExpiry = String.IsNullOrEmpty(model.PassportExpiry) ? (DateTime?)null : DateTime.ParseExact(model.PassportExpiry, "dd/MM/yyyy", null),
                                       EmiratesID = model.EmiratesID,
                                       EmiratesIDExpiry = String.IsNullOrEmpty(model.EmiratesIDExpiry) ? (DateTime?)null : DateTime.ParseExact(model.EmiratesIDExpiry, "dd/MM/yyyy", null),
                                       VisaNumber = model.VisaNumber,
                                       VisaExpiry = String.IsNullOrEmpty(model.VisaExpiry) ? (DateTime?)null : DateTime.ParseExact(model.VisaExpiry, "dd/MM/yyyy", null),
                                       InsuranceNumber = model.InsuranceNumber,
                                       InsuranceExpiry = String.IsNullOrEmpty(model.InsuranceExpiry) ? (DateTime?)null : DateTime.ParseExact(model.InsuranceExpiry, "dd/MM/yyyy", null),
                                       BasicSalary = model.BasicSalary,
                                       JoiningDate = String.IsNullOrEmpty(model.JoiningDate) ? (DateTime?)null : DateTime.ParseExact(model.JoiningDate, "dd/MM/yyyy", null),
                                       Allowance = model.Allowance,
                                       ModifiedBy = User.Identity.Name,
                                       AddedTime = DateTime.UtcNow
                                   };

                    employeeRepository.Update(employee);
                }
                response = request.CreateResponse(HttpStatusCode.OK);
                return response;
            });
        }