public void Given14EmployeesInDb3EmployeesInMemory_WhenTheNewInMemorySupervisorIsAddedToDatabase_ShouldHave17RecordsInDb()
        {
            //---------------------------------- ARRANGE -------------------------------------

            //arranging supervisor data
            Employee supervisorEmployee = TestDataFactory.CreateNewObjectWithValidNewEmployeeData();

            //arranging subordinate data
            Employee subordinateEmployee = TestDataFactory.CreateNewObjectWithValidNewEmployeeData();

            subordinateEmployee.Supervisor = supervisorEmployee;

            Employee subordinateEmployee2 = TestDataFactory.CreateNewObjectWithValidNewEmployeeData();

            subordinateEmployee2.Supervisor = supervisorEmployee;

            //arranging count data
            const int EXPECTED_COUNT = 17;

            //---------------------------------- ACT -------------------------------------

            EmployeeBLL.CreateNewEmployee(supervisorEmployee);

            //---------------------------------- ASSERT -------------------------------------

            int ACTUAL_COUNT = EmployeeBLL.GetTotalCountForAllEmployees(string.Empty, 0, 0);

            Assert.AreEqual(EXPECTED_COUNT, ACTUAL_COUNT, "Count doesn't match!");
        }
Exemple #2
0
        public void CreateNewEmployee_SupervisorsCountryIsNotSame_ShouldThrowException()
        {
            //---------------------------------- ARRANGE -------------------------------------

            const string SUPERVISOR_COUNTRY = "USA";
            const string EMPLOYEE_COUNTRY   = "UK";

            //creating sample data for other employee, that would contain the different COUNTRY of the new employee
            Employee supervisorEmployee = TestDataFactory.CreateNewObjectWithValidExistingEmployeeData();

            supervisorEmployee.Country = SUPERVISOR_COUNTRY;

            //populating sample data to ObjectSet container that would be considered as the data source in mock database for employee entities
            employeeObjectSet = new FakeObjectSet <Employee>();
            employeeObjectSet.AddObject(supervisorEmployee);

            //setting up the mock database with sample object
            mockDatabaseConext.Setup(db => db.Employees).Returns(employeeObjectSet);

            //creating sample data for new employee, that would contain the different COUNTRY of another employee loaded in mock database
            Employee newEmployee = TestDataFactory.CreateNewObjectWithValidNewEmployeeData();

            newEmployee.Country    = EMPLOYEE_COUNTRY;
            newEmployee.Supervisor = supervisorEmployee;

            //---------------------------------- ACT -------------------------------------

            //perform the operation that is under test
            employeeBLL.CreateNewEmployee(newEmployee);
        }
        public void CreateNewEmployee_1000NewEmployeesCreated_ShouldBeExecutedInLessThan10Sec()
        {
            //---------------------------------- ARRANGE -------------------------------------

            //expected loading time is 10 seconds
            TimeSpan EXPECTED_EXECUTION_DURATION = TimeSpan.FromSeconds(10);

            Stopwatch stopwatch = new Stopwatch();

            //string the stopwatch
            stopwatch.Start();

            //---------------------------------- ACT -------------------------------------

            //test method goes here
            for (int i = 0; i < 1000; i++)
            {
                EmployeeBLL.CreateNewEmployee(TestDataFactory.CreateNewObjectWithValidNewEmployeeData());
            }

            //---------------------------------- ASSERT -------------------------------------

            //stopping the stopwatch
            stopwatch.Stop();

            TimeSpan ACTUAL_EXECUTION_DURATION = stopwatch.Elapsed;

            Console.WriteLine("Method executed in toal seconds : " + ACTUAL_EXECUTION_DURATION.TotalSeconds);

            Assert.IsTrue(stopwatch.Elapsed < EXPECTED_EXECUTION_DURATION,
                          string.Format(System.Globalization.CultureInfo.CurrentCulture,
                                        "Loading time ({0:#,##0.0} seconds) exceed the expected time ({1:#,##0.0} seconds).",
                                        ACTUAL_EXECUTION_DURATION.TotalSeconds, EXPECTED_EXECUTION_DURATION.TotalSeconds));
        }
        public void CreateNewEmployee_NullEmployeeToBePassedAsArgument_ShouldThrowException()
        {
            //Arrange
            Employee NULL_EMPLOYEE_AS_INVALID_VALUE = null;

            //Act
            EmployeeBLL.CreateNewEmployee(NULL_EMPLOYEE_AS_INVALID_VALUE);
        }
        public void CreateNewEmployee_MethodCalledWithEmployeeId_ShouldRunSuccessfully()
        {
            //setting up the in-memory database with required data for test
            FakeObjectSet <Employee> employeeObjectSet = new FakeObjectSet <Employee>();

            mockDatabaseConext.Setup(db => db.Employees).Returns(employeeObjectSet);
            mockDatabaseConext.Setup(db => db.SaveChanges()).Returns(1);
            EmployeeBLL employeeBLL     = new EmployeeBLL(mockDatabaseConext.Object);
            Employee    employeeNewData = TestDataFactory.CreateNewObjectWithValidNewEmployeeData();

            employeeBLL.CreateNewEmployee(employeeNewData);
        }
        public void CreateNewEmployee_ValidNewEmployeeObjectPassed_ShouldReturnNonzero()
        {
            //---------------------------------- ARRANGE -------------------------------------

            const int INITIAL_NO_EMPLOYEE_STATE = 0;

            //---------------------------------- ACT -------------------------------------

            int NEW_EMPLOYEE_ID = EmployeeBLL.CreateNewEmployee(TestDataFactory.CreateNewObjectWithValidNewEmployeeData());

            //---------------------------------- ASSERT -------------------------------------

            Assert.AreNotEqual(INITIAL_NO_EMPLOYEE_STATE, NEW_EMPLOYEE_ID, "Employee was not created.");
        }
        public void Given14Employees_WhenANewEmployeeCreatedToDatabase_ShouldHave15Records()
        {
            //---------------------------------- ARRANGE -------------------------------------

            Employee  employee       = TestDataFactory.CreateNewObjectWithValidNewEmployeeData();
            const int EXPECTED_COUNT = 15;

            //---------------------------------- ACT -------------------------------------

            EmployeeBLL.CreateNewEmployee(employee);

            //---------------------------------- ASSERT -------------------------------------

            int ACTUAL_COUNT = EmployeeBLL.GetTotalCountForAllEmployees(string.Empty, 0, 0);

            Assert.AreEqual(EXPECTED_COUNT, ACTUAL_COUNT, "Count doesn't match!");
        }
        public void LastName_ValidValueToBeInsertedToDatabase_ShouldReturnSameValueFromDatabase()
        {
            //---------------------------------- ARRANGE -------------------------------------

            Employee     newEmployeeObjectWithValidSampleData = TestDataFactory.CreateNewObjectWithValidNewEmployeeData();
            const string EXPECTED_LAST_NAME = "Doe";

            newEmployeeObjectWithValidSampleData.LastName = EXPECTED_LAST_NAME;

            //---------------------------------- ACT -------------------------------------

            int newEmployeeId = EmployeeBLL.CreateNewEmployee(newEmployeeObjectWithValidSampleData);

            Employee insertedEmployee = EmployeeBLL.GetEmployeeByEmployeeId(newEmployeeId);
            string   ACTUAL_LAST_NAME = insertedEmployee.LastName;

            Assert.AreEqual(EXPECTED_LAST_NAME, ACTUAL_LAST_NAME, "value was NOT inserted successfully.");
        }
Exemple #9
0
        public void City_NullValueToBeInsertedToDatabase_ShouldReturnNullValueFromDatabase()
        {
            //---------------------------------- ARRANGE -------------------------------------

            Employee     newEmployeeObjectWithValidSampleData = TestDataFactory.CreateNewObjectWithValidNewEmployeeData();
            const string EXPECTED_CITY = null;

            newEmployeeObjectWithValidSampleData.City = EXPECTED_CITY;

            //---------------------------------- ACT -------------------------------------

            int      newEmployeeId    = EmployeeBLL.CreateNewEmployee(newEmployeeObjectWithValidSampleData);
            Employee insertedEmployee = EmployeeBLL.GetEmployeeByEmployeeId(newEmployeeId);
            string   ACTUAL_CITY      = insertedEmployee.City;

            //---------------------------------- ASSERT -------------------------------------

            Assert.AreEqual(EXPECTED_CITY, ACTUAL_CITY, "City was not saved with null value.");
        }
Exemple #10
0
        public void CreateNewEmployee_NewEmployeeObjectPassed_ShouldCall_DatabaseContext_SaveChanges_Method()
        {
            /*The reason to use FakeObjectSet is, CreateNewEmployee method includes query level operation for business logic, we need to use FakeObjectSet. If no query was used we could use IObjectSet mock.*/
            FakeObjectSet <Employee> employees = new FakeObjectSet <Employee>();

            //setting up expectation for the DatabaseContext.SaveChanges method to be called
            mockDatabaseConext.Setup(_db => _db.SaveChanges()).Verifiable();
            //an EmployeeDatabaseContext.Employees ObjectSet is required for invoking IObjectSet.AddObject method
            mockDatabaseConext.Setup(_db => _db.Employees).Returns(employees);
            mockDatabaseConext.Setup(_db => _db.SaveChanges()).Returns(1);


            EmployeeBLL employeeBLL = new EmployeeBLL(mockDatabaseConext.Object);

            //calling the method for expected method verification
            employeeBLL.CreateNewEmployee(TestDataFactory.CreateNewObjectWithValidNewEmployeeData());

            mockDatabaseConext.Verify();
        }
Exemple #11
0
        public void BirthDate_NullValueToBeInsertedToDatabase_ShouldReturnNullValueFromDatabase()
        {
            //---------------------------------- ARRANGE -------------------------------------

            Employee newEmployeeObjectWithValidSampleData = TestDataFactory.CreateNewObjectWithValidNewEmployeeData();
            DateTime?EXPECTED_BIRTH_DATE = null;

            newEmployeeObjectWithValidSampleData.BirthDate = EXPECTED_BIRTH_DATE;

            //---------------------------------- ACT -------------------------------------

            int newEmployeeId = EmployeeBLL.CreateNewEmployee(newEmployeeObjectWithValidSampleData);

            //---------------------------------- ASSERT -------------------------------------

            Employee insertedEmployee  = EmployeeBLL.GetEmployeeByEmployeeId(newEmployeeId);
            DateTime?ACTUAL_BIRTH_DATE = insertedEmployee.BirthDate;

            Assert.AreEqual(EXPECTED_BIRTH_DATE, ACTUAL_BIRTH_DATE, "BirthDate was not saved with null value.");
        }
Exemple #12
0
        public void TitleOfCourtecy_NullValueToBeInsertedToDatabase_ShouldReturnNullValueFromDatabase()
        {
            //---------------------------------- ARRANGE -------------------------------------

            Employee     newEmployeeObjectWithValidSampleData = TestDataFactory.CreateNewObjectWithValidNewEmployeeData();
            const string EXPECTED_TITLE_OF_COURTECY           = null;

            newEmployeeObjectWithValidSampleData.TitleOfCourtesy = EXPECTED_TITLE_OF_COURTECY;

            //---------------------------------- ACT -------------------------------------

            int newEmployeeId = EmployeeBLL.CreateNewEmployee(newEmployeeObjectWithValidSampleData);

            //---------------------------------- ASSERT -------------------------------------

            Employee insertedEmployee         = EmployeeBLL.GetEmployeeByEmployeeId(newEmployeeId);
            string   ACTUAL_TITLE_OF_COURTECY = insertedEmployee.TitleOfCourtesy;

            Assert.AreEqual(EXPECTED_TITLE_OF_COURTECY, ACTUAL_TITLE_OF_COURTECY, "Title of Courtecy was not saved with null value.");
        }
Exemple #13
0
        public void ReportsTo_NullValueToBeInsertedToDatabase_ShouldReturnNullValueFromDatabase()
        {
            //---------------------------------- ARRANGE -------------------------------------

            Employee newEmployeeObjectWithValidSampleData = TestDataFactory.CreateNewObjectWithValidNewEmployeeData();
            int?     EXPECTED_REPORTSTO = null;

            newEmployeeObjectWithValidSampleData.ReportsTo = EXPECTED_REPORTSTO;

            //---------------------------------- ACT -------------------------------------

            int newEmployeeId = EmployeeBLL.CreateNewEmployee(newEmployeeObjectWithValidSampleData);

            //---------------------------------- ASSERT -------------------------------------

            Employee insertedEmployee = EmployeeBLL.GetEmployeeByEmployeeId(newEmployeeId);
            int?     ACTUAL_REPORTSTO = insertedEmployee.ReportsTo;

            Assert.AreEqual(EXPECTED_REPORTSTO, ACTUAL_REPORTSTO, "ReportsTo was not saved with null value.");
        }
Exemple #14
0
        public void Extension_NullValueToBeInsertedToDatabase_ShouldReturnDefaultValueFromDatabase()
        {
            //---------------------------------- ARRANGE -------------------------------------

            Employee     newEmployeeObjectWithValidSampleData = TestDataFactory.CreateNewObjectWithValidNewEmployeeData();
            const string EXPECTED_EXTENSION = "n/a";

            newEmployeeObjectWithValidSampleData.Extension = EXPECTED_EXTENSION;

            //---------------------------------- ACT -------------------------------------

            int newEmployeeId = EmployeeBLL.CreateNewEmployee(newEmployeeObjectWithValidSampleData);

            //---------------------------------- ASSERT -------------------------------------

            Employee insertedEmployee = EmployeeBLL.GetEmployeeByEmployeeId(newEmployeeId);
            string   ACTUAL_EXTENSION = insertedEmployee.Extension;

            Assert.AreEqual(EXPECTED_EXTENSION, ACTUAL_EXTENSION, "Extension was not saved with null value.");
        }
Exemple #15
0
        public void PostalCode_NullValueToBeInsertedToDatabase_ShouldReturnNullValueFromDatabase()
        {
            //---------------------------------- ARRANGE -------------------------------------

            Employee     newEmployeeObjectWithValidSampleData = TestDataFactory.CreateNewObjectWithValidNewEmployeeData();
            const string EXPECTED_POSTALCODE = null;

            newEmployeeObjectWithValidSampleData.PostalCode = EXPECTED_POSTALCODE;

            //---------------------------------- ACT -------------------------------------

            int newEmployeeId = EmployeeBLL.CreateNewEmployee(newEmployeeObjectWithValidSampleData);

            //---------------------------------- ASSERT -------------------------------------

            Employee insertedEmployee  = EmployeeBLL.GetEmployeeByEmployeeId(newEmployeeId);
            string   ACTUAL_POSTALCODE = insertedEmployee.PostalCode;

            Assert.AreEqual(EXPECTED_POSTALCODE, ACTUAL_POSTALCODE, "PostalCode was not saved with null value.");
        }
Exemple #16
0
        public void CreateNewEmployee_NewEmployeeObjectPassed_ShouldCall_ObjectSet_AddObject_Method()
        {
            /*Creating Mock (and Fake) ObjectSet of Employee entity
             * The reason to use Mock is to make ObjectSet available for verification.
             * The reason to use FakeObjectSet is, CreateNewEmployee method includes query level operation for business logic, we need to use FakeObjectSet. If no query was used we could use IObjectSet mock.*/
            Mock <FakeObjectSet <Employee> > employees = new Mock <FakeObjectSet <Employee> >();

            employees.Setup(emp => emp.AddObject(It.IsAny <Employee>())).Verifiable();
            mockDatabaseConext.Setup(db => db.SaveChanges()).Returns(1);

            //an EmployeeDatabaseContext.Employees ObjectSet is required for invoking IObjectSet.AddObject method
            mockDatabaseConext.Setup(_db => _db.Employees).Returns(employees.Object);

            EmployeeBLL employeeBLL = new EmployeeBLL(mockDatabaseConext.Object);

            //calling the method for expected method verification
            employeeBLL.CreateNewEmployee(TestDataFactory.CreateNewObjectWithValidNewEmployeeData());

            employees.Verify();
        }
Exemple #17
0
        public void Photo_NullValueToBeInsertedToDatabase_ShouldReturnNullValueFromDatabase()
        {
            //---------------------------------- ARRANGE -------------------------------------

            Employee     newEmployeeObjectWithValidSampleData = TestDataFactory.CreateNewObjectWithValidNewEmployeeData();
            const byte[] EXPECTED_PHOTO = null;

            newEmployeeObjectWithValidSampleData.Photo = EXPECTED_PHOTO;

            //---------------------------------- ACT -------------------------------------

            int newEmployeeId = EmployeeBLL.CreateNewEmployee(newEmployeeObjectWithValidSampleData);

            //---------------------------------- ASSERT -------------------------------------

            Employee insertedEmployee = EmployeeBLL.GetEmployeeByEmployeeId(newEmployeeId);

            byte[] ACTUAL_PHOTO = insertedEmployee.Photo;

            Assert.AreEqual(EXPECTED_PHOTO, ACTUAL_PHOTO, "Photo was not saved with null value.");
        }
        public void CreateNewEmployee_SupervisorsCountryIsNotSame_ShouldThrowException()
        {
            //---------------------------------- ARRANGE -------------------------------------

            const string SUPERVISOR_COUNTRY            = "USA";
            const string SUBORDINATE_DIFFERENT_COUNTRY = "Bangladesh";

            //arranging supervisor data
            Employee supervisorEmployee = EmployeeBLL.GetEmployeeByEmployeeId(1);

            supervisorEmployee.Country = SUPERVISOR_COUNTRY;

            //arranging subordinate data
            Employee subordinateEmployee = TestDataFactory.CreateNewObjectWithValidNewEmployeeData();

            subordinateEmployee.Country    = SUBORDINATE_DIFFERENT_COUNTRY;
            subordinateEmployee.Supervisor = supervisorEmployee;

            //---------------------------------- ACT -------------------------------------

            //perform the operation that is under test
            EmployeeBLL.CreateNewEmployee(subordinateEmployee);
        }