예제 #1
0
        public void RetrieveEmployeeInfoFail()
        {
            var         testEmail  = "*****@*****.**";
            var         empService = new Mock <IEmployeeService>();
            EttEmployee mockRes    = null; // Return a null response from service call

            empService.Setup(serv => serv.RetrieveEmployeeInfo(It.IsAny <string>())).Returns(mockRes);
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.Name, "test"),
                new Claim(ClaimTypes.NameIdentifier, "1"),
                new Claim("email", testEmail),
            }, "mock"));

            var controller = new EmployeeController(empService.Object);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = user
                }
            };

            var result         = controller.GetEmployeeInfo().Result;
            var notFoundResult = result as NotFoundResult;

            Assert.NotNull(notFoundResult);
            Assert.Equal(404, notFoundResult.StatusCode);
            empService.Verify(x => x.RetrieveEmployeeInfo(It.IsAny <string>()), Times.Once);
        }
예제 #2
0
        public void RetrieveEmployeeInfoNoResults()
        {
            List <EttEmployee> dbRetVal = new List <EttEmployee>();

            MockServiceProvider serviceProvider = new MockServiceProvider()
                                                  .AddMockDBConnection();

            serviceProvider.MockDBConnection
            .Setup(_ => _.ExecuteQuery <EttEmployee>(QueryGenerator.GetEmployeeInfo("*****@*****.**")))
            .Returns(dbRetVal);

            EmployeeService employeeService = new EmployeeService(serviceProvider.Build());
            EttEmployee     response        = employeeService.RetrieveEmployeeInfo("*****@*****.**");

            Assert.Null(response);
        }
예제 #3
0
        public void RetrieveEmployeeInfoSuccess()
        {
            List <EttEmployee> dbRetVal = new List <EttEmployee>()
            {
                new EttEmployee("test", "name", "Developer")
            };

            MockServiceProvider serviceProvider = new MockServiceProvider()
                                                  .AddMockDBConnection();

            serviceProvider.MockDBConnection
            .Setup(_ => _.ExecuteQuery <EttEmployee>(QueryGenerator.GetEmployeeInfo("*****@*****.**")))
            .Returns(dbRetVal);

            EmployeeService employeeService = new EmployeeService(serviceProvider.Build());
            EttEmployee     response        = employeeService.RetrieveEmployeeInfo("*****@*****.**");

            Assert.Equal("test", response.FirstName);
            Assert.Equal("name", response.LastName);
            Assert.Equal("Developer", response.Role);
        }
예제 #4
0
        public void RetrieveEmployeeInfoSuccess()
        {
            var testEmail    = "*****@*****.**";
            var employeeInfo = new EttEmployee("test", "name", "Developer");
            var empService   = new Mock <IEmployeeService>();

            empService.Setup(serv => serv.RetrieveEmployeeInfo(It.IsAny <string>())).Returns(employeeInfo);
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.Name, "test"),
                new Claim(ClaimTypes.NameIdentifier, "1"),
                new Claim("email", testEmail),
            }, "mock"));

            var controller = new EmployeeController(empService.Object);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = user
                }
            };

            var result    = controller.GetEmployeeInfo().Result;
            var okResult  = result as ObjectResult;
            var objString = okResult.Value.ToString();
            var resValue  = JsonConvert.DeserializeObject <EttEmployee>(objString);

            Assert.NotNull(okResult);
            Assert.Equal(200, okResult.StatusCode);
            Assert.Equal("test", resValue.FirstName);
            Assert.Equal("name", resValue.LastName);
            Assert.Equal("Developer", resValue.Role);
            empService.Verify(x => x.RetrieveEmployeeInfo(It.IsAny <string>()), Times.Once);
        }