示例#1
0
 public void LoginUser_WhenUserLoginModelIsNull_ShouldShouldThrowException()
 {
     UserService userService = new UserService(mock.Object);
     string nickname;
     userService.LoginUser(null, out nickname);
 }
示例#2
0
        public void LoginUser_WhenUserLoginModelIsValid_ShouldReturnSessionKeyAndNickname()
        {
            User updatedUser = new User();
            UserLoginModel loginModel = new UserLoginModel()
            {
                AuthCode = "80a63648010756ed51eecccf94c01bc0015048c5",
                Username = "******",
                ConnectionId = "newConnectionId"
            };
            UserService userService = new UserService(mock.Object);
            mock.Setup(g => g.Users.GetAll()).Returns(new User[]
            {
                new User
                {
                    Username = "******",
                    Nickname = "nickname",
                    ConnectionId = "75ccd4c3-fd0f-4a1d-80bb-885fb1bb5296",
                    SessionKey = "100431CZhiZTwwJAh8VTo559HfIyYf8lXyq74Bi2UkBP64ZoLL",
                    AuthCode = "80a63648010756ed51eecccf94c01bc0015048c5"
                },
            }.AsQueryable());
            mock.Setup(u => u.Users.Update(It.IsAny<User>())).Callback((User user) => updatedUser = user);

            string nickname;
            string sessionKey = userService.LoginUser(loginModel, out nickname);
            Assert.AreEqual("nickname",nickname);
            Assert.IsNotNull(sessionKey);
            Assert.AreEqual(loginModel.ConnectionId, updatedUser.ConnectionId);
        }
示例#3
0
        public void LoginUser_WhenAuthCodeIsNotMatch_ShouldThrowException()
        {
            mock.Setup(g => g.Users.GetAll()).Returns(new User[]
            {
                new User
                {
                    Username = "******",
                    Nickname = "nickname",
                    ConnectionId = "75ccd4c3-fd0f-4a1d-80bb-885fb1bb5296",
                    SessionKey = "100431CZhiZTwwJAh8VTo559HfIyYf8lXyq74Bi2UkBP64ZoLL",
                    AuthCode = "80a63648010756ed51eecccf94c01bc0015048c5"
                },
            }.AsQueryable());
            UserLoginModel loginModel = new UserLoginModel()
            {
                AuthCode = "11111648010756ed51eecccf94c01bc0015048c5",
                Username = "******",
                ConnectionId = "newConnectionId"
            };

            UserService userService = new UserService(mock.Object);
            string nickname;
            userService.LoginUser(loginModel, out nickname);
        }
示例#4
0
 public void LoginUserBySeesionKey_WhenSessionKeyIsValindButNoUserWithHim_ShouldThrowException()
 {
     mock.Setup(g => g.Users.GetAll()).Returns(new User[]
     {
         new User
         {
             Username = "******",
             Nickname = "nickname",
             ConnectionId = "75ccd4c3-fd0f-4a1d-80bb-885fb1bb5296",
             SessionKey = "100431CZhiZTwwJAh8VTo559HfIyYf8lXyq74Bi2UkBP64ZoLL",
             AuthCode = "80a63648010756ed51eecccf94c01bc0015048c5"
         },
     }.AsQueryable());
     UserService userService = new UserService(mock.Object);
     userService.LoginUser("888431CZhiZTwwJAh8VTo559HfIyYf8lXyq74Bi2UkBP64ZoLL");
 }
示例#5
0
 public void LoginUserBySeesionKey_WhenSessionKeyIsNull_ShouldThrowException()
 {
     UserService userService = new UserService(mock.Object);
     userService.LoginUser(null);
 }
示例#6
0
 public void LoginUserBySeesionKey_WhenSessionKeyIsInvalid_ShouldThrowException()
 {
     UserService userService = new UserService(mock.Object);
     userService.LoginUser("InvalidSessionKey");
 }
示例#7
0
 public void LoginUserBySeesionKey_WhenCompletedLogin_ShouldReturnId()
 {
     mock.Setup(g => g.Users.GetAll()).Returns(new User[]
     {
         new User
         {
             Id = 1,
             Username = "******",
             Nickname = "nickname",
             ConnectionId = "75ccd4c3-fd0f-4a1d-80bb-885fb1bb5296",
             SessionKey = "100431CZhiZTwwJAh8VTo559HfIyYf8lXyq74Bi2UkBP64ZoLL",
             AuthCode = "80a63648010756ed51eecccf94c01bc0015048c5"
         },
     }.AsQueryable());
     UserService userService = new UserService(mock.Object);
     int id = userService.LoginUser("100431CZhiZTwwJAh8VTo559HfIyYf8lXyq74Bi2UkBP64ZoLL");
     Assert.AreEqual( 1,id);
 }