コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <EmployeeDto> Handle(CreateEmployeeCommand request, CancellationToken cancellationToken)
        {
            //make db call rather
            var result = EmployeeFactory.Create();

            return(result.FirstOrDefault());
        }
コード例 #2
0
        public override string Execute()
        {
            var company = this.db.Companies.Cast <Company>().FirstOrDefault(c => c.Name == this.companyName);

            if (company == null)
            {
                throw new ArgumentException(
                          string.Format("Company {0} does not exist", this.companyName));
            }

            foreach (var e in company.AllEmployees)
            {
                if (e.FirstName == this.firstName && e.LastName == this.lastName)
                {
                    if (e.InUnit is Company)
                    {
                        throw new ArgumentException(
                                  string.Format(
                                      "Employee {0} {1} already exists in {2} (no department)",
                                      this.firstName,
                                      this.lastName,
                                      this.companyName
                                      ));
                    }
                    throw new ArgumentException(
                              string.Format(
                                  "Employee {0} {1} already exists in {2} (in department {3})",
                                  this.firstName,
                                  this.lastName,
                                  this.companyName,
                                  e.InUnit.Name
                                  ));
                }
            }

            IOrganizationalUnit inUnit = company;

            if (this.departmentName != null)
            {
                foreach (var d in company.AllDepartments)
                {
                    if (d.Name == this.departmentName)
                    {
                        inUnit = d;
                        break;
                    }
                }
            }

            var employee = EmployeeFactory.Create(
                this.firstName,
                this.lastName,
                this.position,
                inUnit
                );

            company.AllEmployees.Add(employee);
            inUnit.AddEmployee(employee);
            return("");
        }
コード例 #3
0
        public async Task CreateEmployee_ReturnsNewEmployee()
        {
            var employeeFactory = new EmployeeFactory();
            var employee        = await employeeFactory.Create(1);

            Assert.NotNull(employee);
        }
コード例 #4
0
        public void Employee_Salary_ShouldReturnErrorIfSalaryLessAllowed()
        {
            // Arrange, Act and Assert
            var exception = Assert.Throws <Exception>(() => EmployeeFactory.Create("Thiago", 230.45));

            Assert.Equal("Salary less than allowed", exception.Message);
        }
コード例 #5
0
 private void RefillHiringPool()
 {
     if (EmployeesForHire.Count < _minimumForHire)
     {
         EmployeesForHire.Add(EmployeeFactory.Create());
     }
 }
コード例 #6
0
        public void DepartmentWithNestedManagerTotalExpenses_Equals_TotalEmployeeExpenses()
        {
            Department marketing = new Department
            {
                Name = "Markteting"
            };

            IEmployee qaTester1  = EmployeeFactory.Create(EmployeeType.Employee, _qatester.Item1, _qatester.Item2);
            IEmployee developer1 = EmployeeFactory.Create(EmployeeType.Employee, _developer.Item1, _developer.Item2);
            Manager   manager1   = (Manager)EmployeeFactory.Create(EmployeeType.Manager, _manager.Item1, _manager.Item2);

            manager1.Employees.Add(qaTester1);
            manager1.Employees.Add(developer1);

            decimal manager1Expenses = testHelper.GetTotalExpenses();

            IEmployee qaTester2  = EmployeeFactory.Create(EmployeeType.Employee, _qatester.Item1, _qatester.Item2);
            IEmployee developer2 = EmployeeFactory.Create(EmployeeType.Employee, _developer.Item1, _developer.Item2);
            Manager   manager2   = (Manager)EmployeeFactory.Create(EmployeeType.Manager, _manager.Item1, _manager.Item2);

            manager2.Employees.Add(qaTester2);
            manager2.Employees.Add(developer2);

            decimal manager2Expenses = testHelper.GetTotalExpenses();

            manager2.Employees.Add(manager1);

            marketing.Employees.Add(manager2);

            Assert.AreEqual(marketing.GetTotalExpenses(), manager1Expenses + manager2Expenses);
        }
コード例 #7
0
        public async Task <ActionResult <EmployeeDto> > Pagination([FromQuery] PaginationFilter filter, CancellationToken cancellationToken)
        {
            var route       = Request.Path.Value;
            var validFilter = new PaginationFilter(filter.PageNumber, filter.PageSize, filter.SearchQuery);

            var dbResultSet = EmployeeFactory.Create();

            var AsQueryableResult = dbResultSet.AsQueryable()
                                    .Skip((filter.PageNumber - 1) * filter.PageSize)
                                    .Take(filter.PageSize).ToList();


            if (!string.IsNullOrEmpty(filter.SearchQuery))
            {
                // trim & ignore casing
                var searchQueryForWhereClause = filter.SearchQuery
                                                .Trim().ToLowerInvariant();

                AsQueryableResult.Where(o => o.FirstName.ToLowerInvariant().Contains(searchQueryForWhereClause) ||
                                        o.LastName.ToLowerInvariant().Contains(searchQueryForWhereClause)).ToList();
            }

            AsQueryableResult.ToList();

            var totalRecords = dbResultSet.Count();
            var pagedData    = AsQueryableResult;

            var pagedReponse = PaginationHelper.CreatePagedReponse <EmployeeDto>(
                pagedData, validFilter, totalRecords, _uriService, route
                );

            return(Ok(pagedReponse));
        }
コード例 #8
0
        public async Task CreateEmployee_ReturnsNewEmployee_WithCalculatedVariable()
        {
            var employeeFactory = new EmployeeFactory();
            var employee        = await employeeFactory.Create(1);

            Assert.AreEqual(employee.GenerateEmployeeString(), employee.EmployeeString);
        }
コード例 #9
0
        public void EmployeeFactory_Create_ShouldReturnEmployeeTypeDerivative()
        {
            // Arrange and Act
            var employee = EmployeeFactory.Create("Thiago", 11000);

            // Assert
            Assert.IsAssignableFrom <Person>(employee);
        }
コード例 #10
0
        public async Task CreateEmployee_ReturnsNewEmployee_WithBlogPosts()
        {
            var employeeFactory = new EmployeeFactory();
            var employee        = await employeeFactory.Create(1);

            Assert.NotNull(employee.BlogPosts);
            Assert.Greater(employee.BlogPosts.Count, 80);
        }
コード例 #11
0
    private static void CreateEmployee(EmployeeFactory employeeFactory, IDictionary <string, IEmployee> employeesByName, string[] commandArgs)
    {
        string    employeeType = commandArgs[0];
        string    employeeName = commandArgs[1];
        IEmployee employee     = employeeFactory.Create(employeeType, employeeName);

        employeesByName.Add(employeeName, employee);
    }
コード例 #12
0
        public void Employee_Skills_JuniorShouldHaveBasicSkill()
        {
            // Arrange and Act
            var employee = EmployeeFactory.Create("Thiago", 1000);

            // Assert
            Assert.Contains("OOP", employee.Skills);
        }
コード例 #13
0
        public void Employee_Skills_JuniorShouldntHaveAdvancedSkill()
        {
            // Arrange and Act
            var employee = EmployeeFactory.Create("Thiago", 1000);

            // Assert
            Assert.DoesNotContain("Microservices", employee.Skills);
        }
コード例 #14
0
        public void Employee_Skills_ShouldntHaveEmptySkills()
        {
            // Arrange and Act
            var employee = EmployeeFactory.Create("Thiago", 11000);

            // Assert
            Assert.All(employee.Skills, skill => Assert.False(string.IsNullOrWhiteSpace(skill)));
        }
コード例 #15
0
        public void EmployeeFactory_Create_ShouldReturnEmployeeType()
        {
            // Arrange and Act
            var employee = EmployeeFactory.Create("Thiago", 11000);

            // Assert
            Assert.IsType <Employee>(employee);
        }
コード例 #16
0
        public void CreateEmployee(JobCentre centre, string[] parts)
        {
            string    type    = parts[0];
            string    name    = parts[1];
            IEmployee current = employeeFactory.Create(type, name);

            centre.AddEmployees(current);
        }
コード例 #17
0
        public async Task CreateEmployee_ReturnsNewEmployee_WithStateCity()
        {
            var employeeFactory = new EmployeeFactory();
            var employee        = await employeeFactory.Create(1);

            Assert.NotNull(employee.State);
            Assert.AreEqual(employee.State, "PA");
            Assert.AreEqual(employee.City, "Yankton");
        }
コード例 #18
0
        public IEnumerable <EmployeeDto> spRedisTry()
        {
            if (!_redisCacheService.TryGetValue(key: "carkey", result: out IEnumerable <EmployeeDto> values))
            {
                values = EmployeeFactory.Create();//get data from db instead
                _redisCacheService.Set(key: "carkey", data: values, cacheTimeInMinutes: 60);
            }

            return(values);
        }
コード例 #19
0
        public async Task CreateEmployee_ReturnsNewEmployee_WithRandomValues()
        {
            var employeeFactory = new EmployeeFactory();
            var employee        = await employeeFactory.Create(1);

            var numbers = new[] { 2, 3, 5, 12 };
            var strings = new[] { "Hello", "World", "Ninja" };

            Assert.IsTrue(numbers.Contains(employee.RandomNumber));
            Assert.IsTrue(strings.Contains(employee.RandomString));
        }
コード例 #20
0
ファイル: ManagerTests.cs プロジェクト: todddill/Prototypes
        /*  Manager
         *      QA Tester
         *      Developer
         *      1800
         */
        public void ManagerTotalExpenses_Equals_TotalEmployeeExpenses()
        {
            IEmployee qaTester  = EmployeeFactory.Create(EmployeeType.Employee, _qatester.Item1, _qatester.Item2);
            IEmployee developer = EmployeeFactory.Create(EmployeeType.Employee, _developer.Item1, _developer.Item2);
            Manager   manager   = (Manager)EmployeeFactory.Create(EmployeeType.Manager, _manager.Item1, _manager.Item2);

            manager.Employees.Add(qaTester);
            manager.Employees.Add(developer);

            Assert.AreEqual(manager.GetTotalExpenses(), testHelper.GetTotalExpenses());
        }
コード例 #21
0
        public EmployeeInfo GetEmployeeById(int id)
        {
            var factory = new EmployeeFactory();

            IEnumerable <Employee> employees = this.respository.GetAllEmployee();

            var emp = (from e in employees
                       where e.Id == id
                       select e).FirstOrDefault();

            return(factory.Create(emp));
        }
コード例 #22
0
 private Employee RunFactoryCreate()
 {
     return(_factory.Create(
                new EmployeeInputData()
     {
         ExperienceLevel = experienceLevel,
         FirstName = firstName,
         LastName = lastName,
         OfficeId = officeId,
         ProfileImage = profileImage,
         Salary = salary,
         VacationDays = vacationDays,
     }));
 }
コード例 #23
0
        public void Employee_Skills_SeniorShouldHaveAllSkills()
        {
            // Arrange and Act
            var employee = EmployeeFactory.Create("Thiago", 15000);

            var basicSkills = new[]
            {
                "Programming logic",
                "OOP",
                "Tests",
                "Microservices"
            };

            // Assert
            Assert.Equal(basicSkills, employee.Skills);
        }
コード例 #24
0
        public IEnumerable <EmployeeInfo> GetAllEmployes()
        {
            var factory = new EmployeeFactory();

            IEnumerable <Employee> employees = this.respository.GetAllEmployee();

            List <EmployeeInfo> employeeInfos = new List <EmployeeInfo>();

            foreach (var item in employees)
            {
                var employeeInfo = factory.Create(item);
                employeeInfos.Add(employeeInfo);
            }

            return(employeeInfos);
        }
コード例 #25
0
        public void DepartmentTotalExpenses_Equals_TotalEmployeeExpenses()
        {
            Department marketing = new Department {
                Name = "Markteting"
            };

            IEmployee qaTester  = EmployeeFactory.Create(EmployeeType.Employee, _qatester.Item1, _qatester.Item2);
            IEmployee developer = EmployeeFactory.Create(EmployeeType.Employee, _developer.Item1, _developer.Item2);
            Manager   manager   = (Manager)EmployeeFactory.Create(EmployeeType.Manager, _manager.Item1, _manager.Item2);

            manager.Employees.Add(qaTester);
            manager.Employees.Add(developer);

            marketing.Employees.Add(manager);

            Assert.AreEqual(marketing.GetTotalExpenses(), testHelper.GetTotalExpenses());
        }
コード例 #26
0
        public Employee CreateInvalidEmployee()
        {
            var gender = new Faker().PickRandom <Name.Gender>();

            // Bogus generate a fake employee with random data
            var employee = new Faker <Employee>(locale: "pt_BR")
                           .CustomInstantiator(faker => EmployeeFactory.Create(
                                                   name: faker.Name.FirstName(gender),
                                                   surname: faker.Name.LastName(gender),
                                                   salary: faker.Random.Decimal(1000, 10000),
                                                   email: "",
                                                   bithDate: faker.Date.Past(5, DateTime.Now.AddYears(-10))
                                                   ))
                           // Because we want create a email with name a and surname generated by Bogus
                           .RuleFor(employee => employee.Email, (faker, employee) => faker.Internet.Email(employee.Name.ToLower(), employee.Surname.ToLower()));

            return(employee);
        }
コード例 #27
0
        /// <summary>
        /// Hires a new employee.
        /// </summary>
        public void HireEmployee()
        {
            this.Log("Company is hiring employee");

            var randomIndex = Random.Range(0, EmployeeTemplates.Count);
            var employee    = EmployeeTemplates.ElementAt(randomIndex);

            employee.Generate();

            var employeeFactory   = new EmployeeFactory(employee.Value, gameObject);
            var employeeObject    = employeeFactory.Create();
            var employeeComponent = employeeObject.GetComponent <EmployeeComponent>();

            employeeComponent.SetCompany(this);
            Employees.Add(employeeComponent);

            EmployeeHired?.Invoke(this, new EmployeeHiredEventArgs(employeeComponent, HiringCost));
        }
コード例 #28
0
        public override string Execute()
        {
            foreach (var c
                     in this.db.Companies)
            {
                if (c.Name == this.companyName)
                {
                    throw new Exception(string.Format("Company {0} already exists", this.companyName));
                }
            }

            IOrganizationalUnit company = new Company(this.companyName);
            var ceo = EmployeeFactory.Create(this.ceoFirstName, this.ceoLastName, "CEO", company, this.ceoSalary);

            this.db.AddCompany(company);
            company.AddEmployee(ceo);
            company.Head = ceo;
            return("");
        }
コード例 #29
0
        public async Task <IEnumerable <EmployeeDto> > LocalStorageDocs()
        {
            var collection = EmployeeFactory.Create();

            //_storage.DestroyAsync();
            //_storage.ClearAsync();

            var key = Guid.NewGuid().ToString();

            var expected_amount = collection.Count();

            _storage.StoreAsync(key, collection);

            _storage.PersistAsync();

            var target = await _storage.QueryAsync <EmployeeDto>(key);

            return(target);
        }
コード例 #30
0
ファイル: ManagerTests.cs プロジェクト: todddill/Prototypes
        /* Manager
         *      Manager
         *          QA Tester
         *          Developer
         *          2100
         */
        public void NestedManagerSampleScenarioTotalExpenses_Equals_TotalEmployeeExpenses()
        {
            IEmployee qaTester1  = EmployeeFactory.Create(EmployeeType.Employee, _qatester.Item1, _qatester.Item2);
            IEmployee developer1 = EmployeeFactory.Create(EmployeeType.Employee, _developer.Item1, _developer.Item2);
            Manager   manager1   = (Manager)EmployeeFactory.Create(EmployeeType.Manager, _manager.Item1, _manager.Item2);

            manager1.Employees.Add(qaTester1);
            manager1.Employees.Add(developer1);

            decimal manager1Expenses = testHelper.GetTotalExpenses();

            Manager manager2 = (Manager)EmployeeFactory.Create(EmployeeType.Manager, _manager.Item1, _manager.Item2);

            decimal manager2Expenses = manager2.GetTotalExpenses();

            manager2.Employees.Add(manager1);

            Assert.AreEqual(manager2.GetTotalExpenses(), manager1Expenses + manager2Expenses);
        }