public async Task ShouldRaiseExceptionCreateEmployeeDuplicateNationalIDNumber()
        {
            var employeeDomainObj = new EmployeeDomainObj
            {
                PersonType         = "EM",
                IsEasternNameStyle = false,
                Title            = "Ms.",
                FirstName        = "Jane",
                MiddleName       = "Janice",
                LastName         = "Doe",
                EmailPromotion   = EmailPromoPreference.NoPromotions,
                EmailAddress     = "*****@*****.**",
                PasswordHash     = "pbFwXWE99vobT6g+vPWFy93NtUU/orrIWafF01hccfM=",
                PasswordSalt     = "bE3XiWw=",
                NationalIDNumber = "295847284",
                LoginID          = "adventure-works\\jdoe",
                JobTitle         = "Design Engineer",
                BirthDate        = new DateTime(1989, 6, 5),
                MaritalStatus    = "S",
                Gender           = "F",
                HireDate         = new DateTime(2019, 10, 5),
                IsSalaried       = false,
                VacationHours    = 10,
                SickLeaveHours   = 10,
                IsActive         = true
            };

            var exception = await Assert.ThrowsAsync <AdventureWorksUniqueIndexException>(() => _employeeRepo.CreateEmployee(employeeDomainObj));

            Assert.Equal("Error: This operation would result in a duplicate employee national ID number!", exception.Message);
        }
        public async Task ShouldCreatePersonAndEmployeeFromAEmployeeDomainObj()
        {
            var employeeDomainObj = new EmployeeDomainObj
            {
                PersonType         = "EM",
                IsEasternNameStyle = false,
                Title            = "Ms.",
                FirstName        = "Jane",
                MiddleName       = "Janice",
                LastName         = "Doe",
                EmailPromotion   = EmailPromoPreference.NoPromotions,
                EmailAddress     = "*****@*****.**",
                PasswordHash     = "pbFwXWE99vobT6g+vPWFy93NtUU/orrIWafF01hccfM=",
                PasswordSalt     = "bE3XiWw=",
                NationalIDNumber = "123456123",
                LoginID          = "adventure-works\\jane1",
                JobTitle         = "Design Engineer",
                BirthDate        = new DateTime(1989, 6, 5),
                MaritalStatus    = "S",
                Gender           = "F",
                HireDate         = new DateTime(2019, 10, 5),
                IsSalaried       = false,
                VacationHours    = 10,
                SickLeaveHours   = 10,
                IsActive         = true
            };

            await _employeeRepo.CreateEmployee(employeeDomainObj);

            var result = await _employeeRepo.GetEmployeeByID(employeeDomainObj.BusinessEntityID);

            Assert.NotNull(result);
        }
 public static void Map(this Person.Person entityObj, EmployeeDomainObj domainObj)
 {
     entityObj.BusinessEntityID   = domainObj.BusinessEntityID;
     entityObj.PersonType         = domainObj.PersonType;
     entityObj.IsEasternNameStyle = domainObj.IsEasternNameStyle;
     entityObj.Title                 = domainObj.Title;
     entityObj.FirstName             = domainObj.FirstName;
     entityObj.MiddleName            = domainObj.MiddleName;
     entityObj.LastName              = domainObj.LastName;
     entityObj.Suffix                = domainObj.Suffix;
     entityObj.EmailPromotion        = domainObj.EmailPromotion;
     entityObj.AdditionalContactInfo = domainObj.AdditionalContactInfo;
     entityObj.Demographics          = domainObj.Demographics;
 }
Ejemplo n.º 4
0
 public static void Map(this Employee entityObj, EmployeeDomainObj domainObj)
 {
     entityObj.BusinessEntityID = domainObj.BusinessEntityID;
     entityObj.NationalIDNumber = domainObj.NationalIDNumber;
     entityObj.LoginID          = domainObj.LoginID;
     entityObj.JobTitle         = domainObj.JobTitle;
     entityObj.MaritalStatus    = domainObj.MaritalStatus;
     entityObj.Gender           = domainObj.Gender;
     entityObj.HireDate         = domainObj.HireDate;
     entityObj.IsSalaried       = domainObj.IsSalaried;
     entityObj.VacationHours    = domainObj.VacationHours;
     entityObj.SickLeaveHours   = domainObj.SickLeaveHours;
     entityObj.BirthDate        = domainObj.BirthDate;
     entityObj.IsActive         = domainObj.IsActive;
 }
        public async Task ShouldFailDueToEmployeeLessThan18()
        {
            ResetDatabase();

            var invalidBirthDate = (DateTime.Now).AddDays(1);

            var employeeDomainObj = new EmployeeDomainObj
            {
                PersonType         = "EM",
                IsEasternNameStyle = false,
                Title            = "Ms.",
                FirstName        = "Jane",
                MiddleName       = "Janice",
                LastName         = "Doe",
                EmailPromotion   = EmailPromoPreference.NoPromotions,
                EmailAddress     = "*****@*****.**",
                PasswordHash     = "pbFwXWE99vobT6g+vPWFy93NtUU/orrIWafF01hccfM=",
                PasswordSalt     = "bE3XiWw=",
                NationalIDNumber = "123456123",
                LoginID          = "adventure-works\\jane1",
                JobTitle         = "Design Engineer",
                BirthDate        = invalidBirthDate,
                MaritalStatus    = "M",
                Gender           = "F",
                HireDate         = new DateTime(2006, 6, 30),
                IsSalaried       = false,
                VacationHours    = 10,
                SickLeaveHours   = 10,
                IsActive         = true
            };

            string      jsonEmployee = JsonConvert.SerializeObject(employeeDomainObj);
            HttpContent content      = new StringContent(jsonEmployee, Encoding.UTF8, "application/json");
            var         response     = await _client.PostAsync($"{serviceAddress}{rootAddress}", content);

            Assert.False(response.IsSuccessStatusCode);
            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
        public async Task <IActionResult> DeleteEmployee([FromBody] EmployeeDomainObj employee)
        {
            await _repository.Employee.DeleteEmployee(employee);

            return(NoContent());
        }
        public async Task <IActionResult> CreateEmployee([FromBody] EmployeeDomainObj employee)
        {
            await _repository.Employee.CreateEmployee(employee);

            return(CreatedAtRoute(nameof(GetEmployeeByID), new { employeeID = employee.BusinessEntityID }, employee));
        }