Exemple #1
0
        public void Access_UserChangePassword_Check_ModelStateIsValid()
        {
            var model   = UserModelTestData.UserModelData();
            var options = new DbContextOptionsBuilder <TestMakerContext>()
                          .UseInMemoryDatabase(databaseName: "Access_UserChangePassword_Check_ModelStateIsValid")
                          .Options;

            using var _context = new TestMakerContext(options);
            _context.Users.Add(model);
            _context.SaveChanges();
            IUserRepository userRepository = new UserRepository(_context);
            var             testMapper     = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new AutoMapperConfig());
            });
            var mapper     = testMapper.CreateMapper();
            var controller = new UserController(userRepository, mapper);

            controller.ModelState.AddModelError("error", "some error");
            var view = controller.ChangePassword(model) as ViewResult;

            Assert.Equal("Change password", view.ViewData["Title"]);
            Assert.Equal("ChangePassword", view.ViewData["Action"]);
            Assert.Equal("User", view.ViewData["Controller"]);
        }
Exemple #2
0
        public void Access_UserIndex_db()
        {
            var model   = UserModelTestData.UserModelData();
            var options = new DbContextOptionsBuilder <TestMakerContext>()
                          .UseInMemoryDatabase(databaseName: "Access_UserIndex_db")
                          .Options;

            using var _context = new TestMakerContext(options);
            _context.Users.Add(model);
            _context.SaveChanges();
            Assert.Equal(model.LoginId, _context.Users.FirstOrDefault().LoginId);
            Assert.Equal(model.UserName, _context.Users.FirstOrDefault().UserName);
        }
Exemple #3
0
        public async Task Access_UserChangePassword_db()
        {
            var model   = UserModelTestData.UserModelData();
            var options = new DbContextOptionsBuilder <TestMakerContext>()
                          .UseInMemoryDatabase(databaseName: "Access_UserChangePassword_db")
                          .Options;

            using var _context = new TestMakerContext(options);
            _context.Users.Add(model);
            _context.SaveChanges();
            var user = await _context.Users.FindAsync(1);

            Assert.Equal(model.LoginId, user.LoginId);
            Assert.Equal(model.Password, user.Password);
        }
Exemple #4
0
        public async Task Access_UserDetails_db()
        {
            var model   = UserModelTestData.UserModelData();
            var options = new DbContextOptionsBuilder <TestMakerContext>()
                          .UseInMemoryDatabase(databaseName: "Access_UserDetails_db")
                          .Options;

            using var _context = new TestMakerContext(options);
            _context.Users.Add(model);
            _context.SaveChanges();
            var user = await _context.Users.FirstOrDefaultAsync(m => m.UserId == 1);

            Assert.Equal(model.UserId, user.UserId);
            Assert.Equal(model.LoginId, user.LoginId);
            Assert.Equal(model.UserName, user.UserName);
            Assert.Equal(model.Icon, user.Icon);
            Assert.Equal(model.SelfIntroduction, user.SelfIntroduction);
        }
Exemple #5
0
        public void Access_UserEdit_db()
        {
            var model   = UserModelTestData.UserModelData();
            var options = new DbContextOptionsBuilder <TestMakerContext>()
                          .UseInMemoryDatabase(databaseName: "Access_UserEdit_db")
                          .Options;

            using var _context = new TestMakerContext(options);
            _context.Users.Add(model);
            _context.SaveChanges();
            var user = _context.Users.Find(1);

            Assert.Equal(model.UserId, user.UserId);
            Assert.Equal(model.LoginId, user.LoginId);
            Assert.Equal(model.UserName, user.UserName);
            Assert.Equal(model.Password, user.Password);
            Assert.Equal(model.Salt, user.Salt);
            Assert.Equal(model.SelfIntroduction, user.SelfIntroduction);
            Assert.Equal(model.Icon, user.Icon);
        }
Exemple #6
0
        public void Access_UserDetails_check_whenIdNull_BeNotFound()
        {
            var model   = UserModelTestData.UserModelData();
            var options = new DbContextOptionsBuilder <TestMakerContext>()
                          .UseInMemoryDatabase(databaseName: "Access_UserDetails_check_whenIdNull_BeNotFound")
                          .Options;

            using var _context = new TestMakerContext(options);
            _context.Users.Add(model);
            _context.SaveChanges();
            IUserRepository userRepository = new UserRepository(_context);
            var             testMapper     = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new AutoMapperConfig());
            });
            var mapper       = testMapper.CreateMapper();
            var controller   = new UserController(userRepository, mapper);
            var actionResult = controller.Details(null);

            Assert.IsType <NotFoundResult>(actionResult);
        }
Exemple #7
0
        public void Access_UserDeleteConfirmed_Check_db()
        {
            var model   = UserModelTestData.UserModelData();
            var options = new DbContextOptionsBuilder <TestMakerContext>()
                          .UseInMemoryDatabase(databaseName: "Access_UserDeleteConfirmed_Check_db")
                          .Options;

            using var _context = new TestMakerContext(options);
            _context.Users.Add(model);
            _context.SaveChanges();
            Assert.Equal(1, _context.Users.Count());
            IUserRepository userRepository = new UserRepository(_context);
            var             testMapper     = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new AutoMapperConfig());
            });
            var mapper     = testMapper.CreateMapper();
            var controller = new UserController(userRepository, mapper);

            controller.DeleteConfirmed(1);
            Assert.Equal(0, _context.Users.Count());
        }
Exemple #8
0
        public void Access_UserDeleteConfirmed_check_RedirectToActionResult()
        {
            var model   = UserModelTestData.UserModelData();
            var options = new DbContextOptionsBuilder <TestMakerContext>()
                          .UseInMemoryDatabase(databaseName: "Access_UserDeleteConfirmed_check_RedirectToActionResult")
                          .Options;

            using var _context = new TestMakerContext(options);
            _context.Users.Add(model);
            _context.SaveChanges();
            IUserRepository userRepository = new UserRepository(_context);
            var             testMapper     = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new AutoMapperConfig());
            });
            var mapper       = testMapper.CreateMapper();
            var controller   = new UserController(userRepository, mapper);
            var actionResult = controller.DeleteConfirmed(1) as RedirectToActionResult;

            Assert.Equal("Index", actionResult.ActionName);
            Assert.Equal("Home", actionResult.ControllerName);
        }
Exemple #9
0
        public void Access_UserIndex_check_viewData()
        {
            var model   = UserModelTestData.UserModelData();
            var options = new DbContextOptionsBuilder <TestMakerContext>()
                          .UseInMemoryDatabase(databaseName: "Access_UserIndex_check_viewData")
                          .Options;

            using var _context = new TestMakerContext(options);
            _context.Users.Add(model);
            _context.SaveChanges();
            IUserRepository userRepository = new UserRepository(_context);
            var             testMapper     = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new AutoMapperConfig());
            });
            var mapper     = testMapper.CreateMapper();
            var controller = new UserController(userRepository, mapper);
            var view       = controller.Index() as ViewResult;

            Assert.Equal("Index", view.ViewData["Title"]);
            Assert.Equal("Index", view.ViewData["Action"]);
            Assert.Equal("User", view.ViewData["Controller"]);
        }