示例#1
0
        public void TestPutGetEmployee()
        {
            BusinessAPIControllerTest businessAPITest = new BusinessAPIControllerTest();

            businessAPITest.Setup();

            string businessID = businessAPITest.PostBusiness();

            var employeeDTO = new EmployeeDTO
            {
                FirstName   = "Unit" + DateTime.Now.GetHashCode().ToString(),
                LastName    = "TestPostGet",
                MobilePhone = "876435",
                Email       = "*****@*****.**",
                Type        = EmployeeTypeDTO.Casual,
                BusinessId  = Guid.Parse(businessID)
            };

            //First create a new employee
            HttpResponseMessage response = employeeAPIController.PostEmployee(employeeDTO);

            Assert.AreEqual(response.StatusCode, HttpStatusCode.Created);

            var queryString = new List <string>(response.Headers.Location.Segments);
            var newID       = Guid.Parse(queryString[queryString.Count - 1]);

            employeeDTO.Id = newID;

            //now load the newly saved business back up
            var savedEmployeeDTO = employeeAPIController.GetEmployee(newID);

            Assert.AreEqual(employeeDTO, savedEmployeeDTO);

            //Test UPDATE
            savedEmployeeDTO.LastName = savedEmployeeDTO.LastName.Replace("TestPostGet", "TestPutGet");
            //Test changing employee type
            savedEmployeeDTO.Type = EmployeeTypeDTO.Full_Time;

            //Call update method
            response = employeeAPIController.PutEmployee(newID, savedEmployeeDTO);

            //now load the newly updated business back up and compare
            var updatedEmployeeDTO = employeeAPIController.GetEmployee(newID);

            Assert.AreEqual(savedEmployeeDTO, updatedEmployeeDTO);
        }
示例#2
0
        public void TestPostDeleteEmployeeRole()
        {
            BusinessAPIControllerTest businessAPITest = new BusinessAPIControllerTest();

            businessAPITest.Setup();

            string businessID = businessAPITest.PostBusiness();
            string roleID     = businessAPITest.GetRole(businessID);

            var employeeDTO = new EmployeeDTO
            {
                FirstName   = "Unit" + DateTime.Now.GetHashCode().ToString(),
                LastName    = "TestPostDeleteRole",
                MobilePhone = "876435",
                Email       = "*****@*****.**",
                Type        = EmployeeTypeDTO.Casual,
                BusinessId  = Guid.Parse(businessID)
            };

            //First create a new employee
            HttpResponseMessage response = employeeAPIController.PostEmployee(employeeDTO);

            Assert.AreEqual(response.StatusCode, HttpStatusCode.Created);

            var queryString = new List <string>(response.Headers.Location.Segments);
            var newID       = Guid.Parse(queryString[queryString.Count - 1]);

            HttpResponseMessage responseRole = employeeAPIController.PostEmployeeRole(newID, Guid.Parse(roleID));

            Assert.AreEqual(responseRole.StatusCode, HttpStatusCode.OK);

            //now load the newly saved employee back up and verify that role is added
            var savedEmployeeDTO = employeeAPIController.GetEmployee(newID);

            Assert.IsTrue(savedEmployeeDTO.Roles.Count > 0);
            Assert.IsTrue(savedEmployeeDTO.Roles[0].Id == Guid.Parse(roleID));

            HttpResponseMessage responseDeleteRole = employeeAPIController.DeleteEmployeeRole(newID, Guid.Parse(roleID));

            Assert.AreEqual(responseRole.StatusCode, HttpStatusCode.OK);

            //now load the employee back up and verify that role is removed
            savedEmployeeDTO = employeeAPIController.GetEmployee(newID);
            Assert.IsTrue(savedEmployeeDTO.Roles.Count == 0);
        }
示例#3
0
        public void TestPostDeleteEmployee()
        {
            BusinessAPIControllerTest businessAPITest = new BusinessAPIControllerTest();

            businessAPITest.Setup();

            string businessID = businessAPITest.PostBusiness();

            var employeeDTO = new EmployeeDTO
            {
                FirstName   = "Unit" + DateTime.Now.GetHashCode().ToString(),
                LastName    = "TestPost",
                MobilePhone = "44122322",
                Email       = "*****@*****.**",
                Type        = EmployeeTypeDTO.Casual,
                BusinessId  = Guid.Parse(businessID)
            };

            //First create a new employee
            HttpResponseMessage response = employeeAPIController.PostEmployee(employeeDTO);

            Assert.AreEqual(response.StatusCode, HttpStatusCode.Created);

            var queryString = new List <string>(response.Headers.Location.Segments);
            var newID       = Guid.Parse(queryString[queryString.Count - 1]);

            employeeAPIController.DeleteEmployee(newID);

            try
            {
                //now try to load the deleted business
                var savedEmployeeDTO = employeeAPIController.GetEmployee(newID);
                Assert.Fail(); //Should not get here as exception is thrown.
            }
            catch (HttpResponseException ex)
            {
                Assert.IsTrue(ex.Response.StatusCode == HttpStatusCode.NotFound);
            }
        }
示例#4
0
        public void TestPostDeleteBusinessRole()
        {
            BusinessAPIControllerTest businessAPITest = new BusinessAPIControllerTest();

            businessAPITest.Setup();

            string businessID = businessAPITest.PostBusiness();

            var roleDTO = new RoleDTO
            {
                Id         = Guid.NewGuid(),
                Name       = "UnitTestRole" + DateTime.Now.GetHashCode().ToString(),
                BusinessId = Guid.Parse(businessID)
            };

            HttpResponseMessage response = businessAPIController.PostBusinessRole(roleDTO.BusinessId, roleDTO.Id, roleDTO);

            Assert.AreEqual(response.StatusCode, HttpStatusCode.Created);
            Guid roleId = Guid.Parse(response.Headers.Location.Segments[3]);

            HttpResponseMessage deleteResponse = businessAPIController.DeleteBusinessRole(roleDTO.BusinessId, roleId);

            Assert.AreEqual(deleteResponse.StatusCode, HttpStatusCode.OK);
        }