public void addFriendTest() { MockTokenService tokenService = new MockTokenService(); MockUserDataMapper mockMapper = new MockUserDataMapper(); IUserService _service = new UserService(tokenService, mockMapper); mockMapper.Users.Add(new User { id = 1, username = "******", email = "*****@*****.**", password = "******", fullName = "Janus Þór" }); mockMapper.Users.Add(new User { id = 2, username = "******", email = "*****@*****.**", password = "******", fullName = "Steinn" }); var authDTO = new FriendDTO { username = "******", email = "*****@*****.**", password = "******", fullName = "Janus Þór", accessToken = "1", friendUsername = "******" }; _service.addFriend(authDTO); Assert.Equal(1, mockMapper.Friends.Count()); }
public void deleteUserTest() { MockAccountDataMapper mapper = new MockAccountDataMapper(false); MockTokenService tokenService = new MockTokenService(); AccountService service = new AccountService(mapper, tokenService); AuthorizedUserDTO user = new AuthorizedUserDTO { username = "******" }; Exception ex = Assert.Throws <InvalidParametersException>(() => service.deleteUser(user)); AuthorizedUserDTO user2 = new AuthorizedUserDTO { username = "******", password = "******" }; Exception ex2 = Assert.Throws <AppObjectNotFoundException>(() => service.deleteUser(user2)); mapper = new MockAccountDataMapper(true); service = new AccountService(mapper, tokenService); AuthorizedUserDTO user3 = new AuthorizedUserDTO { username = "******", password = "******" }; Exception ex3 = Assert.Throws <AppValidationException>(() => service.deleteUser(user3)); AuthorizedUserDTO user4 = new AuthorizedUserDTO { username = "******", password = "******" }; service.deleteUser(user4); Assert.Equal(mapper.getDeleteCallCount(), 1); }
public void updateUsernameTest() { MockTokenService tokenService = new MockTokenService(); MockUserDataMapper mockMapper = new MockUserDataMapper(); IUserService _service = new UserService(tokenService, mockMapper); mockMapper.Users.Add(new User { id = 1, username = "******", email = "*****@*****.**", password = "******", fullName = "Janus Þór" }); _service.updateUsername(new UpdateUsernameDTO { username = "******", email = "*****@*****.**", password = "******", fullName = "Janus Þór", accessToken = tokenService.createUserToken(1, "janus"), newUsername = "******" }); Assert.Equal("test", mockMapper.Users.First().username); }
public void updatePasswordTest() { MockAccountDataMapper mapper = new MockAccountDataMapper(false); MockTokenService tokenService = new MockTokenService(); AccountService service = new AccountService(mapper, tokenService); UpdatePasswordDTO user = new UpdatePasswordDTO { newPassword = "******" }; Exception ex = Assert.Throws <InvalidParametersException>(() => service.updatePassword(user)); UpdatePasswordDTO user2 = new UpdatePasswordDTO { username = "******", newPassword = "******" }; Exception ex2 = Assert.Throws <AppObjectNotFoundException>(() => service.updatePassword(user2)); mapper = new MockAccountDataMapper(true); service = new AccountService(mapper, tokenService); UpdatePasswordDTO user3 = new UpdatePasswordDTO { username = "******", }; Exception ex3 = Assert.Throws <InvalidParametersException>(() => service.updatePassword(user3)); Assert.Equal(ex3.Message, "newPassword parameter can not be empty"); UpdatePasswordDTO user4 = new UpdatePasswordDTO { username = "******", newPassword = "******" }; service.updatePassword(user4); Assert.Equal(mapper.getUpdateCallCount(), 1); }
public void createUserSuccessTest() { MockAccountDataMapper mapper = new MockAccountDataMapper(false); MockTokenService tokenService = new MockTokenService(); AccountService service = new AccountService(mapper, tokenService); UserDTO user = new UserDTO { username = "******", email = "test", fullName = "test", password = "******" }; service.createUser(user); Assert.Equal(1, mapper.getCreateCallCount()); }
public void addFavouriteVideoTest() { MockTokenService tokenService = new MockTokenService(); MockUserDataMapper mockMapper = new MockUserDataMapper(); IUserService _service = new UserService(tokenService, mockMapper); mockMapper.Users.Add(new User { id = 1, username = "******", email = "*****@*****.**", password = "******", fullName = "Janus Þór" }); Video v = new Video { id = 1, title = "testing", source = "testing", creator = 1, channelId = 0 }; mockMapper.Videos.Add(v); var vDTO = new VideoDTO { id = 1, title = "testing", source = "testing", creator = 1, channelId = 0 }; var authDTO = new NewFavouriteVideoDTO { username = "******", email = "*****@*****.**", password = "******", fullName = "Janus Þór", accessToken = "1", videoId = vDTO.id }; _service.addFavouriteVideo(authDTO); Assert.Equal(1, mockMapper.Favourites.Count()); Assert.Equal(1, mockMapper.Favourites[0].userId); Assert.Equal(1, mockMapper.Favourites[0].videoId); }
public void getFriendsTest() { MockTokenService tokenService = new MockTokenService(); MockUserDataMapper mockMapper = new MockUserDataMapper(); IUserService _service = new UserService(tokenService, mockMapper); string name = "test"; string mailAddition = "@test.is"; string password = "******"; string fullname = "Test Testson The "; List <FriendDTO> DTOfriends = new List <FriendDTO>(); // Fill USER datalist and friendDTO datalist for (int i = 0; i < 8; i++) { User u = new User { id = i, username = name += i.ToString(), email = name += i.ToString() + mailAddition, password = password += i.ToString(), fullName = fullname += i.ToString() }; mockMapper.Users.Add(u); if (i > 0) { var authDTO = new FriendDTO { username = u.username, email = u.email, password = u.password, fullName = u.fullName, accessToken = "asd", friendUsername = mockMapper.Users[i - 1].username }; DTOfriends.Add(authDTO); } } foreach (FriendDTO friend in DTOfriends) { _service.addFriend(friend); } Assert.Equal(mockMapper.Friends.Count(), 7); }
public void authenticateUserTest() { MockAccountDataMapper mapper = new MockAccountDataMapper(false); MockTokenService tokenService = new MockTokenService(); AccountService service = new AccountService(mapper, tokenService); UserDTO user = new UserDTO { username = "******" }; Exception ex = Assert.Throws <InvalidParametersException>(() => service.authenticateUser(user)); UserDTO user2 = new UserDTO { username = "******", password = "******" }; Exception ex2 = Assert.Throws <AppObjectNotFoundException>(() => service.authenticateUser(user2)); Assert.Equal(mapper.getFindCallCount(), 1); mapper = new MockAccountDataMapper(true); service = new AccountService(mapper, tokenService); UserDTO user3 = new UserDTO { username = "******", password = "******" }; Exception ex3 = Assert.Throws <AppValidationException>(() => service.authenticateUser(user3)); UserDTO user4 = new UserDTO { username = "******", password = "******" }; AuthorizedUserDTO signedIn = service.authenticateUser(user4); Assert.Equal(signedIn.username, "test"); Assert.Equal(signedIn.accessToken, "test"); Assert.Equal(signedIn.fullName, "test"); }
public void createUserFailTest() { MockAccountDataMapper mapper = new MockAccountDataMapper(true); MockTokenService tokenService = new MockTokenService(); AccountService service = new AccountService(mapper, tokenService); UserDTO user = new UserDTO { username = "******", email = "test", fullName = "test" }; Exception ex = Assert.Throws <InvalidParametersException>(() => service.createUser(user)); user.email = ""; Exception ex2 = Assert.Throws <InvalidParametersException>(() => service.createUser(user)); UserDTO user2 = new UserDTO { username = "******", email = "test", fullName = "test", password = "******" }; Exception ex3 = Assert.Throws <DuplicateException>(() => service.createUser(user2)); }
public void getFavVidsTest() { MockTokenService tokenService = new MockTokenService(); MockUserDataMapper mockMapper = new MockUserDataMapper(); IUserService _service = new UserService(tokenService, mockMapper); mockMapper.Users.Add(new User { id = 1, username = "******", email = "*****@*****.**", password = "******", fullName = "Janus Þór" }); Video v1 = new Video { id = 1, title = "testing", source = "testing", creator = 1, channelId = 0 }; Video v2 = new Video { id = 2, title = "testing2", source = "testing2", creator = 1, channelId = 0 }; Video v3 = new Video { id = 3, title = "testing3", source = "testing3", creator = 1, channelId = 0 }; mockMapper.Videos.Add(v1); mockMapper.Videos.Add(v2); mockMapper.Videos.Add(v3); var vDTO1 = new VideoDTO { id = 1, title = "testing", source = "testing", creator = 1, channelId = 0 }; var vDTO2 = new VideoDTO { id = 2, title = "testing2", source = "testing2", creator = 1, channelId = 0 }; var vDTO3 = new VideoDTO { id = 3, title = "testing3", source = "testing3", creator = 1, channelId = 0 }; var authDTO = new NewFavouriteVideoDTO { username = "******", email = "*****@*****.**", password = "******", fullName = "Janus Þór", accessToken = "1", videoId = vDTO1.id }; _service.addFavouriteVideo(authDTO); authDTO.videoId += 1; _service.addFavouriteVideo(authDTO); authDTO.videoId += 1; _service.addFavouriteVideo(authDTO); List <VideoDTO> verifyData = (from v in mockMapper.Videos select new VideoDTO { id = v.id, title = v.title, source = v.source, creator = v.creator, channelId = v.channelId }).ToList(); List <VideoDTO> testData = _service.getFavouriteVideos(authDTO); Assert.Equal(mockMapper.Favourites.Count(), 3); Assert.Equal(verifyData.Count(), testData.Count()); for (int i = 0; i < 0; i++) { Assert.Equal(verifyData[i].id, testData[i].id); Assert.Equal(verifyData[i].title, testData[i].title); Assert.Equal(verifyData[i].source, testData[i].source); Assert.Equal(verifyData[i].creator, testData[i].creator); Assert.Equal(verifyData[i].channelId, testData[i].channelId); } }