public async void GetLevelsInSet() { // arrange await using InWordsDataContext context = InWordsDataContextFactory.Create(); var game1 = new Game(); context.Add(game1); List <GameLevel> gameLevels = new List <GameLevel> { new GameLevel() { GameId = game1.GameId, }, new GameLevel() { GameId = game1.GameId, } }; context.AddRange(gameLevels); await context.SaveChangesAsync(); // act var data = new GetLevelsRequest() { WordSetId = game1.GameId }; var request = new AuthReq <GetLevelsRequest, GetLevelsReply>(data); var handler = new GetWordSetLevels(context); var result = await handler.Handle(request); // assert Assert.Equal(2, result.Levels.Count); }
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 AuthReq <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 AuthReq <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 CreateScore() { using InWordsDataContext context = InWordsDataContextFactory.Create(); { CreateGameContext(context); ClassicCardLevelMetricQuery request = new ClassicCardLevelMetricQuery() { UserId = 1, Metrics = new List <ClassicCardLevelMetric>() { new ClassicCardLevelMetric() { GameLevelId = 1, 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 async void Find_Existed_Account() { // arrange int userId = 1; int other = 2; await using InWordsDataContext context = InWordsDataContextFactory.Create(); await context.AddAccount(userId); await context.SaveChangesAsync(); // act var requestData = new FindIdRequest() { UserId = userId }; var request = new AuthReq <FindIdRequest, PublicProfileReply>(requestData) { UserId = other, }; var handler = new FindProfileId(context); var result = await handler.Handle(request); // assert Assert.Equal(userId, result.UserId); }
public async void AddUserWordPairsInvertedPair() { // arrange int expectedWordsCount = 4; using var context = InWordsDataContextFactory.Create(); Account account1 = await context.AddAccount(1); context.Add(account1); context.Add(new UserWordPair(1, account1.AccountId)); // user1 word context.Add(new UserWordPair(2, 1) { IsInvertPair = true }); // user1 word context.SaveChanges(); // act context.UserWordPairs.AddUserWordPair( new UserWordPair[] { new UserWordPair(2, account1.AccountId), // should be added to user1 new UserWordPair(3, account1.AccountId), // should be added to user1 }); context.SaveChanges(); // assert Assert.Equal(expectedWordsCount, context.UserWordPairs.Count()); }
public async void AddUserWordPairsMultiUser() { // arrange int expectedWordsCount = 2 + 3; int user1WordsCount = 1 + 2; int user2WordsCount = 1 + 1; using var context = InWordsDataContextFactory.Create(); Account account1 = await context.AddAccount(1); Account account2 = await context.AddAccount(2); context.Add(account1); context.Add(account2); context.Add(new UserWordPair(2, account1.AccountId) { IsInvertPair = true }); // user1 word context.Add(new UserWordPair(2, account2.AccountId)); // user2 word context.SaveChanges(); // act context.UserWordPairs.AddUserWordPair( new UserWordPair[] { new UserWordPair(2, account1.AccountId), // should be added to user1 new UserWordPair(3, account1.AccountId), // should be added to user1 new UserWordPair(3, account2.AccountId) // should be added to to user2 }); context.SaveChanges(); // assert Assert.Equal(expectedWordsCount, context.UserWordPairs.Count()); Assert.Equal(user1WordsCount, context.UserWordPairs.Where(s => s.UserId == account1.AccountId).Count()); Assert.Equal(user2WordsCount, context.UserWordPairs.Where(s => s.UserId == account2.AccountId).Count()); }
public async void RegisterUser() { // arrange await using InWordsDataContext context = InWordsDataContextFactory.Create(); 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); var test = await registration.HandleRequest( new RequestObject <RegistrationRequest, RegistrationReply>( new RegistrationRequest() { Email = "*****@*****.**", Password = "******" })) .ConfigureAwait(false); // assert Assert.Equal(1, context.Accounts.Count()); mock.Verify(a => a.InstatiateVerifierMessage(It.IsAny <User>(), It.IsAny <string>()), Times.Once()); jwtMock.Verify(a => a.GenerateToken(It.IsAny <ClaimsIdentity>()), Times.Once()); }
public async void WrongLinkTest() { // arrange string rightGuid = Guid.NewGuid().ToString(); await using InWordsDataContext context = InWordsDataContextFactory.Create(); context.EmailVerifies.Add(new EmailVerifies() { Guid = rightGuid, }); await context.SaveChangesAsync(); // act var requestObject = new RequestObject <ConfirmEmailLinkRequest, ConfirmEmailReply>( new ConfirmEmailLinkRequest() { ActivationGuid = "wronglink" }); var registration = new ConfirmEmailLink(context); await registration.HandleRequest(requestObject); Assert.Equal(StatusCode.InvalidArgument, requestObject.StatusCode); }
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 void AddingTheSameWords() { // arrange var context = InWordsDataContextFactory.Create(); context.Add(new Word("a")); context.SaveChanges(); // act IEnumerable <Word> wordsToAdd = new List <Word>() { new Word("a"), new Word("A"), new Word("b"), new Word("B"), new Word("b"), new Word("b "), new Word(" b ") }; context.Words.AddWords(wordsToAdd); context.SaveChanges(); // assert Assert.Equal(2, wordsToAdd.Where(d => d.WordId > 0).Count()); Assert.Equal(2, context.Words.Count()); }
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 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 ConfirmValidCode() { // arrange int userId = 1; Guid rightGuid = Guid.NewGuid(); string newEmail = "*****@*****.**"; await using InWordsDataContext context = InWordsDataContextFactory.Create(); await context.AddAccount(userId); context.EmailVerifies.Add(new EmailVerifies() { UserId = userId, Guid = rightGuid, Email = newEmail }); await context.SaveChangesAsync(); // act var requestObject = new RequestObject <ConfirmEmailLinkRequest, ConfirmEmailReply>( new ConfirmEmailLinkRequest() { ActivationGuid = rightGuid.ToString() }); var registration = new ConfirmEmailLink(context); var test = await registration.HandleRequest(requestObject).ConfigureAwait(false); // assert Assert.Equal(0, context.EmailVerifies.Count()); Assert.Equal(newEmail, test.Email); Assert.Equal(newEmail, context.Accounts.First().Email); }
public async void DeleteExistedAccount() { // arrange int userId = 1; int otherId = 2; await using InWordsDataContext context = InWordsDataContextFactory.Create(); await context.AddAccount(userId); await context.AddAccount(otherId); await context.SaveChangesAsync(); // act var requestObject = new AuthorizedRequestObject <DeleteAccountRequest, Empty>( new DeleteAccountRequest() { Text = "Delete me just for test" }) { UserId = userId }; var registration = new DeleteAccount(context); await registration.HandleRequest(requestObject).ConfigureAwait(false); // assert Assert.Single(context.Accounts); Assert.Equal(otherId, context.Accounts.First().AccountId); }
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 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 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 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 void AddContentAsWords() { // arrange var context = InWordsDataContextFactory.Create(); string[] content = { "a", "b", "c" }; // act var actual = context.Words.AddWords(content); context.SaveChanges(); // assert Assert.Equal(content.Count(), context.Words.Count()); Assert.Equal(content.Count(), actual.Where(d => d.WordId > 0).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); }
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 void CheckALlInLowercase() { var context = InWordsDataContextFactory.Create(); IEnumerable <Word> actual = new List <Word>() { new Word("A"), new Word("B") }; string[] expected = { "a", "b" }; context.Words.AddWords(actual); // assert Assert.Equal(expected, actual.Select(e => e.Content)); }
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 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); }
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 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 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()); }