Esempio n. 1
0
        public void addEmployee()
        {
            Employees employee = new EmployeeBuilder("Boskovic", "Milos").Build();

            index = repo.addEmployee(employee);
            Assert.IsTrue(index != 0);
        }
Esempio n. 2
0
        public void TestDeleteEmployeeByID()
        {
            onSetUp();
            // Create an employee
            var employeeBuilder     = new EmployeeBuilder().setName(NAME);
            var addEmployeesRequest = employeeBuilder.CreateAddEmployeesRequest();

            // Add them to the database
            employeeController.Post(addEmployeesRequest);
            //Get them from the database and find their ID
            var databaseEmployee = employeeController.Get(NAME);
            var ID = databaseEmployee.Employees.Last().PersonalId;

            var removeEmployeeRequest = new RemoveEmployeeRequest()
            {
                PersonalID = ID
            };

            employeeController.Delete(removeEmployeeRequest);

            try
            {
                employeeController.GetEmployeeByID(ID);
                Assert.IsTrue(false); //Means that it found the employee so fail the test
            }
            catch
            {
                Assert.IsTrue(true);
            }
        }
Esempio n. 3
0
        public void TestDeleteEmployees()
        {
            onSetUp();
            var employeeBuilder = new EmployeeBuilder().setName(NAME);

            employeeRepository.AddEmployees(new List <Employee>()
            {
                employeeBuilder.CreateEmployee()
            });

            var removeEmployeeRequest = new RemoveEmployeeRequest()
            {
                Name = NAME
            };

            employeeController.Delete(removeEmployeeRequest);

            try
            {
                employeeController.Get(NAME);
                Assert.Fail("Expected exception to be thrown.");
            }
            catch (NoSuchEntityException e)
            {
                Assert.IsTrue(e.Message.Contains(NAME));
            }
        }
Esempio n. 4
0
        public void UsingAnotherBuilderInSetup_EmployeeMustAtLeastHaveOneAussieAddress()
        {
            var builder = new EmployeeBuilder();

            var actual = builder.WithEmployeeFromAustralia()
                         // mix things up a bit and add another address manually by instantiating a new AddressBuilder
                         .With(e => e.Addresses.Add(new AddressBuilder()
                                                    .WithSouthAfricanAddress()
                                                    .Build())
                               )
                         .Build();

            actual.Addresses.Count().ShouldBeGreaterThan(1);
            actual.Addresses.Any(a => a.PostCode == "6000").ShouldBeTrue("No Aussie address detected.");


            // same test BUT this time request a builder via the .With<TRequestBuilder> instead of instantiating it.
            builder = new EmployeeBuilder();
            actual  = builder.WithEmployeeFromAustralia()
                      .With <AddressBuilder>((e, addressBuilder) => e.Addresses.Add(addressBuilder
                                                                                    .WithSouthAfricanAddress()
                                                                                    .Build())
                                             )
                      .Build();

            actual.Addresses.Count().ShouldBeGreaterThan(1);
            actual.Addresses.Any(a => a.PostCode == "6000").ShouldBeTrue("No Aussie address detected.");
        }
Esempio n. 5
0
 private void btnThem_Click_1(object sender, EventArgs e)
 {
     try
     {
         string   last_name = txtHoTen.Text;
         string   address   = txtQueQuan.Text;
         string   phone     = txtSDT.Text;
         string   email     = txtEmail.Text;
         DateTime birth_day = dtpNgaySinh.Value;
         id_position = (int)cbChucVu.EditValue;
         PersonBuilder personBuilder;
         if (id_position == 1)
         {
             personBuilder = new AdminBuilder();
         }
         else
         {
             personBuilder = new EmployeeBuilder();
         }
         personBuilder
         .BuildAddress(address)
         .BuildFullName(last_name)
         .BuildEamil(email)
         .BuildPhone(phone)
         .BuildBirthDate(birth_day);
         PersonBus.Instance.InsertPerson(personBuilder.getPerson());
         LoadAllEmployee();
     }
     catch (Exception ex)
     {
         XtraMessageBox.Show("Error: " + ex.Message);
     }
     ResetInput();
 }
Esempio n. 6
0
 public Employee(EmployeeBuilder builder)
 {
     this.Name              = builder.name;
     this.LastName          = builder.lastname;
     this.isActiveEmployee  = builder.isActiveEmployee;
     this.iFullTimeEmployee = builder.iFullTimeEmployee;
     this.salary            = builder.salary;
 }
        public Employees getEmployeeById(int employeeID)
        {
            Employees employee = null;

            Connection    conn       = new Connection();
            SqlConnection connection = conn.SqlConnection;

            SqlCommand selectCommand = new SqlCommand();

            selectCommand.Connection  = connection;
            selectCommand.CommandType = CommandType.StoredProcedure;
            selectCommand.CommandText = "GetEmployeeById";

            selectCommand.Parameters.Add("@EmployeeID", SqlDbType.Int);
            selectCommand.Parameters["@EmployeeID"].Value = employeeID;

            {
                try
                {
                    connection.Open();
                    SqlDataReader dataReader = selectCommand.ExecuteReader();

                    if (dataReader.HasRows)
                    {
                        dataReader.Read();
                        employee = new EmployeeBuilder(dataReader.GetInt32(0), dataReader.GetString(1), dataReader.GetString(2))
                                   .Title(dataReader.IsDBNull(3) ? (string)null : dataReader.GetString(3))
                                   .TitleOfCourtesy(dataReader.IsDBNull(4) ? (string)null : dataReader.GetString(4))
                                   .BirthDate(dataReader.IsDBNull(5) ? (DateTime?)null : dataReader.GetDateTime(5))
                                   .HireDate(dataReader.IsDBNull(6) ? (DateTime?)null : dataReader.GetDateTime(6))
                                   .Address(dataReader.IsDBNull(7) ? (string)null : dataReader.GetString(7))
                                   .City(dataReader.IsDBNull(8) ? (string)null : dataReader.GetString(8))
                                   .Region(dataReader.IsDBNull(9) ? (string)null : dataReader.GetString(9))
                                   .PostalCode(dataReader.IsDBNull(10) ? (string)null : dataReader.GetString(10))
                                   .Country(dataReader.IsDBNull(11) ? (string)null : dataReader.GetString(11))
                                   .HomePhone(dataReader.IsDBNull(12) ? (string)null : dataReader.GetString(12))
                                   .Extension(dataReader.IsDBNull(13) ? (string)null : dataReader.GetString(13))
                                   .Photo(dataReader.IsDBNull(14) ? null : (byte[])dataReader.GetValue(14))
                                   .Notes(dataReader.IsDBNull(15) ? (string)null : dataReader.GetString(15))
                                   .ReportsTo(dataReader.IsDBNull(16) ? (int?)null : dataReader.GetInt32(16))
                                   .PhotoPath(dataReader.IsDBNull(17) ? (string)null : dataReader.GetString(17))
                                   .Build();
                    }
                    dataReader.Close();
                }
                catch (Exception exc)
                {
                    logger.logError(DateTime.Now, "Error while trying to get Employee with EmployeeID = " + employeeID + ".");
                    MessageBox.Show(exc.Message);
                }
                finally
                {
                    connection.Close();
                }
                logger.logInfo(DateTime.Now, "GetEmployeeById method has sucessfully invoked.");
                return(employee);
            }
        }
        public static void Main(String[] args)
        {
            EmployeeBuilder employeeBuilder = new EmployeeBuilder();  //Create object of class

            employeeBuilder.addCompanyEmpWage("Dmart", 20, 2, 10);    //call method
            employeeBuilder.addCompanyEmpWage("Reliance", 10, 4, 20); //call method
            employeeBuilder.ComputeEmpWage();                         //call method
            Console.WriteLine("Totsl Wage For Dmart Comapny :- " + employeeBuilder.getTotalWage("Dmart"));
        }
Esempio n. 9
0
        public void Execute()
        {
            var manager = new Employee();

            var employee = new EmployeeBuilder()
                           .SetLogin("employee01")
                           .SetManager(manager)
                           .SetLocation(WorkLocations.Remote)
                           .Build();
        }
        public void GetAgeReturnsCorrectValue_MoreExpressive_Test()
        {
            // Arrange
            Employee emp = new EmployeeBuilder().WithBirthDate(new DateTime(1983, 1, 1));
            // Act
            int age = emp.getAge();

            // Assert
            Assert.That(age, Is.EqualTo(DateTime.Today.Year - 1983));
        }
Esempio n. 11
0
        static void Main(string[] args)
        {
            var builder = new EmployeeBuilder();

            builder
            .EmployeeName("aamir khan")
            .Born("03/02/1996")
            .WorkingOn("IT")
            .StaysAt("Chandraghona");
        }
        public void GetFullNameReturnsCombination_MoreExpressive_Test()
        {
            // Arrange
            Employee emp = new EmployeeBuilder().WithFirstName("Kenneth").WithLastName("Truyers");
            // Act
            string fullname = emp.getFullName();

            // Assert
            Assert.That(fullname, Is.EqualTo("Kenneth Truyers"));
        }
        public void TestNestedObjectUsingBuilders()
        {
            var employee = new EmployeeBuilder()
                           .WithFirstName("test")
                           .WithAddress(new AddressBuilder().WithCity("Chicago").Build())
                           .Build();

            Assert.AreEqual("test", employee.FirstName);
            Assert.AreEqual("Chicago", employee.Address.City);
        }
Esempio n. 14
0
        public void SpecificRequirementsCall()
        {
            var builder = new EmployeeBuilder();

            var actual = builder.WithParticularScenarioOfRequirements()
                         .Build();

            actual.Name.ShouldBe("The Name");
            actual.LastName.ShouldBe("The LastName");
            actual.Addresses.Count().ShouldBe(3);
        }
Esempio n. 15
0
        public void SimpleEmployeeBuilder()
        {
            const string expectedText = "Test name";

            var builder = new EmployeeBuilder();

            var actual = builder.With(x => x.Name = expectedText)
                         .Build();

            actual.Name.ShouldBe(expectedText);
        }
Esempio n. 16
0
        public void attaching_a_transient_object_immediately_hits_the_database()
        {
            var employee    = new EmployeeBuilder().Build();
            var insertCount = Statistics.EntityInsertCount;

            Assert.AreEqual(employee.Id, 0);
            Session.Save(employee);
            Assert.Greater(employee.Id, 0);
            // a new insert statement will have been issued already even though we haven't flushed the session
            Assert.AreEqual(insertCount + 1, Statistics.EntityInsertCount);
        }
Esempio n. 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Employee"/> class.
 /// It uses a builder pattern as otherwise there would be too many arguments in constructor
 /// </summary>
 /// <param name="builder">The builder of EmployeeBuilder type</param>
 private Employee(EmployeeBuilder builder)
 {
     this.Id          = builder.id;
     this.Name        = builder.Name;
     this.Address     = builder.Address;
     this.Phone       = builder.Phone;
     this.Email       = builder.Email;
     this.Designation = builder.Designation;
     this.Dept        = builder.Department;
     this.HourlyWage  = builder.HourlyWage;
 }
Esempio n. 18
0
        public void RemoveManualAddingAnAddressIntoAIntoANiceAddMethod_EmployeeMustAtLeastHaveOneAussieAddressJustAnotherWayToCreateTest()
        {
            var builder = new EmployeeBuilder();

            var actual = builder.WithEmployeeFromAustralia()
                         .AddSouthAfricanAddress()
                         .Build();

            actual.Addresses.Count().ShouldBeGreaterThan(1);
            actual.Addresses.Any(a => a.PostCode == "6000").ShouldBeTrue("No Aussie address detected.");
        }
Esempio n. 19
0
        public void GetAgeReturnsCorrectValueFulentBuilder()
        {
            // Arrange
            Employee emp = new EmployeeBuilder().WithBirthDate(new DateTime(1983, 1, 1));

            // Act
            var age = emp.GetAge();

            // Assert
            Assert.AreEqual(age, DateTime.Today.Year - 1983);
        }
Esempio n. 20
0
        public void TestEmployee()
        {
            var builder = new EmployeeBuilder();

            var employee = builder
                           .WithName("Samuel")
                           .HasAge(35)
                           .HasGrossSalaryOf(1000)
                           .Build();

            Assert.AreEqual(850, employee.CalculateNetSalary());
        }
Esempio n. 21
0
        public void TestRoundtripEmployeeRepository()
        {
            OnSetUp();
            var employee = new EmployeeBuilder().CreateEmployee();

            _employeeRepository.AddEmployees(new List <Employee> {
                employee
            });
            Assert.AreEqual(_employeeRepository.GetEmployeeByName(employee.Name).Name, employee.Name);
            Assert.AreEqual(_employeeRepository.GetEmployeeByName(employee.Name).Ext, employee.Ext);
            Assert.AreEqual(_employeeRepository.GetEmployeeByName(employee.Name).WarehouseId, employee.WarehouseId);
        }
Esempio n. 22
0
        public void get_employee_with_highest_salary()
        {
            // the maximum salary to be generated for the testdata is set at 3500
            var topPaidEmployee = new EmployeeBuilder().WithSalary(3600).Build();

            Session.Save(topPaidEmployee);
            FlushAndClear();

            Employee retrievedEmployee = null;

            Assert.AreEqual(topPaidEmployee, retrievedEmployee);
        }
Esempio n. 23
0
        public void TestAddEmployees()
        {
            onSetUp();
            var employeeBuilder     = new EmployeeBuilder().setName(NAME);
            var addEmployeesRequest = employeeBuilder.CreateAddEmployeesRequest();

            var response               = employeeController.Post(addEmployeesRequest);
            var databaseEmployee       = employeeRepository.GetEmployeeByName(NAME);
            var correctDatabaseEmploye = employeeBuilder.CreateEmployee();

            Assert.IsTrue(response.Success);
            Assert.IsTrue(EmployeesAreEqual(new Employee(databaseEmployee), correctDatabaseEmploye));
        }
Esempio n. 24
0
        public void AddMethodShouldOnlyAddOnce_EmployeeMustAtLeastHaveOneAussieAddressJustAnotherWayToCreateTest()
        {
            var builder = new EmployeeBuilder();

            var actual = builder.WithEmployeeFromAustralia() //addresses 1 => aus
                         .AddSouthAfricanAddress()           //addresses 2 => aus, south afr. address
                         .AddSouthAfricanAddress()           //must not add a third address
                         .Build();

            actual.Addresses.Count().ShouldNotBe(3);
            actual.Addresses.Count().ShouldBe(2);
            actual.Addresses.Any(a => a.PostCode == "6000").ShouldBeTrue("No Aussie address detected.");
        }
Esempio n. 25
0
        public void get_employee_with_highest_salary()
        {
            // the maximum salary to be generated for the testdata is set at 3500
            var topPaidEmployee = new EmployeeBuilder().WithSalary(3600).Build();

            Session.Save(topPaidEmployee);
            FlushAndClear();

            var retrievedEmployee = Session.Query <Employee>()
                                    .OrderByDescending(e => e.Salary)
                                    .First();

            Assert.AreEqual(topPaidEmployee, retrievedEmployee);
        }
Esempio n. 26
0
        public Employee Get(string id)
        {
            EmployeeBuilder employeeBuilder = new EmployeeBuilder();

            foreach (Employee employee in employeeBuilder.employeesList)
            {
                if (employee.ID == id)
                {
                    return(employee);
                }
            }

            return(null);
        }
Esempio n. 27
0
        public void SimpleEmployeeBuilderSetMoreThanOneValue()
        {
            var builder = new EmployeeBuilder();

            var actual = builder.With(x =>
            {
                x.Name     = "First";
                x.LastName = "Last";
            })
                         .Build();

            actual.Name.ShouldBe("First");
            actual.LastName.ShouldBe("Last");
        }
        public void EmployeeValidatorTests_EmployeeAddressShouldBeINVALIDWhenNoAustralianPostCodeDetected()
        {
            //arrange
            var builder = new EmployeeBuilder();

            var employee = builder.WithEmployeeFromSouthAfrica()
                           .Build();
            //act
            //system under test
            var sut = new EmployeeValidator(employee);

            //assert
            sut.IsValidAustralianAddress().ShouldBeFalse();
        }
        public void EmployeeValidatorTests_EmployeeAddressShouldBeVALIDWhenAnyPostCodeFromAustraliaDetected()
        {
            //arrange
            var builder = new EmployeeBuilder();

            var employee = builder.WithEmployeeFromAustralia()
                           .Build();

            //act
            //system under test
            var sut = new EmployeeValidator(employee);

            //assert
            sut.IsValidAustralianAddress().ShouldBeTrue();
        }
        public void TestDataUsingBuilder()
        {
            var birthDate = new DateTime(2000, 11, 30);
            var today     = new DateTime(2020, 11, 30);

            var employee = new EmployeeBuilder().WithFirstName("test").Build();

            Assert.AreEqual("test", employee.FirstName);

            employee = new EmployeeBuilder().WithLastName("test").WithBirthDate(birthDate).Build();
            Assert.AreEqual("", employee.FirstName);
            Assert.AreEqual("test", employee.LastName);
            Assert.AreEqual(birthDate, employee.BirthDate);
            Assert.AreEqual(20, employee.GetAge(today));
        }