Example #1
0
        public async Task ShouldInsert_ExternalAgentAndEmployee()
        {
            Guid id = Guid.NewGuid();

            Employee employee = new Employee
                                (
                new ExternalAgent(id, AgentType.Employee),
                SupervisorId.Create(id),
                PersonName.Create("George", "Orwell", "J"),
                SSN.Create("623789999"),
                PhoneNumber.Create("817-987-1234"),
                MaritalStatus.Create("M"),
                TaxExemption.Create(5),
                PayRate.Create(40.00M),
                StartDate.Create(new DateTime(1998, 12, 2)),
                IsActive.Create(true)
                                );

            await _employeeRepo.AddAsync(employee);

            await _unitOfWork.Commit();

            var employeeResult = await _employeeRepo.Exists(employee.Id);

            Assert.True(employeeResult);
        }
Example #2
0
        public void Configure(EntityTypeBuilder <Employee> entity)
        {
            entity.ToTable("Employees", schema: "HumanResources");
            entity.HasKey(e => e.Id);
            entity.Property(p => p.Id).HasColumnType("UNIQUEIDENTIFIER").HasColumnName("EmployeeId");
            entity.Property(p => p.SupervisorId)
            .HasConversion(p => p.Value, p => SupervisorId.Create(p))
            .HasColumnType("UNIQUEIDENTIFIER")
            .HasColumnName("SupervisorId")
            .IsRequired();
            entity.OwnsOne(p => p.EmployeeName, p =>
            {
                p.Property(pp => pp.LastName).HasColumnType("NVARCHAR(25)").HasColumnName("LastName").IsRequired();
                p.Property(pp => pp.FirstName).HasColumnType("NVARCHAR(25)").HasColumnName("FirstName").IsRequired();
                p.Property(pp => pp.MiddleInitial).HasColumnType("NCHAR(1)").HasColumnName("MiddleInitial");
            });

            entity.Property(p => p.SSN)
            .HasConversion(p => p.Value, p => SSN.Create(p))
            .HasColumnType("NVARCHAR(9)")
            .HasColumnName("SSN")
            .IsRequired();
            entity.Property(p => p.Telephone)
            .HasConversion(p => p.Value, p => PhoneNumber.Create(p))
            .HasColumnType("NVARCHAR(14)")
            .HasColumnName("Telephone")
            .IsRequired();
            entity.Property(p => p.MaritalStatus)
            .HasConversion(p => p.Value, p => MaritalStatus.Create(p))
            .HasColumnType("NCHAR(1)")
            .HasColumnName("MaritalStatus")
            .IsRequired();
            entity.Property(p => p.TaxExemption)
            .HasConversion(p => p.Value, p => TaxExemption.Create(p))
            .HasColumnType("int")
            .HasColumnName("Exemptions")
            .IsRequired();
            entity.Property(p => p.PayRate)
            .HasConversion(p => p.Value, p => PayRate.Create(p))
            .HasColumnType("DECIMAL(18,2)")
            .HasColumnName("PayRate")
            .IsRequired();
            entity.Property(p => p.StartDate)
            .HasConversion(p => p.Value, p => StartDate.Create(p))
            .HasColumnType("datetime2(0)")
            .HasColumnName("StartDate")
            .IsRequired();
            entity.Property(p => p.IsActive)
            .HasConversion(p => p.Value, p => IsActive.Create(p))
            .HasColumnType("BIT")
            .HasColumnName("IsActive")
            .IsRequired();
            entity.Property(e => e.CreatedDate)
            .HasColumnType("datetime2(7)")
            .ValueGeneratedOnAdd()
            .HasDefaultValueSql("sysdatetime()");
            entity.Property(e => e.LastModifiedDate).HasColumnType("datetime2(7)");
        }
Example #3
0
        public void ShouldReturn_Valid_EmployeePayRate()
        {
            decimal rate = 7.51M;

            var result = PayRate.Create(rate);

            Assert.IsType <PayRate>(result);
            Assert.Equal(rate, result.Value);
        }
Example #4
0
        public void ShouldRaiseError_Invalid_PayRateTooLarge()
        {
            decimal rate = 40.01M;

            Action action = () => PayRate.Create(rate);

            var caughtException = Assert.Throws <ArgumentException>(action);

            Assert.Contains("Invalid pay rate, must be between $7.50 and $40.00 (per hour) inclusive!", caughtException.Message);
        }
Example #5
0
        public void ShouldRaiseError_Invalid_PayRateZero()
        {
            decimal rate = 0;

            Action action = () => PayRate.Create(rate);

            var caughtException = Assert.Throws <ArgumentException>(action);

            Assert.Contains("Invalid pay rate; pay rate can not be zero!", caughtException.Message);
        }
        /**     Helper methods     **/
        private Employee GetEmployee()
        {
            var employeeAgent = new ExternalAgent(Guid.NewGuid(), AgentType.Employee);

            return(new Employee
                   (
                       employeeAgent,
                       SupervisorId.Create(Guid.NewGuid()),
                       PersonName.Create("George", "Orwell", "Z"),
                       SSN.Create("123789999"),
                       PhoneNumber.Create("817-987-1234"),
                       MaritalStatus.Create("M"),
                       TaxExemption.Create(5),
                       PayRate.Create(40.00M),
                       StartDate.Create(new DateTime(1998, 12, 2)),
                       IsActive.Create(true)
                   ));
        }
        public void ShouldRaiseError_CreateEmployeeWithNullExternalAgent()
        {
            Action action = () => new Employee
                            (
                null,
                SupervisorId.Create(Guid.NewGuid()),
                PersonName.Create("Ken", "Sanchez", "J"),
                SSN.Create("123789999"),
                PhoneNumber.Create("817-987-1234"),
                MaritalStatus.Create("M"),
                TaxExemption.Create(5),
                PayRate.Create(40.00M),
                StartDate.Create(new DateTime(1998, 12, 2)),
                IsActive.Create(true)
                            );

            var caughtException = Assert.Throws <ArgumentNullException>(action);

            Assert.Contains("The external agent is required.", caughtException.Message);
        }
        public void ShouldReturn_NewEmployee()
        {
            var employeeAgent = new ExternalAgent(Guid.NewGuid(), AgentType.Employee);

            Employee employee = new Employee
                                (
                employeeAgent,
                SupervisorId.Create(employeeAgent.Id),
                PersonName.Create("Ken", "Sanchez", "J"),
                SSN.Create("123789999"),
                PhoneNumber.Create("817-987-1234"),
                MaritalStatus.Create("M"),
                TaxExemption.Create(5),
                PayRate.Create(40.00M),
                StartDate.Create(new DateTime(1998, 12, 2)),
                IsActive.Create(true)
                                );

            Assert.IsType <Employee>(employee);
        }
        private DomainUser GetUser()
        {
            var agent = new ExternalAgent(Guid.NewGuid(), AgentType.Employee);

            Employee employee = new Employee
                                (
                agent,
                SupervisorId.Create(agent.Id),
                PersonName.Create("Ken", "Sanchez", "J"),
                SSN.Create("123789999"),
                PhoneNumber.Create("817-987-1234"),
                MaritalStatus.Create("M"),
                TaxExemption.Create(5),
                PayRate.Create(40.00M),
                StartDate.Create(new DateTime(1998, 12, 2)),
                IsActive.Create(true)
                                );

            return(new DomainUser(agent.Id, "Jon", "Doe", ""));
        }
        private Employee GetEmployeeWithContactPeople()
        {
            var employeeAgent = new ExternalAgent(Guid.NewGuid(), AgentType.Employee);
            var employee      = new Employee
                                (
                employeeAgent,
                SupervisorId.Create(Guid.NewGuid()),
                PersonName.Create("George", "Orwell", "Z"),
                SSN.Create("123789999"),
                PhoneNumber.Create("817-987-1234"),
                MaritalStatus.Create("M"),
                TaxExemption.Create(5),
                PayRate.Create(40.00M),
                StartDate.Create(new DateTime(1998, 12, 2)),
                IsActive.Create(true)
                                );

            employee.AddContactPerson(1, PersonName.Create("Fidel", "Castro", "C"), PhoneNumber.Create("555-555-1234"), "You are being tested.");
            employee.AddContactPerson(2, PersonName.Create("Fidel", "Raul", "Z"), PhoneNumber.Create("555-555-5678"), "You are not being tested.");

            return(employee);
        }
        private Employee GetEmployeeWithAddresses()
        {
            var employeeAgent = new ExternalAgent(Guid.NewGuid(), AgentType.Employee);
            var employee      = new Employee
                                (
                employeeAgent,
                SupervisorId.Create(Guid.NewGuid()),
                PersonName.Create("George", "Orwell", "Z"),
                SSN.Create("123789999"),
                PhoneNumber.Create("817-987-1234"),
                MaritalStatus.Create("M"),
                TaxExemption.Create(5),
                PayRate.Create(40.00M),
                StartDate.Create(new DateTime(1998, 12, 2)),
                IsActive.Create(true)
                                );

            employee.AddAddress(1, AddressVO.Create("123 Main Terrace", "#4", "Somewhere", "TX", "78885"));
            employee.AddAddress(2, AddressVO.Create("123 Main Plaza", "Apt 13", "nowhere", "TX", "78981"));

            return(employee);
        }
Example #12
0
        public static async Task Execute(EditEmployeeInfo model, IEmployeeAggregateRepository repo, IUnitOfWork unitOfWork)
        {
            var employee = await repo.GetByIdAsync(model.Id) ??
                           throw new InvalidOperationException($"An employee with id '{model.Id}' could not be found!");

            if (model.Status == RecordStatus.Modified)
            {
                employee.UpdateSupervisorId(SupervisorId.Create(model.SupervisorId));
                employee.UpdateEmployeeName(PersonName.Create(model.FirstName, model.LastName, model.MiddleInitial));
                employee.UpdateSSN(SSN.Create(model.SSN));
                employee.UpdateTelephone(PhoneNumber.Create(model.Telephone));
                employee.UpdateMaritalStatus(MaritalStatus.Create(model.MaritalStatus));
                employee.UpdateTaxExemptions(TaxExemption.Create(model.Exemptions));
                employee.UpdatePayRate(PayRate.Create(model.PayRate));
                employee.UpdateLastModifiedDate();

                if (model.IsActive)
                {
                    employee.Activate();
                }
                else if (!model.IsActive)
                {
                    employee.Deactivate();
                }
            }

            if (model.Addresses != null && model.Addresses.Count > 0)
            {
                foreach (var address in model.Addresses)
                {
                    if (address.Status == RecordStatus.New)
                    {
                        employee.AddAddress(0, AddressVO.Create(address.AddressLine1, address.AddressLine2, address.City, address.StateCode, address.Zipcode));
                    }
                    else if (address.Status == RecordStatus.Modified)
                    {
                        employee.UpdateAddress(address.AddressId, AddressVO.Create(address.AddressLine1, address.AddressLine2, address.City, address.StateCode, address.Zipcode));
                    }
                    else if (address.Status == RecordStatus.Deleted)
                    {
                        employee.DeleteAddress(address.AddressId);
                    }
                }
            }

            if (model.Contacts != null && model.Contacts.Count > 0)
            {
                foreach (var contact in model.Contacts)
                {
                    if (contact.Status == RecordStatus.New)
                    {
                        employee.AddContactPerson(0, PersonName.Create(contact.FirstName, contact.LastName, contact.MiddleInitial), PhoneNumber.Create(contact.Telephone), contact.Notes);
                    }
                    else if (contact.Status == RecordStatus.Modified)
                    {
                        employee.UpdateContactPerson(contact.PersonId, PersonName.Create(contact.FirstName, contact.LastName, contact.MiddleInitial), PhoneNumber.Create(contact.Telephone), contact.Notes);
                    }
                    if (contact.Status == RecordStatus.Deleted)
                    {
                        employee.DeleteContactPerson(contact.PersonId);
                    }
                }
            }

            await unitOfWork.Commit();
        }
Example #13
0
        public static async Task Execute(CreateEmployeeInfo model, IEmployeeAggregateRepository repo, IUnitOfWork unitOfWork)
        {
            if (await repo.Exists(model.Id))
            {
                throw new InvalidOperationException($"This employee ({model.FirstName} {model.MiddleInitial ?? ""} {model.LastName}) already exists!");
            }

            ExternalAgent agent = new(model.Id, AgentType.Employee);

            Employee employee = new Employee
                                (
                agent,
                SupervisorId.Create(model.SupervisorId),
                PersonName.Create(model.FirstName, model.LastName, model.MiddleInitial),
                SSN.Create(model.SSN),
                PhoneNumber.Create(model.Telephone),
                MaritalStatus.Create(model.MaritalStatus),
                TaxExemption.Create(model.Exemptions),
                PayRate.Create(model.PayRate),
                StartDate.Create(model.StartDate),
                IsActive.Create(model.IsActive)
                                );

            if (model.Addresses != null && model.Addresses.Count > 0)
            {
                foreach (var address in model.Addresses)
                {
                    employee.AddAddress(
                        0,
                        AddressVO.Create
                        (
                            address.AddressLine1,
                            address.AddressLine2,
                            address.City,
                            address.StateCode,
                            address.Zipcode
                        )
                        );
                }
            }

            if (model.Contacts != null && model.Contacts.Count > 0)
            {
                foreach (var contact in model.Contacts)
                {
                    employee.AddContactPerson
                    (
                        0,
                        PersonName.Create(contact.FirstName, contact.LastName, contact.MiddleInitial),
                        PhoneNumber.Create(contact.Telephone),
                        contact.Notes
                    );
                }
            }

            await repo.AddAsync(employee);

            await unitOfWork.Commit();

            model.Id = employee.Id;
        }