Exemple #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);
        }
Exemple #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)");
        }
Exemple #3
0
        public void ShouldReturn_Valid_StartDate()
        {
            DateTime start = new DateTime(2021, 6, 1);

            var result = StartDate.Create(start);

            Assert.IsType <StartDate>(result);
            Assert.Equal(start, result);
        }
Exemple #4
0
        public void ShouldRaiseError_Invalid_StartDateIsDefaultDate()
        {
            DateTime start = new DateTime();

            Action action = () => StartDate.Create(start);

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

            Assert.Contains("The employee start date is required.", 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);
        }
Exemple #11
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;
        }