Esempio n. 1
0
        public IActionResult GetAll([FromBody] EmployeeSignUpDTO employeeSignUpDTO)
        {
            if (employeeSignUpDTO == null)
            {
                return(new BadRequestResult());
            }

            var result = _signUpService.NewSignUp(employeeSignUpDTO);

            if (result == null)
            {
                //Internal Server Error
                return(StatusCode(500));
            }

            return(new JsonResult(result));
        }
Esempio n. 2
0
        public void TestNewSignUp_ValidInput()
        {
            //Setup the required properties
            var random     = new Random();
            var eventId    = random.Next(2000);
            var employeeId = random.Next(2000);

            var emailAddress = "*****@*****.**";
            var comments     = "Test 2 Comments";
            var firstName    = "Test 2 First Name";
            var lastName     = "Test 2 Last Name";

            var employeeDTO = Mock.Of <EmployeeDTO>(e => e.EmailAddress == emailAddress &&
                                                    e.FirstName == firstName &&
                                                    e.LastName == lastName &&
                                                    e.Id == employeeId);

            var employeeSignUps = Mock.Of <List <EmployeeSignUps> >();

            //Setup the test object
            var employeeSignUpDTO = Mock.Of <EmployeeSignUpDTO>(x => x.Comments == comments &&
                                                                x.EmailAddress == emailAddress &&
                                                                x.EventId == eventId &&
                                                                x.FirstName == firstName &&
                                                                x.LastName == lastName);

            //Setup the _employeeService methods
            _employeeService.Setup(x => x.GetEmployee(It.IsAny <string>())).Returns((EmployeeDTO)null);
            _employeeService.Setup(x => x.AddNewEmployee(It.IsAny <EmployeeSignUpDTO>())).Returns(employeeDTO);

            //Setup the _eventsService methods
            _eventsService.Setup(x => x.GetSignUpsForEvent(It.IsAny <int>())).Returns(employeeSignUps);
            _eventsService.Setup(x => x.AddEmployeeToEvent(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(employeeSignUpDTO);

            //Call the method to test => NewSignUp()
            var signUpResult = _signUpService.NewSignUp(employeeSignUpDTO);

            //Verify Employee Service method calls
            _employeeService.Verify(m => m.GetEmployee(It.IsAny <string>()), Times.Once);
            _employeeService.Verify(m =>
                                    m.AddNewEmployee(It.Is <EmployeeSignUpDTO>(s => s.Comments == comments &&
                                                                               s.EmailAddress == emailAddress &&
                                                                               s.EventId == eventId &&
                                                                               s.FirstName == firstName &&
                                                                               s.LastName == lastName)
                                                     ), Times.Once);

            //Verify Event Service method calls
            _eventsService.Verify(m => m.GetSignUpsForEvent(It.Is <int>(x => x == eventId)), Times.Once);
            _eventsService.Verify(m => m.AddEmployeeToEvent(It.Is <int>(x => x == eventId),
                                                            It.Is <int>(x => x == employeeId), It.Is <string>(x => x == comments)), Times.Once);

            //Test the Returned Object
            Assert.True(signUpResult.Result);
            Assert.IsEmpty(signUpResult.ErrorMessage);
            Assert.IsNotNull(signUpResult.EmployeeSignUp);

            Assert.AreEqual(signUpResult.EmployeeSignUp.Comments, comments);
            Assert.AreEqual(signUpResult.EmployeeSignUp.EmailAddress, emailAddress);
            Assert.AreEqual(signUpResult.EmployeeSignUp.EventId, eventId);
            Assert.AreEqual(signUpResult.EmployeeSignUp.FirstName, firstName);
            Assert.AreEqual(signUpResult.EmployeeSignUp.LastName, lastName);
        }