예제 #1
0
        public void UserTest_Init()
        {
            var createdDate = DateTime.Now;

            CACI.DAL.Models.User obj = new CACI.DAL.Models.User()
            {
                UserId      = 15,
                FirstName   = "First",
                MiddleName  = "M",
                LastName    = "Last",
                Email       = "*****@*****.**",
                IsActive    = true,
                IsApproved  = true,
                UserName    = "******",
                Password    = "******",
                CreatedDate = createdDate,
                CreatedUser = "******"
            };


            Assert.IsNotNull(obj);
            Assert.AreEqual(15, obj.UserId);
            Assert.AreEqual("First", obj.FirstName);
            Assert.AreEqual("M", obj.MiddleName);
            Assert.AreEqual("Last", obj.LastName);
            Assert.AreEqual("*****@*****.**", obj.Email);
            Assert.AreEqual(true, obj.IsActive);
            Assert.AreEqual(true, obj.IsApproved);
            Assert.AreEqual("PickSomethingHard", obj.Password);
            Assert.AreEqual(createdDate, obj.CreatedDate);
            Assert.AreEqual("UnitTestAdmin1", obj.CreatedUser);
            Assert.IsNull(obj.ModifiedDate);
            Assert.IsNull(obj.ModifiedUser);
        }
예제 #2
0
        public void UserController_Post_ReturnsBadRequestOnException()
        {
            _mockService.Setup(m => m.Add(It.IsAny <CACI.DAL.Models.User>())).Throws(new System.Exception("Test Exception"));
            UserController _controller = new UserController(_mockService.Object, _logger.Object);

            CACI.DAL.Models.User user = new CACI.DAL.Models.User()
            {
                CreatedDate  = DateTime.Now.AddDays(-8),
                CreatedUser  = "******",
                Email        = "*****@*****.**",
                FirstName    = "Unit",
                LastName     = "Test",
                IsActive     = true,
                IsApproved   = true,
                MiddleName   = "T",
                ModifiedDate = DateTime.Now,
                ModifiedUser = "******",
                Password     = "******",
                UserId       = 1,
                UserName     = "******"
            };
            var result = _controller.Post(user);

            Assert.IsTrue(result is BadRequestObjectResult);
        }
예제 #3
0
        public void UserController_DeleteFromBody_ReturnsBadRequestOnException()
        {
            _mockService.Setup(m => m.Delete(It.IsAny <CACI.DAL.Models.User>())).Throws(new System.Exception("Test Exception"));
            UserController _controller = new UserController(_mockService.Object, _logger.Object);

            CACI.DAL.Models.User user = new CACI.DAL.Models.User()
            {
                CreatedDate  = DateTime.Now.AddDays(-88),
                CreatedUser  = "******",
                Email        = "*****@*****.**",
                FirstName    = "Unit5",
                LastName     = "Test",
                IsActive     = true,
                IsApproved   = true,
                MiddleName   = "T",
                ModifiedDate = DateTime.Now.AddDays(-32),
                ModifiedUser = "******",
                Password     = "******",
                UserId       = 4,
                UserName     = "******"
            };

            var result = _controller.Delete(user);

            Assert.IsTrue(result is BadRequestObjectResult);
        }
예제 #4
0
        public void UserController_Login_ReturnsBadRequestWhenModelStateNotValid()
        {
            CACI.DAL.Models.User user = new CACI.DAL.Models.User()
            {
                CreatedDate  = DateTime.Now.AddDays(-8),
                CreatedUser  = "******",
                Email        = "*****@*****.**",
                FirstName    = "Unit",
                LastName     = "Test",
                IsActive     = true,
                IsApproved   = true,
                MiddleName   = "T",
                ModifiedDate = DateTime.Now,
                ModifiedUser = "******",
                Password     = "******",
                UserId       = 1,
                UserName     = "******"
            };
            UserController _controller = new UserController(_mockService.Object, _logger.Object);

            _controller.ModelState.AddModelError("error", "test");

            var result = _controller.Login(user);

            Assert.IsTrue(result.Result is BadRequestObjectResult);
        }
예제 #5
0
        public void UserController_Login()
        {
            CACI.DAL.Models.User user = new CACI.DAL.Models.User()
            {
                CreatedDate  = DateTime.Now.AddDays(-8),
                CreatedUser  = "******",
                Email        = "*****@*****.**",
                FirstName    = "Unit",
                LastName     = "Test",
                IsActive     = true,
                IsApproved   = true,
                MiddleName   = "T",
                ModifiedDate = DateTime.Now,
                ModifiedUser = "******",
                Password     = "******",
                UserId       = 1,
                UserName     = "******"
            };
            UserController _controller = new UserController(_mockService.Object, _logger.Object);
            var            result      = _controller.Login(user);

            Assert.IsNotNull(result);
        }
예제 #6
0
        public void UserController_DeleteFromBody()
        {
            CACI.DAL.Models.User user = new CACI.DAL.Models.User()
            {
                CreatedDate  = DateTime.Now.AddDays(-88),
                CreatedUser  = "******",
                Email        = "*****@*****.**",
                FirstName    = "Unit5",
                LastName     = "Test",
                IsActive     = true,
                IsApproved   = true,
                MiddleName   = "T",
                ModifiedDate = DateTime.Now.AddDays(-32),
                ModifiedUser = "******",
                Password     = "******",
                UserId       = 4,
                UserName     = "******"
            };
            UserController _controller = new UserController(_mockService.Object, _logger.Object);
            var            result      = _controller.Delete(user);

            Assert.IsNotNull(result);
        }
예제 #7
0
        public void UserController_Put()
        {
            CACI.DAL.Models.User application = new CACI.DAL.Models.User()
            {
                CreatedDate  = DateTime.Now.AddDays(-88),
                CreatedUser  = "******",
                Email        = "*****@*****.**",
                FirstName    = "Unit8",
                LastName     = "Test",
                IsActive     = true,
                IsApproved   = true,
                MiddleName   = "T",
                ModifiedDate = DateTime.Now.AddDays(-32),
                ModifiedUser = "******",
                Password     = "******",
                UserId       = 9,
                UserName     = "******"
            };
            UserController _controller = new UserController(_mockService.Object, _logger.Object);
            var            result      = _controller.Put(application);

            Assert.IsNotNull(result);
        }
예제 #8
0
        public void UserController_Login_ReturnsUnauthorizedResultWhenUserServiceLoginReturnsNull()
        {
            _mockService.Setup(m => m.Login(It.IsAny <CACI.DAL.Models.User>())).Returns(null as CACI.DAL.Models.User);
            CACI.DAL.Models.User user = new CACI.DAL.Models.User()
            {
                CreatedDate  = DateTime.Now.AddDays(-8),
                CreatedUser  = "******",
                Email        = "*****@*****.**",
                FirstName    = "Unit",
                LastName     = "Test",
                IsActive     = true,
                IsApproved   = true,
                MiddleName   = "T",
                ModifiedDate = DateTime.Now,
                ModifiedUser = "******",
                Password     = "******",
                UserId       = 1,
                UserName     = "******"
            };
            UserController _controller = new UserController(_mockService.Object, _logger.Object);
            var            result      = _controller.Login(user);

            Assert.IsTrue(result.Result is UnauthorizedResult);
        }