예제 #1
0
        public void FaillingTestInsertUser()
        {
            var userAdmin = new User
            {
                UserName = "******",
                Role = "Admin",
                Enabled = false
            };
            //Action

            var chkInsert = userService.Insert(userAdmin);
            // Assert
            moqIDALContext.Verify(m => m.Users.Create(userAdmin), Times.Never());
            moqIDALContext.Verify(m => m.SaveChanges(), Times.Never());
            Assert.Equal(false, chkInsert);
        }
예제 #2
0
        public void TestInsertUserSuccessfull()
        {
            var userAdmin = new User
            {
                UserName = "******",
                Role = "Admin",
                Enabled = true
            };
            //Action
            var chkInsert = userService.Insert(userAdmin);
            // Assert
            moqIDALContext.Verify(m => m.Users.Create(userAdmin), Times.Exactly(1));
            moqIDALContext.Verify(m => m.SaveChanges(), Times.Exactly(1));

            // Statebased testing
            Assert.Equal(true, chkInsert);
        }
예제 #3
0
 /// <summary>
 /// Return 1: New User has succeeded to register.
 /// Return 0: Has exception
 /// Return 2: UserName or Email is already in system.
 /// </summary>
 /// z
 /// <param name="user"></param>
 /// <returns></returns>
 public int Register(User user)
 {
     if (CheckUser(user))
     {
         try
         {
             context.Users.Create(user);
             context.SaveChanges();
             return 0;
         }
         catch (Exception exception)
         {
             _logService.LogError("Function Register: {0}", exception);
             return 2;
         }
     }
     return 1;
 }
예제 #4
0
        public TestBussiness()
        {
            user = new User
            {
                UserName = "******",
                Role = "Tester",
                Enabled = true
            };

            var users = new List<User>
            {
                new User{UserId = 1, UserName = "******", Role = "Description",Enabled = true},
                new User{UserId = 2, UserName = "******", Role = "PM",Enabled = true},
                new User{UserId = 3, UserName = "******", Role = "QA",Enabled = true},
            };

            // Setup
            moqIDALContext = new Mock<IDALContext>();
            //moqIDALContext.Setup(db => db.Users).Verifiable();
            // Assert
            _IDALContext = moqIDALContext.Object;
            userService = new UserService(_IDALContext);
        }
예제 #5
0
        public void SetUp()
        {
            user = new User
            {
                UserName = "******",
                Role = "Tester",
                Enabled = true
            };

            List<User> users = new List<User>
            {
                new User{UserId = 1, UserName = "******", Role = "Description",Enabled = true},
                new User{UserId = 2, UserName = "******", Role = "PM",Enabled = true},
                new User{UserId = 3, UserName = "******", Role = "QA",Enabled = true},
            };

            moqService = new Mock<IUserService>();

            moqService.Setup(mUserS => mUserS.GetAll()).Returns(users);
            moqService.Setup(mUserS => mUserS.Insert(user)).Returns(true);
            logService = new FileLogManager(typeof(HomeController));

            userService = moqService.Object;
        }
예제 #6
0
 public ActionResult Insert(User objUser)
 {
     return null;
 }
예제 #7
0
 public User Update(User user)
 {
     context.Users.Update(user);
     context.SaveChanges();
     return user;
 }
예제 #8
0
 public bool Delete(User user)
 {
     context.Users.Delete(user);
     context.SaveChanges();
     return true;
 }
예제 #9
0
 public bool CheckUser(User user)
 {
     if (user == null) return false;
     var check = context.Users.All().FirstOrDefault(x => x.UserName == user.UserName || x.Email == user.Email);
     return check != null;
 }