Exemplo n.º 1
0
 public void CreateUser_WhenNicknameAlreadyExists_ShouldThrowException()
 {
     User[] users = new User[]
     {
         new User { Username = "******", Nickname = "nickname" },
         new User { Username = "******", Nickname = "otherNickName" },
     };
     UserRegisterModel userModel = new UserRegisterModel()
     {
         Username = "******",
         Nickname = "nickname",
         AuthCode = "80a63648010756ed51eecccf94c01bc0015048c5",
         ConnectionId = "75ccd4c3-fd0f-4a1d-80bb-885fb1bb5296",
     };
     mock.Setup(m => m.Users.GetAll()).Returns(users.AsQueryable());
     UserService userService = new UserService(mock.Object);
     userService.CreateUser(userModel);
 }
Exemplo n.º 2
0
        public void CreateUser_WhenModelIsValid_ShouldAddToRepository()
        {
            List<User> users = new List<User>();
            users.Add(new User { Username = "******", Nickname = "nickname" });
            users.Add(new User { Username = "******", Nickname = "otherNickName" });

            UserRegisterModel userModel = new UserRegisterModel()
            {
                Username = "******",
                Nickname = "kaluhckua",
                AuthCode = "80a63648010756ed51eecccf94c01bc0015048c5",
                ConnectionId = "75ccd4c3-fd0f-4a1d-80bb-885fb1bb5296",
            };
            mock.Setup(m => m.Users.GetAll()).Returns(users.AsQueryable());
            mock.Setup(m => m.Users.Add(It.IsAny<User>())).Callback((User user) => users.Add(user));
            UserService userService = new UserService(mock.Object);
            userService.CreateUser(userModel);
            Assert.AreEqual(userModel.AuthCode, users[2].AuthCode);
            Assert.AreEqual(userModel.Nickname, users[2].Nickname);
            Assert.AreEqual(userModel.Username, users[2].Username);
            Assert.AreEqual(userModel.ConnectionId, users[2].ConnectionId);
        }
Exemplo n.º 3
0
 public void CreateUser_WhenUserRegisterModelIsNull_ShouldShouldThrowException()
 {
     UserService userService = new UserService(mock.Object);
     string nickname;
     userService.CreateUser(null);
 }
Exemplo n.º 4
0
 public void SaveConnectionId_WhenSessionKeyIsInvalid_ShouldThrowException()
 {
     UserService userService = new UserService(mock.Object);
     userService.SaveConnectionId("InvalidSessionKey", "1234");
 }
Exemplo n.º 5
0
 public void SaveConnectionId_WhenDataIsValid_ShouldUpdataConnectionId()
 {
     Mock<IUowData> mock = new Mock<IUowData>();
     User updatedUser = new User();
     UserService userService = new UserService(mock.Object);
     mock.Setup(g => g.Users.GetAll()).Returns(new User[]
     {
         new User { SessionKey = "100431CZhiZTwwJAh8VTo559HfIyYf8lXyq74Bi2UkBP64ZoLL" },
     }.AsQueryable());
     mock.Setup(u => u.Users.Update(It.IsAny<User>())).Callback((User user) => updatedUser = user);
     userService.SaveConnectionId("100431CZhiZTwwJAh8VTo559HfIyYf8lXyq74Bi2UkBP64ZoLL", "1234");
     Assert.AreEqual("1234",updatedUser.ConnectionId );
 }
Exemplo n.º 6
0
 public void SaveConnectionId_WhenConnectionIdIsNull_ShouldThrowException()
 {
     UserService userService = new UserService(mock.Object);
     userService.SaveConnectionId("100431CZhiZTwwJAh8VTo559HfIyYf8lXyq74Bi2UkBP64ZoLL", null);
 }
Exemplo n.º 7
0
 public void LogoutUser_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.LogoutUser("888431CZhiZTwwJAh8VTo559HfIyYf8lXyq74Bi2UkBP64ZoLL");
 }
Exemplo n.º 8
0
 public void LogoutUser_WhenSessionKeyIsNull_ShouldThrowException()
 {
     UserService userService = new UserService(mock.Object);
     userService.LogoutUser(null);
 }
Exemplo n.º 9
0
 public void LogoutUser_WhenSessionKeyIsInvalid_ShouldThrowException()
 {
     UserService userService = new UserService(mock.Object);
     userService.LogoutUser("InvalidSesionKey");
 }
Exemplo n.º 10
0
 public void LogoutUser_WhenCompletedLogin_ShouldSetSessinKeyToNull()
 {
     User updatedUser = new User();
     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());
     mock.Setup(g => g.Users.Update(It.IsAny<User>())).Callback((User user) => updatedUser = user);
     UserService userService = new UserService(mock.Object);
     userService.LogoutUser("100431CZhiZTwwJAh8VTo559HfIyYf8lXyq74Bi2UkBP64ZoLL");
     Assert.IsNull(updatedUser.SessionKey);
 }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
 public void LoginUser_WhenUserLoginModelIsNull_ShouldShouldThrowException()
 {
     UserService userService = new UserService(mock.Object);
     string nickname;
     userService.LoginUser(null, out nickname);
 }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
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);
 }
Exemplo n.º 15
0
 public void GetAllUsers_WhenHasTwoUsersInRepository_ShouldReturnTwoUsers()
 {
     mock.Setup(g => g.Users.GetAll()).Returns(new User[]
     {
         new User
         {
             Id=1,
         },
           new User
         {
             Id=2,
         },
     }.AsQueryable());
     UserService userService = new UserService(mock.Object);
     IEnumerable<User> users = userService.GetAllUsers();
     Assert.AreEqual(2, users.Count());
 }