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 GetWordsAsyncUserHasOne() { // 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 }; context.UserWordPairs.Add(new UserWordPair() { UserId = context.Users.First().UserId, ForeignWord = "test4", NativeWord = "тест4" }); context.SaveChanges(); // act var reply = await new GetMarkedWordsHandler(context).Handle(request); // assert Assert.Single(reply.Words.Where(d => d.HasAdded.Equals(true))); Assert.Single(reply.Words.Where(d => d.HasAdded.Equals(false))); }
public async void Find_Existed_Account() { // arrange int userId = 1; string nickname = "nick"; int other = 2; await using InWordsDataContext context = InWordsDataContextFactory.Create(); await context.AddAccount(userId); await context.SaveChangesAsync(); context.Users.First().NickName = nickname; context.SaveChanges(); // act var requestData = new FindUsernameRequest() { UserName = nickname }; var request = new AuthReq <FindUsernameRequest, PublicProfilesReply>(requestData) { UserId = other, }; var handler = new FindProfileNickname(context); var result = await handler.Handle(request); // assert Assert.Equal(userId, result.Users.First().UserId); }
public async Task ToDictionary_ShouldBeOk() { // arrange await using InWordsDataContext context = InWordsDataContextFactory.Create(); await CreateTestContext(context); WordSetWordsRequest requestData = new WordSetWordsRequest() { WordSetId = context.Games.First().GameId }; var request = new AuthReq <WordSetWordsRequest, Empty>(requestData) { UserId = context.Users.First().UserId }; context.UserWordPairs.Add(new UserWordPair() { UserId = context.Users.First().UserId, ForeignWord = "test4", NativeWord = "тест4" }); context.SaveChanges(); // act var mock = new Mock <IRequestHandler <AuthReq <AddWordsRequest, AddWordsReply>, AddWordsReply> >(); mock.Setup(a => a.Handle(It.Is(IsGameOne()), It.IsAny <CancellationToken>())); var reply = await new ToDictionaryHandler(context, mock.Object).Handle(request); // assert mock.Verify(a => a.Handle(It.Is(IsGameOne()), It.IsAny <CancellationToken>()), Times.Once()); }
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 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 Task HistoryLevelsMultyTypes_GetOnce() { // prepare var userId = 1; using InWordsDataContext context = InWordsDataContextFactory.Create(); int gameId = 1; var creation1 = new Game { CreatorId = userId, GameId = gameId }; context.Games.Add(creation1); context.GameTags.Add(new GameTag() { Tags = GameTags.CustomLevelsHistory, GameId = gameId, UserId = userId }); creation1.GameLevels.Add(new GameLevel() { Game = creation1 }); context.SaveChanges(); int gameLevelId = creation1.GameLevels.First().GameLevelId; context.UserGameLevels.Add(new UserGameLevel(userId, gameLevelId, 6, GameType.Audio)); context.UserGameLevels.Add(new UserGameLevel(userId, gameLevelId, 6, GameType.ClosedAudioCards)); context.UserGameLevels.Add(new UserGameLevel(userId, gameLevelId, 6, GameType.Total)); 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.Single(test.Levels); }
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); }
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() { 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 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); }