public static async Task <WordSetReply> GetWordSets(this InWordsDataContext context, int offset = 0, int limit = 50) { if (context == null) { throw new ArgumentNullException(nameof(context)); } WordSetReply reply = new WordSetReply(); var games = (from tags in context.GameTags.Where(d => d.Tags == GameTags.Official) join game in context.Games on tags.GameId equals game.GameId select game).Skip(offset).Take(limit); var include = await games.Include(d => d.CreationDescriptions) .ToArrayAsync() .ConfigureAwait(false); var wordsSets = include.Select(g => { var description = g.CreationDescriptions.Single(d => d.LanguageId == 2); return(new WordSetInfo() { Id = g.GameId, Picture = g.Picture, Title = description.Title, Description = description.Description }); }); reply.WordSets.AddRange(wordsSets); return(reply); }
public static IQueryable <int> WordsInGame(this InWordsDataContext context, int id) { IQueryable <GameLevel> levelsQueryable = context.GameLevels.Levels(id); IQueryable <GameLevelWord> levelWordsQueryable = context.GameLevelWords.Words(levelsQueryable); return(levelWordsQueryable.AsNoTracking().Select(w => w.WordPairId).Distinct()); }
public async void GetUserWords() { // arrange int userId = 1; int otherId = 2; using InWordsDataContext context = InWordsDataContextFactory.Create(); await context.AddAccount(userId); await context.AddAccount(otherId); await context.SaveChangesAsync(); context.Add(CreateUserWordPair(userId, "0", "0-0")); context.Add(CreateUserWordPair(userId, "1", "1-1")); context.Add(CreateUserWordPair(userId, "3", "3-3")); context.Add(CreateUserWordPair(otherId, "2", "2-2")); await context.SaveChangesAsync(); // act var service = new GetUserWords(context); var requestData = new GetWordsRequest(); var request = new AuthorizedRequestObject <GetWordsRequest, WordsReply>(requestData) { UserId = userId }; var reply = await service.HandleRequest(request, default); // assert Assert.Equal(context.UserWordPairs.Where(d => d.UserId == userId).Count(), reply.ToAdd.Count()); Assert.Empty(reply.ToDelete); }
public async void RequestContainsExistedWords() { // arrange int userId = 1; int otherId = 2; using InWordsDataContext context = InWordsDataContextFactory.Create(); await context.AddAccount(userId); await context.AddAccount(otherId); await context.SaveChangesAsync(); context.Add(CreateUserWordPair(userId, "0", "0-0", 1)); context.Add(CreateUserWordPair(userId, "1", "1-1", 2)); context.Add(CreateUserWordPair(otherId, "2", "2-2", 3)); context.Add(CreateUserWordPair(userId, "3", "3-3", 4)); await context.SaveChangesAsync(); // act var service = new GetUserWords(context); var requestData = new GetWordsRequest(); requestData.UserWordpairIds.Add(new int[] { 1, 2, 99, 100 }); var request = new AuthorizedRequestObject <GetWordsRequest, WordsReply>(requestData) { UserId = userId }; var reply = await service.HandleRequest(request, default); // assert Assert.Equal(4, reply.ToAdd[0].UserWordPair); Assert.Equal(new int[] { 99, 100 }, reply.ToDelete.ToArray()); }
public async void HandleWords() { await using InWordsDataContext context = InWordsDataContextFactory.Create(); var creation = new Game { GameId = 1 }; context.Games.Add(creation); context.GameLevels.Add(new GameLevel { GameLevelId = 1, GameId = 1 }); context.GameLevels.Add(new GameLevel { GameLevelId = 2, GameId = 1 }); context.GameLevelWords.Add(new GameLevelWord { GameLevelId = 1, GameLevelWordId = 1, WordPairId = 1 }); context.GameLevelWords.Add(new GameLevelWord { GameLevelId = 2, GameLevelWordId = 2, WordPairId = 1 }); context.GameLevelWords.Add(new GameLevelWord { GameLevelId = 2, GameLevelWordId = 3, WordPairId = 2 }); context.SaveChanges(); var words = new WordsIdsByGameIdHandler(context); WordsIdsByGameIdQueryResult test = await words.Handle(new WordsIdsByGameQuery { Id = 1 }) .ConfigureAwait(false); Assert.Equal(2, test.WordTranslationsList.Count); }
public LevelCreator(InWordsDataContext context) { userWordPairRepository = new UserWordPairRepository(context); creationRepository = new CreationRepository(context); gameLevelRepository = new GameLevelRepository(context); gameLevelWordRepository = new GameLevelWordRepository(context); }
/// <summary> /// GetOrAdd history usergame and save levels in game levels. Return levels ids. /// </summary> /// <param name="context">database context</param> /// <param name="userId">auhtorized user identity</param> /// <param name="levelsWords">words id array in list of levels</param> /// <returns>Levels ids</returns> public static async Task <int[]> CreateLevels(this InWordsDataContext context, int userId, IList <int[]> levelsWords) { var historyGameId = await context.AddOrGetUserHistoryGame(userId).ConfigureAwait(false); var levels = await context.CreateLevels(historyGameId, userId, levelsWords).ConfigureAwait(false); return(levels); }
public static async Task <int> AddOrGetUserHistoryGame(this InWordsDataContext context, int userId) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var historyGame = (from game in context.Games.Where(d => d.CreatorId == userId) join tag in context.GameTags.Where(d => d.Tags == GameTags.CustomLevelsHistory) on game.GameId equals tag.GameId select game).OrderBy(g => g.GameId).ToArray(); int historyGameId = 0; if (historyGame.Any()) { historyGameId = historyGame[0].GameId; if (historyGame.Length > 1) { var historyCollisions = historyGame.Skip(1); int[] ids = historyCollisions.Select(d => d.GameId).ToArray(); var levels = context.GameLevels.Where(g => ids.Contains(g.GameId)); levels.ForEach(level => { level.GameId = historyGameId; }); await context.SaveChangesAsync().ConfigureAwait(false); context.Remove(historyCollisions); await context.SaveChangesAsync().ConfigureAwait(false); } } else { Game game = new Game { CreatorId = userId }; context.Add(game); await context.SaveChangesAsync().ConfigureAwait(false); GameTag historyGameTag = new GameTag() { GameId = game.GameId, Tags = GameTags.CustomLevelsHistory, UserId = userId }; context.Add(historyGameTag); await context.SaveChangesAsync().ConfigureAwait(false); historyGameId = game.GameId; } return(historyGameId); }
public async void CreateHistoryGame() { using InWordsDataContext context = InWordsDataContextFactory.Create(); { context.WordPairs.Add(new WordPair() { WordPairId = 2 }); context.WordPairs.Add(new WordPair() { WordPairId = 3 }); context.WordPairs.Add(new WordPair() { WordPairId = 4 }); context.UserWordPairs.Add(new UserWordPair() { UserWordPairId = 1, WordPairId = 2, UserId = 1 }); context.UserWordPairs.Add(new UserWordPair() { UserWordPairId = 3, WordPairId = 3, UserId = 1 }); context.UserWordPairs.Add(new UserWordPair() { UserWordPairId = 4, WordPairId = 4, UserId = 1 }); ClassicCardLevelMetricQuery request = new ClassicCardLevelMetricQuery() { UserId = 1, Metrics = new List <ClassicCardLevelMetric>() { new ClassicCardLevelMetric() { GameLevelId = 0, WordPairIdOpenCounts = new Dictionary <int, int>() { { 1, 4 }, { 3, 4 }, { 4, 1 } } } }.ToImmutableArray() }; await context.SaveChangesAsync().ConfigureAwait(false); ClassicCardLevelMetricQueryResult result = await new SaveLevelMetric(context) .Handle(request) .ConfigureAwait(false); } var userGameLevel = context.UserGameLevels.First(u => u.UserId.Equals(1)); Assert.Equal(3, userGameLevel.UserStars); }
public static IQueryable <UserWordPair> CurrentUserWordPairs(this InWordsDataContext context, int userid) { if (context == null) { throw new ArgumentNullException(nameof(context)); } return(context.UserWordPairs.Where(u => u.UserId == userid)); }
public async void GetOfficialSets_ShouldBeOk() { // arrange string picture = "testPicture"; string description = "testdes"; string title = "testtitle"; Language language = new Language() { LanguageId = 2, Title = "ru" }; await using InWordsDataContext context = InWordsDataContextFactory.Create(); Game game = new Game() { Picture = picture }; context.Add(language); context.Add(game); await context.SaveChangesAsync(); CreationDescription creationDescription = new CreationDescription() { CreationId = game.GameId, Description = description, LanguageId = 2, Title = title, }; context.Add(creationDescription); GameTag gameTag = new GameTag() { GameId = game.GameId, Tags = GameTags.Official }; context.Add(gameTag); context.SaveChanges(); // act Empty empty = new Empty(); var request = new AuthReq <Empty, WordSetReply>(empty) { UserId = 0 }; var reply = await new GetWordSetsHandler(context).Handle(request); // assert Assert.Single(reply.WordSets); Assert.Equal(description, reply.WordSets[0].Description); Assert.Equal(title, reply.WordSets[0].Title); Assert.Equal(picture, reply.WordSets[0].Picture); }
public async void GetLevelWords() { // arrange int userId = 1; await using InWordsDataContext context = InWordsDataContextFactory.Create(); Game game = new Game() { }; context.Add(game); await context.SaveChangesAsync(); GameLevel gameLevel = new GameLevel() { GameId = game.GameId }; context.Add(gameLevel); await context.SaveChangesAsync(); List <GameLevelWord> gameLevelWords = new List <GameLevelWord> { new GameLevelWord() { GameLevelId = gameLevel.GameLevelId, ForeignWord = "test1", NativeWord = "тест1" }, new GameLevelWord() { GameLevelId = gameLevel.GameLevelId, ForeignWord = "test2", NativeWord = "тест2" }, }; context.GameLevelWords.AddRange(gameLevelWords); await context.SaveChangesAsync(); await context.AddAccount(userId); await context.SaveChangesAsync(); // act var data = new GetLevelWordsRequest() { LevelId = gameLevel.GameLevelId }; var request = new AuthReq <GetLevelWordsRequest, GetLevelWordsReply>(data) { UserId = userId }; GetLevelWordsReply result = await new GetLevelWords(context).HandleRequest(request); // assert Assert.Equal(2, result.Words.Count); }
public async void DeleteUserWordPairs_ShouldBeOk() { // arrange int userId = 1; int otherId = 2; await using InWordsDataContext context = InWordsDataContextFactory.Create(); await context.AddAccount(userId); await context.AddAccount(otherId); await context.SaveChangesAsync(); context.Add(new UserWordPair() { UserWordPairId = 1, ForeignWord = "Test1", NativeWord = "Тест1", UserId = userId });; context.Add(new UserWordPair() { UserWordPairId = 2, ForeignWord = "Test2", NativeWord = "Тест2", UserId = userId }); context.Add(new UserWordPair() { UserWordPairId = 3, ForeignWord = "Test3", NativeWord = "Тест3", UserId = userId }); await context.SaveChangesAsync(); DeleteWordsRequest deletewordsRequets = new DeleteWordsRequest(); deletewordsRequets.Delete.AddRange(new int[] { 1, 3 }); // act var requestObject = new AuthReq <DeleteWordsRequest, Empty>(deletewordsRequets) { UserId = userId }; var deleteWords = new DeleteWords(context); Empty response = await deleteWords.HandleRequest(requestObject).ConfigureAwait(false); // assert Assert.Equal(1, context.UserWordPairs.Count()); Assert.Equal("Тест2", context.UserWordPairs.First().NativeWord); }
public static async Task <Account> AddAccount(this InWordsDataContext context, int id = 0) { if (id == 0) { id = await context.Accounts.MaxAsync(d => d.AccountId) + 1; } Account account = new Account { AccountId = id, Email = $"test{id}@test.ru", RegistrationDate = default,
public static async Task <int[]> CreateLevels(this InWordsDataContext context, int gameId, int userId, IList <int[]> pairsInLevels) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (pairsInLevels == null) { pairsInLevels = Array.Empty <int[]>(); } // create levles var levels = pairsInLevels.Select(d => { var game = new GameLevel() { GameId = gameId }; game.Historylevel = new Historylevel() { DateTime = DateTime.UtcNow, WordsCount = d.Distinct().Count(), GameLevel = game }; context.Add(game); return(game); }).ToArray(); await context.SaveChangesAsync().ConfigureAwait(false); // fill levels with words for (int i = 0; i < pairsInLevels.Count; i++) { var currentLevel = levels[i]; int[] currentWordsIds = pairsInLevels[i].ToArray(); var currentWords = context.CurrentUserWordPairs(userId) .Where(u => currentWordsIds.Contains(u.UserWordPairId)) .ToArray(); var gameLevelWords = currentWords.Select(w => new GameLevelWord() { ForeignWord = w.ForeignWord, NativeWord = w.NativeWord, GameLevelId = currentLevel.GameLevelId, }).ToArray(); context.GameLevelWords.AddRange(gameLevelWords); } await context.SaveChangesAsync().ConfigureAwait(false); return(levels.Select(level => level.GameLevelId).ToArray()); }
public async void EstimateTraining_Returns6Stars() { // arrange int userId = 1; using InWordsDataContext context = InWordsDataContextFactory.Create(); Game game = new Game() { }; context.Add(game); context.SaveChanges(); GameLevel gameLevel = new GameLevel() { GameId = game.GameId }; context.Add(gameLevel); context.SaveChanges(); await context.AddAccount(userId); await context.SaveChangesAsync(); // act TrainingDataRequest trainingDataRequest = new TrainingDataRequest(); Training training = new Training { }; training.ClosedCardsMetric = new ClosedCardsMetric(); training.ClosedCardsMetric.WordIdOpenCount.Add(1, 4); training.ClosedCardsMetric.WordIdOpenCount.Add(2, 4); training.ClosedCardsMetric.WordIdOpenCount.Add(3, 2); training.OpenedCardsMetric = new OpenedCardsMetric(); training.OpenedCardsMetric.WordIdOpenCount.Add(1, 3); training.OpenedCardsMetric.WordIdOpenCount.Add(2, 2); training.OpenedCardsMetric.WordIdOpenCount.Add(3, 2); trainingDataRequest.Metrics.Add(training); var requestData = new AuthReq <TrainingDataRequest, TrainingScoreReply>(trainingDataRequest) { UserId = userId }; var requestHandler = new EstimateTraining(context); var result = await requestHandler.HandleRequest(requestData); // assert Assert.Single(result.Scores); Assert.Equal(6, result.Scores.Single().ClosedCards.Score); Assert.Equal(5, result.Scores.Single().OpenedCards.Score); Assert.Equal(6, result.Scores.Single().Score); }
public async Task Get_History_Levels() { // prepare var userId = 1; using InWordsDataContext context = InWordsDataContextFactory.Create(); var creation1 = new Game { CreatorId = userId, GameId = 1 }; var creation2 = new Game { CreatorId = userId + 2, GameId = 2 }; // != user context.Games.Add(creation1); context.Games.Add(creation2); context.GameTags.Add(new GameTag() { Tags = GameTags.CustomLevelsHistory, GameId = 1, UserId = userId }); creation1.GameLevels.Add(new GameLevel() { Game = creation1, }); creation1.GameLevels.Add(new GameLevel() { Game = creation1 }); creation2.GameLevels.Add(new GameLevel() { Game = creation2 }); creation2.GameLevels.Add(new GameLevel() { Game = creation2 }); context.SaveChanges(); // action var words = new GetTrainingLevelsHistory(context); var test = await words.Handle((new AuthReq <Empty, GameScoreReply>(new Empty()) { UserId = userId })) .ConfigureAwait(false); // assert Assert.Equal(2, test.Levels.Count); }
public async void HandleWords() { // prepare var userId = 2; await using InWordsDataContext context = InWordsDataContextFactory.Create(); var creation2 = new Game { CreatorId = userId + 1 }; // != user var creation1 = new Game { CreatorId = userId, GameId = 2 }; context.Games.Add(creation1); context.Games.Add(creation2); context.GameTags.Add(new GameTag() { Tags = GameTags.CustomLevelsHistory, GameId = 2, UserId = userId }); creation1.GameLevels.Add(new GameLevel() { Game = creation1 }); creation1.GameLevels.Add(new GameLevel() { Game = creation1 }); creation2.GameLevels.Add(new GameLevel() { Game = creation2 }); creation2.GameLevels.Add(new GameLevel() { Game = creation2 }); context.SaveChanges(); // action var words = new GetUserGameStoryHandler(context); var test = await words.Handle(new GetUserGameStoryQuery() { UserId = userId }) .ConfigureAwait(false); // assert Assert.Equal(2, test.Count); }
private static void CreateGame(HashSet <GameLevelWord> words, InWordsDataContext context) { HashSet <GameLevel> gameLevels1 = new HashSet <GameLevel> { new GameLevel() { GameLevelWords = words, } }; context.Games.Add(new Game() { CreatorId = 0, GameLevels = gameLevels1 }); }
private async void AddFakeUser(InWordsDataContext context) { context.Accounts.Add(new Account() { AccountId = 1, Email = email, Hash = new byte[255], Role = role }); context.Users.Add(new User() { UserId = 1, NickName = nickname }); await context.SaveChangesAsync(); }
public async void HandleWords() { var userId = 1; await using InWordsDataContext context = InWordsDataContextFactory.Create(); var pair = new WordPair() { WordForeign = new Word(), WordNative = new Word() }; context.UserWordPairs.Add(new UserWordPair() { UserId = userId + 1, TimeGap = DateTime.UtcNow.AddDays(-5), WordPair = pair }); context.UserWordPairs.Add(new UserWordPair() { UserId = userId, TimeGap = DateTime.UtcNow.AddDays(-5), WordPair = pair }); context.UserWordPairs.Add(new UserWordPair() { UserId = userId, TimeGap = DateTime.UtcNow.AddDays(-1), WordPair = pair }); context.UserWordPairs.Add(new UserWordPair() { UserId = userId, TimeGap = DateTime.UtcNow.AddDays(1), WordPair = pair }); context.UserWordPairs.Add(new UserWordPair() { UserId = userId, TimeGap = DateTime.UtcNow.AddDays(2), WordPair = pair }); context.UserWordPairs.Add(new UserWordPair() { UserId = userId, TimeGap = DateTime.UtcNow.AddDays(3), WordPair = pair }); context.UserWordPairs.Add(new UserWordPair() { UserId = userId + 1, TimeGap = DateTime.UtcNow.AddDays(3), WordPair = pair }); context.SaveChanges(); var words = new GetLearningUserWordsId(context); var test = await words.Handle(new GetLearningUserWordsIdQuery(userId)).ConfigureAwait(false); Assert.Equal(3, test.Count()); }
public async void HistoryLevelHistoryGameExistWordsExists() { const int userId = 1; // initialise await using InWordsDataContext context = InWordsDataContextFactory.Create(); CreateContextWithExistedGame(context, userId); await context.SaveChangesAsync().ConfigureAwait(false); var testQuery = new CustomLevelMetricQuery() { UserId = userId, Metrics = new List <ClassicCardLevelMetric>() { new ClassicCardLevelMetric() { GameLevelId = 0, WordPairIdOpenCounts = new Dictionary <int, int>() { { 1, 4 }, { 2, 5 }, { 3, 1 } } } }.ToImmutableArray() }; // act var handler = new CreateHistoryLevelsRequest(context); CustomLevelMetricQuery actualResult = await handler.Handle(testQuery).ConfigureAwait(false); // assert var expectedLevels = 1; List <GameLevel> actualLevels = context.GameLevels.Where(g => g.GameId.Equals(1)).ToList(); Assert.Equal(expectedLevels, actualLevels.Count); var expectedLevelWords = 3; var actualLevelWords = context.GameLevelWords .Where(d => actualLevels.Contains(d.GameLevel)); Assert.Equal(expectedLevelWords, actualLevelWords.Count()); Assert.Equal(4, actualResult.Metrics[0].WordPairIdOpenCounts[2]); context.Dispose(); }
public async void TrainingIds_Ok() { // arrange int userId = 1; int otherId = 2; await using InWordsDataContext context = InWordsDataContextFactory.Create(); await context.AddAccount(userId); await context.AddAccount(otherId); await context.SaveChangesAsync(); var time = DateTime.UtcNow; context.UserWordPairs.Add(new UserWordPair() { UserWordPairId = 1, UserId = userId, NativeWord = "1", ForeignWord = "1", Background = false, TimeGap = time }); context.UserWordPairs.Add(new UserWordPair() { UserWordPairId = 2, UserId = userId, NativeWord = "2", ForeignWord = "2", Background = false, TimeGap = time.AddDays(1) }); context.UserWordPairs.Add(new UserWordPair() { UserWordPairId = 3, UserId = userId, NativeWord = "2", ForeignWord = "2", Background = false, TimeGap = time.AddDays(2) }); context.UserWordPairs.Add(new UserWordPair() { UserWordPairId = 4, UserId = otherId, NativeWord = "3", ForeignWord = "3", Background = false, TimeGap = time }); context.SaveChanges(); // act var requestObject = new AuthReq <Empty, TrainingIdsReply>(new Empty()) { UserId = userId }; var addWords = new GetTrainingIds(context); TrainingIdsReply response = await addWords.HandleRequest(requestObject).ConfigureAwait(false); // assert Assert.Equal(2, response.UserWordPairs.Count); Assert.Contains(1, response.UserWordPairs); Assert.Contains(2, response.UserWordPairs); }
public async void ResendEmailIfUnverfed() { string testEmail = "*****@*****.**"; // arrange await using InWordsDataContext context = InWordsDataContextFactory.Create(); Account account = new Account() { Email = testEmail, Hash = new byte[255], Role = RoleType.Unverified }; User User = new User() { Account = account, NickName = "user" }; await context.SaveChangesAsync(); var mock = new Mock <IEmailTemplateSender>(); mock.Setup(a => a.SendMailAsync(testEmail, It.IsAny <EmailTemplateBase>())); // act var registration = new ChangeEmail(context, mock.Object); var requestObject = new AuthorizedRequestObject <EmailChangeRequest, EmailChangeReply>( new EmailChangeRequest() { Email = testEmail, }) { UserId = account.AccountId }; var test = await registration.HandleRequest( new AuthorizedRequestObject <EmailChangeRequest, EmailChangeReply>( new EmailChangeRequest() { Email = testEmail, })) .ConfigureAwait(false); // assert Assert.Equal(1, context.EmailVerifies.Count()); mock.Verify(a => a.SendMailAsync(testEmail, It.IsAny <EmailTemplateBase>()), Times.Once()); }
public async void RegisterExistedEmail() { string email = "*****@*****.**"; // arrange await using InWordsDataContext context = InWordsDataContextFactory.Create(); Account account = new Account() { Email = email, Hash = new byte[256], Role = InWords.Data.Enums.RoleType.Unverified }; User user = new User() { Account = account, NickName = "nick" }; context.Accounts.Add(account); await context.SaveChangesAsync().ConfigureAwait(false); var mock = new Mock <IEmailVerifierService>(); mock.Setup(a => a.InstatiateVerifierMessage(It.IsAny <User>(), It.IsAny <string>())); var jwtMock = new Mock <IJwtProvider>(); jwtMock.Setup(a => a.GenerateToken(It.IsAny <ClaimsIdentity>())).Returns("token"); // act var registration = new UserRegistration(context, jwtMock.Object, mock.Object); // assert var request = new RequestObject <RegistrationRequest, RegistrationReply>( new RegistrationRequest() { Email = email, Password = "******" }); var reply = registration.HandleRequest(request); Assert.Equal(StatusCode.AlreadyExists, request.StatusCode); Assert.Equal(1, context.Accounts.Count()); mock.Verify(a => a.InstatiateVerifierMessage(It.IsAny <User>(), It.IsAny <string>()), Times.Never()); }
public async Task WhereAnyTestUserWordPairTest() { // prepare var userWordPairsList = new List <int>() { 2, 3, 4 }; var expectedWordPairsList = new List <int>() { 3, 4, 4 }; await using InWordsDataContext context = InWordsDataContextFactory.Create(); context.UserWordPairs.Add(new UserWordPair() { UserId = 1, UserWordPairId = 1, WordPairId = 2 }); // Bad context.UserWordPairs.Add(new UserWordPair() { UserId = 1, UserWordPairId = 2, WordPairId = 3 }); // Good context.UserWordPairs.Add(new UserWordPair() { UserId = 1, UserWordPairId = 3, WordPairId = 4 }); // Good context.UserWordPairs.Add(new UserWordPair() { UserId = 2, UserWordPairId = 4, WordPairId = 4 }); // Good context.UserWordPairs.Add(new UserWordPair() { UserId = 2, UserWordPairId = 5, WordPairId = 3 }); // Bad await context.SaveChangesAsync().ConfigureAwait(false); // act var actualList = context.UserWordPairs.WhereAny(userWordPairsList).Select(d => d.WordPairId).ToList(); // assert Assert.Equal(expectedWordPairsList, actualList); }
public async void GetTokenOnExistFalsePassword() { // arrange await using InWordsDataContext context = InWordsDataContextFactory.Create(); AddFakeUser(context); var mock = new Mock <IPasswordSalter>(); mock.Setup(a => a.EqualsSequence(It.IsAny <string>(), It.IsAny <byte[]>())).Returns(false); var jwtMock = new Mock <IJwtProvider>(); jwtMock.Setup(a => a.GenerateToken(It.IsAny <ClaimsIdentity>())).Returns("token"); // act var token = new UserToken(context, jwtMock.Object, mock.Object); var response = await HandleRequest(token); // assert Assert.True(string.IsNullOrWhiteSpace(response.Token)); }
public async void GetTokenOnExistRightPassword() { // arrange await using InWordsDataContext context = InWordsDataContextFactory.Create(); AddFakeUser(context); var mock = new Mock <IPasswordSalter>(); mock.Setup(a => a.EqualsSequence(It.IsAny <string>(), It.IsAny <byte[]>())).Returns(true); var jwtMock = new Mock <IJwtProvider>(); jwtMock.Setup(a => a.GenerateToken(It.IsAny <ClaimsIdentity>())).Returns("token"); // act var token = new UserToken(context, jwtMock.Object, mock.Object); var test = await HandleRequest(token).ConfigureAwait(false); // assert Assert.Equal(1, test.UserId); }
private void CreateContextWithExistedGame(InWordsDataContext context, int userId) { context.Games.Add(new Game { GameId = 1 }); context.GameTags.Add(new GameTag() { UserId = userId, Tags = GameTags.CustomLevelsHistory, GameId = 1 }); context.WordPairs.AddRange(new List <WordPair>() { new WordPair() { WordPairId = 2 }, new WordPair() { WordPairId = 3 }, new WordPair() { WordPairId = 4 }, }); context.UserWordPairs.AddRange(new List <UserWordPair>() { new UserWordPair() { UserWordPairId = 1, WordPairId = 2, UserId = userId }, new UserWordPair() { UserWordPairId = 2, WordPairId = 3, UserId = userId }, new UserWordPair() { UserWordPairId = 3, WordPairId = 4, UserId = userId }, }); }
public async Task GetWordsAsync() { // arrange await using InWordsDataContext context = InWordsDataContextFactory.Create(); await CreateTestContext(context); WordSetWordsRequest requestData = new WordSetWordsRequest() { WordSetId = context.Games.First().GameId }; var request = new AuthReq <WordSetWordsRequest, WordSetWordsReply>(requestData) { UserId = context.Users.First().UserId }; // act var reply = await new GetMarkedWordsHandler(context).Handle(request); // assert Assert.Equal(2, reply.Words.Count); }