コード例 #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;
 }