public async Task UserInVisibilityList() { var db = DbHelper.GetEmptyTestDB(); var cardCreator = await UserHelper.CreateInDbAsync(db); var languageId = await CardLanguagHelper.CreateAsync(db); var otherUser = await UserHelper.CreateInDbAsync(db); var card = await CardHelper.CreateAsync(db, cardCreator, language : languageId, userWithViewIds : new[] { cardCreator, otherUser }); var newFrontSide = RandomHelper.String(); using (var dbContext = new MemCheckDbContext(db)) { var r = UpdateCardHelper.RequestForFrontSideChange(card, newFrontSide, otherUser); await new UpdateCard(dbContext.AsCallContext()).RunAsync(r); } using (var dbContext = new MemCheckDbContext(db)) { var cardFromDb = dbContext.Cards.Single(c => c.Id == card.Id); Assert.AreEqual(newFrontSide, cardFromDb.FrontSide); } }
public async Task NonPrivateCardNotDeleted_UserOwnerOfCurrentButNotPrevious() { var db = DbHelper.GetEmptyTestDB(); var loggedUserName = RandomHelper.String(); var loggedUser = await UserHelper.CreateInDbAsync(db, userName : loggedUserName); var language = await CardLanguagHelper.CreateAsync(db); var userToDelete = await UserHelper.CreateInDbAsync(db); var card = await CardHelper.CreateAsync(db, loggedUser, language : language); await UpdateCardHelper.RunAsync(db, UpdateCardHelper.RequestForFrontSideChange(card, RandomHelper.String(), versionCreator: userToDelete)); using (var dbContext = new MemCheckDbContext(db)) { using var userManager = UserHelper.GetUserManager(dbContext); await new DeleteUserAccount(dbContext.AsCallContext(new TestRoleChecker(loggedUser)), userManager).RunAsync(new DeleteUserAccount.Request(loggedUser, userToDelete)); } using (var dbContext = new MemCheckDbContext(db)) { Assert.AreEqual(DeleteUserAccount.DeletedUserName, dbContext.Cards.Include(card => card.VersionCreator).Single(card => card.Id == card.Id).VersionCreator.UserName); Assert.AreEqual(loggedUserName, dbContext.CardPreviousVersions.Include(cardPreviousVersion => cardPreviousVersion.VersionCreator).Single(cardPreviousVersion => cardPreviousVersion.Card == card.Id).VersionCreator.UserName); } }
public async Task FailIfNotCreatorOfCurrentVersion() { var db = DbHelper.GetEmptyTestDB(); var firstVersionCreator = await UserHelper.CreateInDbAsync(db); var languageId = await CardLanguagHelper.CreateAsync(db); var card = await CardHelper.CreateAsync(db, firstVersionCreator, language : languageId); var lastVersionCreator = await UserHelper.CreateInDbAsync(db); using (var dbContext = new MemCheckDbContext(db)) await new UpdateCard(dbContext.AsCallContext()).RunAsync(UpdateCardHelper.RequestForFrontSideChange(card, RandomHelper.String(), lastVersionCreator)); using (var dbContext = new MemCheckDbContext(db)) { var deleter = new DeleteCards(dbContext.AsCallContext(new TestLocalizer(new System.Collections.Generic.KeyValuePair <string, string>("YouAreNotTheCreatorOfCurrentVersion", "YouAreNotTheCreatorOfCurrentVersion")))); var e = await Assert.ThrowsExceptionAsync <RequestInputException>(async() => await deleter.RunAsync(new DeleteCards.Request(firstVersionCreator, card.Id.AsArray()))); StringAssert.Contains(e.Message, "YouAreNotTheCreatorOfCurrentVersion"); } using (var dbContext = new MemCheckDbContext(db)) { Assert.AreEqual(card.Id, dbContext.Cards.Single().Id); Assert.AreEqual(card.Id, dbContext.CardPreviousVersions.Single().Card); } }
public async Task CardWithIntermediaryVersionsToBeDeletedFromPreviousVersions() { var db = DbHelper.GetEmptyTestDB(); var user = await UserHelper.CreateInDbAsync(db); var languageId = await CardLanguagHelper.CreateAsync(db); var card = await CardHelper.CreateAsync(db, user, language : languageId); await UpdateCardHelper.RunAsync(db, UpdateCardHelper.RequestForFrontSideChange(card, RandomHelper.String())); var runDate = RandomHelper.Date(); using (var dbContext = new MemCheckDbContext(db)) { var deleter = new DeleteCards(dbContext.AsCallContext(), RandomHelper.DateBefore(runDate)); await deleter.RunAsync(new DeleteCards.Request(user, card.Id.AsArray())); } using (var dbContext = new MemCheckDbContext(db)) Assert.AreEqual(3, dbContext.CardPreviousVersions.Count()); using (var dbContext = new MemCheckDbContext(db)) await new DeleteCardPreviousVersionsOfDeletedCards(dbContext.AsCallContext(new TestRoleChecker(user))).RunAsync(new DeleteCardPreviousVersionsOfDeletedCards.Request(user, runDate)); using (var dbContext = new MemCheckDbContext(db)) Assert.AreEqual(0, dbContext.CardPreviousVersions.Count()); }
public async Task ReduceVisibility_OtherUserHasInDeck_OtherAuthor() { var db = DbHelper.GetEmptyTestDB(); var cardCreator = await UserHelper.CreateInDbAsync(db); var languageId = await CardLanguagHelper.CreateAsync(db); var card = await CardHelper.CreateAsync(db, cardCreator, language : languageId, userWithViewIds : Array.Empty <Guid>()); var userWithCardInDeck = await UserHelper.CreateInDbAsync(db); var deck = await DeckHelper.CreateAsync(db, userWithCardInDeck); await DeckHelper.AddCardAsync(db, deck, card.Id, 0); var otherUser = await UserHelper.CreateInDbAsync(db); using (var dbContext = new MemCheckDbContext(db)) { var r = UpdateCardHelper.RequestForFrontSideChange(card, RandomHelper.String(), otherUser); await new UpdateCard(dbContext.AsCallContext()).RunAsync(r); } using (var dbContext = new MemCheckDbContext(db)) { var r = UpdateCardHelper.RequestForVisibilityChange(card, cardCreator.AsArray()); await Assert.ThrowsExceptionAsync <RequestInputException>(async() => await new UpdateCard(dbContext.AsCallContext()).RunAsync(r)); } using (var dbContext = new MemCheckDbContext(db)) { var r = UpdateCardHelper.RequestForVisibilityChange(card, otherUser.AsArray(), otherUser); await Assert.ThrowsExceptionAsync <RequestInputException>(async() => await new UpdateCard(dbContext.AsCallContext()).RunAsync(r)); } using (var dbContext = new MemCheckDbContext(db)) { var r = UpdateCardHelper.RequestForVisibilityChange(card, new[] { userWithCardInDeck }, userWithCardInDeck); await Assert.ThrowsExceptionAsync <RequestInputException>(async() => await new UpdateCard(dbContext.AsCallContext()).RunAsync(r)); } using (var dbContext = new MemCheckDbContext(db)) { var r = UpdateCardHelper.RequestForVisibilityChange(card, new[] { cardCreator, otherUser, userWithCardInDeck }); await new UpdateCard(dbContext.AsCallContext()).RunAsync(r); } using (var dbContext = new MemCheckDbContext(db)) { CardVisibilityHelper.CheckUserIsAllowedToViewCards(dbContext, cardCreator, card.Id); CardVisibilityHelper.CheckUserIsAllowedToViewCards(dbContext, otherUser, card.Id); CardVisibilityHelper.CheckUserIsAllowedToViewCards(dbContext, userWithCardInDeck, card.Id); } }
public async Task UserNotLoggedIn() { var db = DbHelper.GetEmptyTestDB(); var user = await UserHelper.CreateInDbAsync(db); var languageId = await CardLanguagHelper.CreateAsync(db); var card = await CardHelper.CreateAsync(db, user, language : languageId); using var dbContext = new MemCheckDbContext(db); var request = UpdateCardHelper.RequestForFrontSideChange(card, RandomHelper.String(), Guid.Empty); await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await new UpdateCard(dbContext.AsCallContext()).RunAsync(request)); }
public async Task MultipleCase() { var db = DbHelper.GetEmptyTestDB(); var user = await UserHelper.CreateInDbAsync(db); var languageId = await CardLanguagHelper.CreateAsync(db); var runDate = RandomHelper.Date(); var cardNotDeleted = await CardHelper.CreateAsync(db, user, language : languageId); await UpdateCardHelper.RunAsync(db, UpdateCardHelper.RequestForFrontSideChange(cardNotDeleted, RandomHelper.String())); using (var dbContext = new MemCheckDbContext(db)) Assert.AreEqual(1, dbContext.CardPreviousVersions.Count()); var cardDeletedAfterRunDate = await CardHelper.CreateAsync(db, user, language : languageId); using (var dbContext = new MemCheckDbContext(db)) { var deleter = new DeleteCards(dbContext.AsCallContext(), RandomHelper.Date(runDate)); await deleter.RunAsync(new DeleteCards.Request(user, cardDeletedAfterRunDate.Id.AsArray())); } using (var dbContext = new MemCheckDbContext(db)) Assert.AreEqual(3, dbContext.CardPreviousVersions.Count()); var cardDeletedBeforeRunDate = await CardHelper.CreateAsync(db, user, language : languageId); using (var dbContext = new MemCheckDbContext(db)) { var deleter = new DeleteCards(dbContext.AsCallContext(), RandomHelper.DateBefore(runDate)); await deleter.RunAsync(new DeleteCards.Request(user, cardDeletedBeforeRunDate.Id.AsArray())); } using (var dbContext = new MemCheckDbContext(db)) Assert.AreEqual(5, dbContext.CardPreviousVersions.Count()); using (var dbContext = new MemCheckDbContext(db)) await new DeleteCardPreviousVersionsOfDeletedCards(dbContext.AsCallContext(new TestRoleChecker(user))).RunAsync(new DeleteCardPreviousVersionsOfDeletedCards.Request(user, runDate)); using (var dbContext = new MemCheckDbContext(db)) { var previousVersions = await dbContext.CardPreviousVersions.ToListAsync(); Assert.AreEqual(3, previousVersions.Count); Assert.AreEqual(1, previousVersions.Where(pv => pv.Card == cardNotDeleted.Id).Count()); Assert.AreEqual(2, previousVersions.Where(pv => pv.Card == cardDeletedAfterRunDate.Id).Count()); } }
public async Task DescriptionTooLong() { var db = DbHelper.GetEmptyTestDB(); var cardCreator = await UserHelper.CreateInDbAsync(db); var languageId = await CardLanguagHelper.CreateAsync(db); var card = await CardHelper.CreateAsync(db, cardCreator, language : languageId, userWithViewIds : Array.Empty <Guid>()); var request = UpdateCardHelper.RequestForFrontSideChange(card, RandomHelper.String(), versionDescription: RandomHelper.String(CardInputValidator.MaxVersionDescriptionLength + 1)); using var dbContext = new MemCheckDbContext(db); await Assert.ThrowsExceptionAsync <RequestInputException>(async() => await new UpdateCard(dbContext.AsCallContext()).RunAsync(request)); }
public async Task EmptyDB_OriginalVersionDoesNotExist() { var db = DbHelper.GetEmptyTestDB(); var userId = await UserHelper.CreateInDbAsync(db); var language = await CardLanguagHelper.CreateAsync(db); var card = await CardHelper.CreateAsync(db, userId, language : language); using (var dbContext = new MemCheckDbContext(db)) await new UpdateCard(dbContext.AsCallContext()).RunAsync(UpdateCardHelper.RequestForFrontSideChange(card, RandomHelper.String())); using (var dbContext = new MemCheckDbContext(db)) await dbContext.CardPreviousVersions.Where(previous => previous.Card == card.Id).SingleAsync(); using (var dbContext = new MemCheckDbContext(DbHelper.GetEmptyTestDB())) await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await new GetCardDiff(dbContext.AsCallContext()).RunAsync(new GetCardDiff.Request(userId, card.Id, Guid.NewGuid()))); }
public async Task UserDoesNotExist() { var db = DbHelper.GetEmptyTestDB(); var user = await UserHelper.CreateInDbAsync(db); var languageId = await CardLanguagHelper.CreateAsync(db); var frontSide = RandomHelper.String(); var card = await CardHelper.CreateAsync(db, user, language : languageId, frontSide : frontSide); using var dbContext = new MemCheckDbContext(db); var r = UpdateCardHelper.RequestForFrontSideChange(card, RandomHelper.String(), Guid.NewGuid()); await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await new UpdateCard(dbContext.AsCallContext()).RunAsync(r)); await CardHelper.AssertCardHasFrontSide(db, card.Id, frontSide); }
public async Task ReduceVisibility_NoUserHasInDeck_OtherAuthor() { var db = DbHelper.GetEmptyTestDB(); var cardCreatorName = RandomHelper.String(); var cardCreator = await UserHelper.CreateInDbAsync(db, userName : cardCreatorName); var languageId = await CardLanguagHelper.CreateAsync(db); var card = await CardHelper.CreateAsync(db, cardCreator, language : languageId, userWithViewIds : Array.Empty <Guid>()); var newVersionCreatorName = RandomHelper.String(); var newVersionCreator = await UserHelper.CreateInDbAsync(db, userName : newVersionCreatorName); using (var dbContext = new MemCheckDbContext(db)) { var r = UpdateCardHelper.RequestForFrontSideChange(card, RandomHelper.String(), newVersionCreator); await new UpdateCard(dbContext.AsCallContext()).RunAsync(r); } using (var dbContext = new MemCheckDbContext(db)) { var r = UpdateCardHelper.RequestForVisibilityChange(card, cardCreator.AsArray(), cardCreator); var e = await Assert.ThrowsExceptionAsync <RequestInputException>(async() => await new UpdateCard(dbContext.AsCallContext()).RunAsync(r)); Assert.IsTrue(e.Message.Contains(newVersionCreatorName)); } using (var dbContext = new MemCheckDbContext(db)) { var r = UpdateCardHelper.RequestForVisibilityChange(card, new[] { newVersionCreator }, newVersionCreator); var e = await Assert.ThrowsExceptionAsync <RequestInputException>(async() => await new UpdateCard(dbContext.AsCallContext()).RunAsync(r)); Assert.IsTrue(e.Message.Contains(cardCreatorName)); } using (var dbContext = new MemCheckDbContext(db)) { var r = UpdateCardHelper.RequestForVisibilityChange(card, new[] { cardCreator, newVersionCreator }); await new UpdateCard(dbContext.AsCallContext()).RunAsync(r); } using (var dbContext = new MemCheckDbContext(db)) { CardVisibilityHelper.CheckUserIsAllowedToViewCards(dbContext, cardCreator, card.Id); CardVisibilityHelper.CheckUserIsAllowedToViewCards(dbContext, newVersionCreator, card.Id); } }
public async Task CardsNotFoundAnymore_StillExists_UserAllowedToView() { var db = DbHelper.GetEmptyTestDB(); var cardCreator = await UserHelper.CreateInDbAsync(db); var language = await CardLanguagHelper.CreateAsync(db); var card = await CardHelper.CreateAsync(db, cardCreator, versionDate : new DateTime(2050, 03, 01), language : language); var subscriber = await UserHelper.CreateInDbAsync(db); var subscription = await SearchSubscriptionHelper.CreateAsync(db, subscriber, requiredText : card.FrontSide); using (var dbContext = new MemCheckDbContext(db)) { var searchResult = await new UserSearchNotifier(dbContext.AsCallContext(), 100, new DateTime(2050, 05, 01)).RunAsync(subscription.Id); Assert.AreEqual(1, searchResult.TotalNewlyFoundCardCount); } using (var dbContext = new MemCheckDbContext(db)) { var updateRequest = UpdateCardHelper.RequestForFrontSideChange(card, RandomHelper.String()); await new UpdateCard(dbContext.AsCallContext(), new DateTime(2050, 05, 02)).RunAsync(updateRequest); } var runDate = new DateTime(2050, 05, 03); using (var dbContext = new MemCheckDbContext(db)) { var searchResult = await new UserSearchNotifier(dbContext.AsCallContext(), 100, runDate).RunAsync(subscription.Id); Assert.AreEqual(0, searchResult.TotalNewlyFoundCardCount); Assert.AreEqual(0, searchResult.NewlyFoundCards.Length); Assert.AreEqual(1, searchResult.CountOfCardsNotFoundAnymore_StillExists_UserAllowedToView); Assert.AreEqual(1, searchResult.CardsNotFoundAnymore_StillExists_UserAllowedToView.Length); Assert.AreEqual(card.Id, searchResult.CardsNotFoundAnymore_StillExists_UserAllowedToView.Single().CardId); Assert.AreEqual(0, searchResult.CountOfCardsNotFoundAnymore_Deleted_UserAllowedToView); Assert.AreEqual(0, searchResult.CardsNotFoundAnymore_Deleted_UserAllowedToView.Length); Assert.AreEqual(0, searchResult.CountOfCardsNotFoundAnymore_StillExists_UserNotAllowedToView); Assert.AreEqual(0, searchResult.CountOfCardsNotFoundAnymore_Deleted_UserNotAllowedToView); } using (var dbContext = new MemCheckDbContext(db)) Assert.AreEqual(runDate, dbContext.SearchSubscriptions.Single(s => s.Id == subscription.Id).LastRunUtcDate); }
public async Task UserNotAllowedToViewCard() { var db = DbHelper.GetEmptyTestDB(); var cardCreator = await UserHelper.CreateInDbAsync(db); var languageId = await CardLanguagHelper.CreateAsync(db); var frontSide = RandomHelper.String(); var card = await CardHelper.CreateAsync(db, cardCreator, language : languageId, userWithViewIds : cardCreator.AsArray(), frontSide : frontSide); var otherUser = await UserHelper.CreateInDbAsync(db); using var dbContext = new MemCheckDbContext(db); var r = UpdateCardHelper.RequestForFrontSideChange(card, RandomHelper.String(), otherUser); await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await new UpdateCard(dbContext.AsCallContext()).RunAsync(r)); await CardHelper.AssertCardHasFrontSide(db, card.Id, frontSide); }
public async Task CardWithPreviousVersionsNotDeleted() { var db = DbHelper.GetEmptyTestDB(); var user = await UserHelper.CreateInDbAsync(db); var languageId = await CardLanguagHelper.CreateAsync(db); var card = await CardHelper.CreateAsync(db, user, language : languageId); await UpdateCardHelper.RunAsync(db, UpdateCardHelper.RequestForFrontSideChange(card, RandomHelper.String())); using (var dbContext = new MemCheckDbContext(db)) Assert.AreEqual(1, dbContext.CardPreviousVersions.Count()); using (var dbContext = new MemCheckDbContext(db)) await new DeleteCardPreviousVersionsOfDeletedCards(dbContext.AsCallContext(new TestRoleChecker(user))).RunAsync(new DeleteCardPreviousVersionsOfDeletedCards.Request(user, DateTime.MaxValue)); using (var dbContext = new MemCheckDbContext(db)) Assert.AreEqual(1, dbContext.CardPreviousVersions.Count()); }
public async Task UserNotSubscribingToCardOnEdit() { var db = DbHelper.GetEmptyTestDB(); var cardCreator = await UserHelper.CreateInDbAsync(db); var languageId = await CardLanguagHelper.CreateAsync(db); var card = await CardHelper.CreateAsync(db, cardCreator, language : languageId); var newVersionCreator = await UserHelper.CreateInDbAsync(db, subscribeToCardOnEdit : false); using (var dbContext = new MemCheckDbContext(db)) { var r = UpdateCardHelper.RequestForFrontSideChange(card, RandomHelper.String(), newVersionCreator); await new UpdateCard(dbContext.AsCallContext()).RunAsync(r); } Assert.IsFalse(await CardSubscriptionHelper.UserIsSubscribedToCardAsync(db, newVersionCreator, card.Id)); }
public async Task PublicCard() { var db = DbHelper.GetEmptyTestDB(); var cardCreator = await UserHelper.CreateInDbAsync(db); var languageId = await CardLanguagHelper.CreateAsync(db); var card = await CardHelper.CreateAsync(db, cardCreator, language : languageId, userWithViewIds : Array.Empty <Guid>()); var otherUser = await UserHelper.CreateInDbAsync(db); var newFrontSide = RandomHelper.String(); using (var dbContext = new MemCheckDbContext(db)) { var r = UpdateCardHelper.RequestForFrontSideChange(card, newFrontSide, otherUser); await new UpdateCard(dbContext.AsCallContext()).RunAsync(r); } await CardHelper.AssertCardHasFrontSide(db, card.Id, newFrontSide); }
public async Task SucceedsIfCreatorOfCurrentVersionIsDeleted() { var db = DbHelper.GetEmptyTestDB(); var firstVersionCreator = await UserHelper.CreateInDbAsync(db); var languageId = await CardLanguagHelper.CreateAsync(db); var card = await CardHelper.CreateAsync(db, firstVersionCreator, language : languageId); var lastVersionCreator = await UserHelper.CreateInDbAsync(db); using (var dbContext = new MemCheckDbContext(db)) await new UpdateCard(dbContext.AsCallContext()).RunAsync(UpdateCardHelper.RequestForFrontSideChange(card, RandomHelper.String(), lastVersionCreator)); await UserHelper.DeleteAsync(db, lastVersionCreator); using (var dbContext = new MemCheckDbContext(db)) await new DeleteCards(dbContext.AsCallContext()).RunAsync(new DeleteCards.Request(firstVersionCreator, card.Id.AsArray())); using (var dbContext = new MemCheckDbContext(db)) { Assert.IsFalse(dbContext.Cards.Any()); Assert.AreEqual(3, dbContext.CardPreviousVersions.Count()); } }
public async Task UpdateDoesNotAlterRatings() { var db = DbHelper.GetEmptyTestDB(); var user = await UserHelper.CreateInDbAsync(db); var languageId = await CardLanguagHelper.CreateAsync(db); var card = await CardHelper.CreateAsync(db, user, language : languageId); var rating = RandomHelper.Rating(); using (var dbContext = new MemCheckDbContext(db)) await new SetCardRating(dbContext.AsCallContext()).RunAsync(new SetCardRating.Request(user, card.Id, rating)); using (var dbContext = new MemCheckDbContext(db)) await new UpdateCard(dbContext.AsCallContext()).RunAsync(UpdateCardHelper.RequestForFrontSideChange(card, RandomHelper.String())); using (var dbContext = new MemCheckDbContext(db)) { var loaded = dbContext.Cards.Single(); Assert.AreEqual(1, loaded.RatingCount); Assert.AreEqual(rating, loaded.AverageRating); } }
public async Task SucceedsIfDeletedUserHasCreatedAPreviousVersion() { var db = DbHelper.GetEmptyTestDB(); var firstVersionCreator = await UserHelper.CreateInDbAsync(db); var languageId = await CardLanguagHelper.CreateAsync(db); var card = await CardHelper.CreateAsync(db, firstVersionCreator, language : languageId); var lastVersionCreator = await UserHelper.CreateInDbAsync(db); using (var dbContext = new MemCheckDbContext(db)) await new UpdateCard(dbContext.AsCallContext()).RunAsync(UpdateCardHelper.RequestForFrontSideChange(card, RandomHelper.String(), lastVersionCreator)); using (var dbContext = new MemCheckDbContext(db)) using (var userManager = UserHelper.GetUserManager(dbContext)) await new DeleteUserAccount(dbContext.AsCallContext(new TestRoleChecker(lastVersionCreator)), userManager).RunAsync(new DeleteUserAccount.Request(lastVersionCreator, firstVersionCreator)); using (var dbContext = new MemCheckDbContext(db)) await new DeleteCards(dbContext.AsCallContext()).RunAsync(new DeleteCards.Request(lastVersionCreator, card.Id.AsArray())); using (var dbContext = new MemCheckDbContext(db)) { Assert.IsFalse(dbContext.Cards.Any()); Assert.AreEqual(3, dbContext.CardPreviousVersions.Count()); } }
public async Task MultipleVersions() { var db = DbHelper.GetEmptyTestDB(); var userName = RandomHelper.String(); var userId = await UserHelper.CreateInDbAsync(db, userName : userName); var language = await CardLanguagHelper.CreateAsync(db); var oldestDate = RandomHelper.Date(); var oldestDescription = RandomHelper.String(); var card = await CardHelper.CreateAsync(db, userId, language : language, versionDate : oldestDate, versionDescription : oldestDescription); var otherUserName = RandomHelper.String(); var otherUserId = await UserHelper.CreateInDbAsync(db, userName : otherUserName); var intermediaryDate = RandomHelper.Date(); var intermediaryDescription = RandomHelper.String(); using (var dbContext = new MemCheckDbContext(db)) { var request = UpdateCardHelper.RequestForFrontSideChange(card, RandomHelper.String(), versionCreator: otherUserId, versionDescription: intermediaryDescription); request = request with { AdditionalInfo = RandomHelper.String() }; await new UpdateCard(dbContext.AsCallContext(), intermediaryDate).RunAsync(request); } var newestDate = RandomHelper.Date(); var newestDescription = RandomHelper.String(); using (var dbContext = new MemCheckDbContext(db)) { var cardFromDb = await dbContext.Cards .Include(c => c.VersionCreator) .Include(c => c.VersionCreator) .Include(c => c.Images) .Include(c => c.CardLanguage) .Include(c => c.TagsInCards) .Include(c => c.UsersWithView) .SingleAsync(c => c.Id == card.Id); await new UpdateCard(dbContext.AsCallContext(), newestDate).RunAsync(UpdateCardHelper.RequestForBackSideChange(cardFromDb, RandomHelper.String(), versionDescription: newestDescription, versionCreator: userId)); } using (var dbContext = new MemCheckDbContext(db)) { var versions = (await new GetCardVersions(dbContext.AsCallContext()).RunAsync(new GetCardVersions.Request(otherUserId, card.Id))).ToList(); Assert.AreEqual((await dbContext.CardPreviousVersions.SingleAsync(c => c.VersionUtcDate == oldestDate)).Id, versions[2].VersionId); Assert.AreEqual(oldestDate, versions[2].VersionUtcDate); Assert.AreEqual(userName, versions[2].VersionCreator); Assert.AreEqual(oldestDescription, versions[2].VersionDescription); Assert.AreEqual(5, versions[2].ChangedFieldNames.Count()); Assert.AreEqual((await dbContext.CardPreviousVersions.SingleAsync(c => c.VersionUtcDate == intermediaryDate)).Id, versions[1].VersionId); Assert.AreEqual(intermediaryDate, versions[1].VersionUtcDate); Assert.AreEqual(otherUserName, versions[1].VersionCreator); Assert.AreEqual(intermediaryDescription, versions[1].VersionDescription); Assert.AreEqual(2, versions[1].ChangedFieldNames.Count()); Assert.IsTrue(versions[1].ChangedFieldNames.Any(f => f == "FrontSide")); Assert.IsTrue(versions[1].ChangedFieldNames.Any(f => f == "AdditionalInfo")); Assert.IsNull(versions[0].VersionId); Assert.AreEqual(newestDate, versions[0].VersionUtcDate); Assert.AreEqual(userName, versions[0].VersionCreator); Assert.AreEqual(newestDescription, versions[0].VersionDescription); Assert.AreEqual(1, versions[0].ChangedFieldNames.Count()); Assert.AreEqual("BackSide", versions[0].ChangedFieldNames.First()); } } }
public async Task CardWithPreviousVersion() { var db = DbHelper.GetEmptyTestDB(); var language = await CardLanguagHelper.CreateAsync(db); var firstVersionCreatorId = await UserHelper.CreateInDbAsync(db); var firstVersionDate = RandomHelper.Date(); var card = await CardHelper.CreateAsync(db, firstVersionCreatorId, language : language, versionDate : firstVersionDate); var lastVersionCreatorName = RandomHelper.String(); var lastVersionCreatorId = await UserHelper.CreateInDbAsync(db, userName : lastVersionCreatorName); var lastVersionDate = RandomHelper.Date(); var lastVersionDescription = RandomHelper.String(); var lastVersionFrontSide = RandomHelper.String(); using (var dbContext = new MemCheckDbContext(db)) await new UpdateCard(dbContext.AsCallContext(), lastVersionDate).RunAsync(UpdateCardHelper.RequestForFrontSideChange(card, lastVersionFrontSide, versionCreator: lastVersionCreatorId, versionDescription: lastVersionDescription)); var otherUserId = await UserHelper.CreateInDbAsync(db); using (var dbContext = new MemCheckDbContext(db)) { var loaded = await new GetCardForEdit(dbContext.AsCallContext()).RunAsync(new GetCardForEdit.Request(otherUserId, card.Id)); Assert.AreEqual(firstVersionDate, loaded.FirstVersionUtcDate); Assert.AreEqual(lastVersionDate, loaded.LastVersionUtcDate); Assert.AreEqual(lastVersionCreatorName, loaded.LastVersionCreatorName); Assert.AreEqual(lastVersionDescription, loaded.LastVersionDescription); Assert.AreEqual(lastVersionFrontSide, loaded.FrontSide); } }
public async Task MultipleVersions() { var db = DbHelper.GetEmptyTestDB(); var language = await CardLanguagHelper.CreateAsync(db); var initialVersionCreatorName = RandomHelper.String(); var initialVersionCreatorId = await UserHelper.CreateInDbAsync(db, userName : initialVersionCreatorName); var initialVersionDate = RandomHelper.Date(); var initialVersionDescription = RandomHelper.String(); var initialVersionFrontSide = RandomHelper.String(); var card = await CardHelper.CreateAsync(db, initialVersionCreatorId, language : language, versionDate : initialVersionDate, versionDescription : initialVersionDescription, frontSide : initialVersionFrontSide); var intermediaryVersionCreatorName = RandomHelper.String(); var intermediaryVersionCreatorId = await UserHelper.CreateInDbAsync(db, userName : intermediaryVersionCreatorName); var intermediaryVersionDate = RandomHelper.Date(); var intermediaryVersionDescription = RandomHelper.String(); var intermediaryVersionFrontSide = RandomHelper.String(); using (var dbContext = new MemCheckDbContext(db)) await new UpdateCard(dbContext.AsCallContext(), intermediaryVersionDate).RunAsync(UpdateCardHelper.RequestForFrontSideChange(card, intermediaryVersionFrontSide, versionCreator: intermediaryVersionCreatorId, versionDescription: intermediaryVersionDescription)); using (var dbContext = new MemCheckDbContext(db)) //We need a new version to exist but don't mind about its contents await new UpdateCard(dbContext.AsCallContext(), RandomHelper.Date()).RunAsync(UpdateCardHelper.RequestForBackSideChange(card, RandomHelper.String(), versionDescription: RandomHelper.String(), versionCreator: initialVersionCreatorId)); using (var dbContext = new MemCheckDbContext(db)) { var versions = (await new GetCardVersions(dbContext.AsCallContext()).RunAsync(new GetCardVersions.Request(intermediaryVersionCreatorId, card.Id))).Where(v => v.VersionId != null).Select(v => v.VersionId !.Value).ToList(); var initialVersionId = versions[1]; var intermediaryVersionId = versions[0]; var initialVersion = await new GetCardVersion(dbContext.AsCallContext()).RunAsync(new GetCardVersion.Request(initialVersionCreatorId, initialVersionId)); Assert.AreEqual(initialVersionDescription, initialVersion.VersionDescription); Assert.AreEqual(initialVersionDate, initialVersion.VersionUtcDate); Assert.AreEqual(initialVersionCreatorName, initialVersion.CreatorName); Assert.AreEqual(initialVersionFrontSide, initialVersion.FrontSide); var intermediaryVersion = await new GetCardVersion(dbContext.AsCallContext()).RunAsync(new GetCardVersion.Request(initialVersionCreatorId, intermediaryVersionId)); Assert.AreEqual(intermediaryVersionDescription, intermediaryVersion.VersionDescription); Assert.AreEqual(intermediaryVersionDate, intermediaryVersion.VersionUtcDate); Assert.AreEqual(intermediaryVersionCreatorName, intermediaryVersion.CreatorName); Assert.AreEqual(intermediaryVersionFrontSide, intermediaryVersion.FrontSide); } }
public async Task MultipleVersions() { var db = DbHelper.GetEmptyTestDB(); var userId = await UserHelper.CreateInDbAsync(db); var initialVersionDate = RandomHelper.Date(); var intialVersionDescription = RandomHelper.String(); var language = await CardLanguagHelper.CreateAsync(db); var initialFrontSide = RandomHelper.String(); var card = await CardHelper.CreateAsync(db, userId, initialVersionDate, language : language, frontSide : initialFrontSide, versionDescription : intialVersionDescription); var intermediaryVersionDescription = RandomHelper.String(); var intermediaryVersionDate = RandomHelper.Date(initialVersionDate); var intermediaryFrontSide = RandomHelper.String(); using (var dbContext = new MemCheckDbContext(db)) await new UpdateCard(dbContext.AsCallContext(), intermediaryVersionDate).RunAsync(UpdateCardHelper.RequestForFrontSideChange(card, intermediaryFrontSide, versionDescription: intermediaryVersionDescription)); Guid initialVersionId; using (var dbContext = new MemCheckDbContext(db)) initialVersionId = (await dbContext.CardPreviousVersions.SingleAsync()).Id; var currentVersionDescription = RandomHelper.String(); var currentVersionDate = RandomHelper.Date(initialVersionDate); using (var dbContext = new MemCheckDbContext(db)) await new UpdateCard(dbContext.AsCallContext(), currentVersionDate).RunAsync(UpdateCardHelper.RequestForFrontSideChange(card, initialFrontSide, versionDescription: currentVersionDescription)); Guid intermediaryVersionId; using (var dbContext = new MemCheckDbContext(db)) intermediaryVersionId = (await dbContext.CardPreviousVersions.SingleAsync(c => c.Id != initialVersionId)).Id; using (var dbContext = new MemCheckDbContext(db)) { var diffRequest = new GetCardDiff.Request(userId, card.Id, intermediaryVersionId); var result = await new GetCardDiff(dbContext.AsCallContext()).RunAsync(diffRequest); Assert.AreEqual(currentVersionDate, result.CurrentVersionUtcDate); Assert.AreEqual(intermediaryVersionDate, result.OriginalVersionUtcDate); Assert.AreEqual(currentVersionDescription, result.CurrentVersionDescription); Assert.AreEqual(intermediaryVersionDescription, result.OriginalVersionDescription); Assert.AreEqual(new(initialFrontSide, intermediaryFrontSide), result.FrontSide); Assert.IsNull(result.Language); Assert.IsNull(result.BackSide); Assert.IsNull(result.Tags); Assert.IsNull(result.AdditionalInfo); Assert.IsNull(result.UsersWithView); Assert.IsNull(result.ImagesOnFrontSide); Assert.IsNull(result.ImagesOnBackSide); Assert.IsNull(result.ImagesOnAdditionalSide); } using (var dbContext = new MemCheckDbContext(db)) { var diffRequest = new GetCardDiff.Request(userId, card.Id, initialVersionId); var result = await new GetCardDiff(dbContext.AsCallContext()).RunAsync(diffRequest); Assert.AreEqual(currentVersionDate, result.CurrentVersionUtcDate); Assert.AreEqual(initialVersionDate, result.OriginalVersionUtcDate); Assert.AreEqual(currentVersionDescription, result.CurrentVersionDescription); Assert.AreEqual(intialVersionDescription, result.OriginalVersionDescription); Assert.IsNull(result.Language); Assert.IsNull(result.FrontSide); Assert.IsNull(result.BackSide); Assert.IsNull(result.Tags); Assert.IsNull(result.AdditionalInfo); Assert.IsNull(result.UsersWithView); Assert.IsNull(result.ImagesOnFrontSide); Assert.IsNull(result.ImagesOnBackSide); Assert.IsNull(result.ImagesOnAdditionalSide); } }
public async Task MultipleDiffs() { var db = DbHelper.GetEmptyTestDB(); var userName = RandomHelper.String(); var userId = await UserHelper.CreateInDbAsync(db, userName : userName); var originalVersionDate = RandomHelper.Date(); var originalVersionDescription = RandomHelper.String(); var language = await CardLanguagHelper.CreateAsync(db); var originalVersionImageName = RandomHelper.String(); var originalVersionImage = await ImageHelper.CreateAsync(db, userId, originalVersionImageName); var originalFrontSide = RandomHelper.String(); var originalBackSide = RandomHelper.String(); var originalTagName1 = RandomHelper.String(); var originalTagId1 = await TagHelper.CreateAsync(db, originalTagName1); var originalTagName2 = RandomHelper.String(); var originalTagId2 = await TagHelper.CreateAsync(db, originalTagName2); var card = await CardHelper.CreateAsync(db, userId, originalVersionDate, language : language, frontSide : originalFrontSide, backSide : originalBackSide, tagIds : new[] { originalTagId1, originalTagId2 }, additionalSideImages : originalVersionImage.AsArray(), versionDescription : originalVersionDescription); var newVersionDescription = RandomHelper.String(); var newVersionDate = RandomHelper.Date(originalVersionDate); var newFrontSide = RandomHelper.String(); var newBackSide = RandomHelper.String(); var newVersionImageName = RandomHelper.String(); var newVersionImage = await ImageHelper.CreateAsync(db, userId, newVersionImageName); using (var dbContext = new MemCheckDbContext(db)) { var r = UpdateCardHelper.RequestForFrontSideChange(card, newFrontSide, versionDescription: newVersionDescription); r = r with { BackSide = newBackSide }; r = r with { AdditionalInfoImageList = newVersionImage.AsArray() }; r = r with { Tags = originalTagId1.AsArray() }; await new UpdateCard(dbContext.AsCallContext(), newVersionDate).RunAsync(r); } Guid previousVersionId; using (var dbContext = new MemCheckDbContext(db)) previousVersionId = (await dbContext.CardPreviousVersions.Where(previous => previous.Card == card.Id).SingleAsync()).Id; using (var dbContext = new MemCheckDbContext(db)) { var diffRequest = new GetCardDiff.Request(userId, card.Id, previousVersionId); var result = await new GetCardDiff(dbContext.AsCallContext()).RunAsync(diffRequest); Assert.AreEqual(userName, result.CurrentVersionCreator); Assert.AreEqual(userName, result.OriginalVersionCreator); Assert.AreEqual(newVersionDate, result.CurrentVersionUtcDate); Assert.AreEqual(originalVersionDate, result.OriginalVersionUtcDate); Assert.AreEqual(newVersionDescription, result.CurrentVersionDescription); Assert.AreEqual(originalVersionDescription, result.OriginalVersionDescription); Assert.AreEqual(new(newVersionImageName, originalVersionImageName), result.ImagesOnAdditionalSide); Assert.AreEqual(new(newFrontSide, originalFrontSide), result.FrontSide); Assert.AreEqual(new(newBackSide, originalBackSide), result.BackSide); var expectedTagDiffString = string.Join(",", new[] { originalTagName1, originalTagName2 }.OrderBy(s => s)); Assert.AreEqual(new(originalTagName1, expectedTagDiffString), result.Tags); Assert.IsNull(result.Language); Assert.IsNull(result.AdditionalInfo); Assert.IsNull(result.UsersWithView); Assert.IsNull(result.ImagesOnFrontSide); Assert.IsNull(result.ImagesOnBackSide); } }
public async Task FrontDiff() { var db = DbHelper.GetEmptyTestDB(); var userName = RandomHelper.String(); var userId = await UserHelper.CreateInDbAsync(db, userName : userName); var originalVersionDate = RandomHelper.Date(); var originalFrontSide = RandomHelper.String(); var originalVersionDescription = RandomHelper.String(); var language = await CardLanguagHelper.CreateAsync(db); var card = await CardHelper.CreateAsync(db, userId, originalVersionDate, frontSide : originalFrontSide, language : language, versionDescription : originalVersionDescription); var newFrontSide = RandomHelper.String(); var newVersionDate = RandomHelper.Date(originalVersionDate); var newVersionDescription = RandomHelper.String(); using (var dbContext = new MemCheckDbContext(db)) await new UpdateCard(dbContext.AsCallContext(), newVersionDate).RunAsync(UpdateCardHelper.RequestForFrontSideChange(card, newFrontSide, versionDescription: newVersionDescription)); Guid previousVersionId; using (var dbContext = new MemCheckDbContext(db)) previousVersionId = (await dbContext.CardPreviousVersions.Where(previous => previous.Card == card.Id).SingleAsync()).Id; using (var dbContext = new MemCheckDbContext(db)) { var diffRequest = new GetCardDiff.Request(userId, card.Id, previousVersionId); var result = await new GetCardDiff(dbContext.AsCallContext()).RunAsync(diffRequest); Assert.AreEqual(userName, result.CurrentVersionCreator); Assert.AreEqual(userName, result.OriginalVersionCreator); Assert.AreEqual(newVersionDate, result.CurrentVersionUtcDate); Assert.AreEqual(originalVersionDate, result.OriginalVersionUtcDate); Assert.AreEqual(newVersionDescription, result.CurrentVersionDescription); Assert.AreEqual(originalVersionDescription, result.OriginalVersionDescription); Assert.AreEqual(new(newFrontSide, originalFrontSide), result.FrontSide); Assert.IsNull(result.Language); Assert.IsNull(result.BackSide); Assert.IsNull(result.AdditionalInfo); Assert.IsNull(result.Tags); Assert.IsNull(result.UsersWithView); Assert.IsNull(result.ImagesOnFrontSide); Assert.IsNull(result.ImagesOnBackSide); Assert.IsNull(result.ImagesOnAdditionalSide); } }
public async Task CountOfCardsNotFoundAnymore_Deleted_UserNotAllowedToView() { var db = DbHelper.GetEmptyTestDB(); var cardCreator = await UserHelper.CreateInDbAsync(db); var language = await CardLanguagHelper.CreateAsync(db); var card = await CardHelper.CreateAsync(db, cardCreator, versionDate : new DateTime(2050, 03, 01), language : language); var subscriber = await UserHelper.CreateInDbAsync(db); var subscription = await SearchSubscriptionHelper.CreateAsync(db, subscriber); using (var dbContext = new MemCheckDbContext(db)) { var searchResult = await new UserSearchNotifier(dbContext.AsCallContext(), 100, new DateTime(2050, 05, 01)).RunAsync(subscription.Id); Assert.AreEqual(1, searchResult.TotalNewlyFoundCardCount); } //Create a previous version on which subscriber can see the card using (var dbContext = new MemCheckDbContext(db)) { var updateRequest = UpdateCardHelper.RequestForFrontSideChange(card, RandomHelper.String()); await new UpdateCard(dbContext.AsCallContext(), new DateTime(2050, 05, 02)).RunAsync(updateRequest); } //So this version does not appear as new in a search using (var dbContext = new MemCheckDbContext(db)) { var searchResult = await new UserSearchNotifier(dbContext.AsCallContext(), 100, new DateTime(2050, 05, 03)).RunAsync(subscription.Id); Assert.AreEqual(0, searchResult.TotalNewlyFoundCardCount); Assert.AreEqual(0, searchResult.NewlyFoundCards.Length); Assert.AreEqual(0, searchResult.CountOfCardsNotFoundAnymore_StillExists_UserAllowedToView); Assert.AreEqual(0, searchResult.CardsNotFoundAnymore_StillExists_UserAllowedToView.Length); Assert.AreEqual(0, searchResult.CountOfCardsNotFoundAnymore_Deleted_UserAllowedToView); Assert.AreEqual(0, searchResult.CardsNotFoundAnymore_Deleted_UserAllowedToView.Length); Assert.AreEqual(0, searchResult.CountOfCardsNotFoundAnymore_StillExists_UserNotAllowedToView); Assert.AreEqual(0, searchResult.CountOfCardsNotFoundAnymore_Deleted_UserNotAllowedToView); } //Create a previous version which prevents subscriber from seing the card using (var dbContext = new MemCheckDbContext(db)) { var updateRequest = UpdateCardHelper.RequestForVisibilityChange(card, cardCreator.AsArray()); await new UpdateCard(dbContext.AsCallContext(), new DateTime(2050, 05, 02)).RunAsync(updateRequest); } //Delete the card using (var dbContext = new MemCheckDbContext(db)) { var deletionRequest = new DeleteCards.Request(cardCreator, card.Id.AsArray()); await new DeleteCards(dbContext.AsCallContext()).RunAsync(deletionRequest); } var runDate = new DateTime(2050, 05, 03); //Now the card must be reported as disappeard using (var dbContext = new MemCheckDbContext(db)) { var searchResult = await new UserSearchNotifier(dbContext.AsCallContext(), 100, runDate).RunAsync(subscription.Id); Assert.AreEqual(0, searchResult.TotalNewlyFoundCardCount); Assert.AreEqual(0, searchResult.NewlyFoundCards.Length); Assert.AreEqual(0, searchResult.CountOfCardsNotFoundAnymore_StillExists_UserAllowedToView); Assert.AreEqual(0, searchResult.CardsNotFoundAnymore_StillExists_UserAllowedToView.Length); Assert.AreEqual(0, searchResult.CountOfCardsNotFoundAnymore_Deleted_UserAllowedToView); Assert.AreEqual(0, searchResult.CardsNotFoundAnymore_Deleted_UserAllowedToView.Length); Assert.AreEqual(0, searchResult.CountOfCardsNotFoundAnymore_StillExists_UserNotAllowedToView); Assert.AreEqual(1, searchResult.CountOfCardsNotFoundAnymore_Deleted_UserNotAllowedToView); } using (var dbContext = new MemCheckDbContext(db)) Assert.AreEqual(runDate, dbContext.SearchSubscriptions.Single(s => s.Id == subscription.Id).LastRunUtcDate); }