Esempio n. 1
0
        public async Task PrivateCardDeletedWhileOthersExist()
        {
            var db         = DbHelper.GetEmptyTestDB();
            var loggedUser = await UserHelper.CreateInDbAsync(db);

            var language = await CardLanguagHelper.CreateAsync(db);

            var userToDelete = await UserHelper.CreateInDbAsync(db);

            var privateCardToDelete = await CardHelper.CreateAsync(db, userToDelete, language : language, userWithViewIds : userToDelete.AsArray());

            await UpdateCardHelper.RunAsync(db, UpdateCardHelper.RequestForBackSideChange(privateCardToDelete, RandomHelper.String()));

            var privateCardNotToDelete = await CardHelper.CreateAsync(db, loggedUser, language : language, userWithViewIds : loggedUser.AsArray());

            await UpdateCardHelper.RunAsync(db, UpdateCardHelper.RequestForBackSideChange(privateCardNotToDelete, RandomHelper.String()));

            var publicCard = await CardHelper.CreateAsync(db, userToDelete, language : language);

            await UpdateCardHelper.RunAsync(db, UpdateCardHelper.RequestForBackSideChange(publicCard, RandomHelper.String()));

            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.IsFalse(dbContext.Cards.Any(card => card.Id == privateCardToDelete.Id));
                Assert.IsFalse(dbContext.CardPreviousVersions.Any(previousVersion => previousVersion.Card == privateCardToDelete.Id));
                Assert.IsTrue(dbContext.Cards.Any(card => card.Id == privateCardNotToDelete.Id));
                Assert.IsTrue(dbContext.CardPreviousVersions.Any(previousVersion => previousVersion.Card == privateCardNotToDelete.Id));
                Assert.IsTrue(dbContext.Cards.Any(card => card.Id == publicCard.Id));
                Assert.IsTrue(dbContext.CardPreviousVersions.Any(previousVersion => previousVersion.Card == publicCard.Id));
            }
        }
Esempio n. 2
0
        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());
            }
        }
    }
Esempio n. 3
0
        public async Task BackDiff()
        {
            var db       = DbHelper.GetEmptyTestDB();
            var userName = RandomHelper.String();
            var userId   = await UserHelper.CreateInDbAsync(db, userName : userName);

            var originalVersionDate        = RandomHelper.Date();
            var originalBackSide           = RandomHelper.String();
            var originalVersionDescription = RandomHelper.String();
            var language = await CardLanguagHelper.CreateAsync(db);

            var card = await CardHelper.CreateAsync(db, userId, originalVersionDate, backSide : originalBackSide, language : language, versionDescription : originalVersionDescription);

            var newBackSide           = 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.RequestForBackSideChange(card, newBackSide, 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(newBackSide, originalBackSide), result.BackSide);
                Assert.IsNull(result.Language);
                Assert.IsNull(result.FrontSide);
                Assert.IsNull(result.AdditionalInfo);
                Assert.IsNull(result.Tags);
                Assert.IsNull(result.UsersWithView);
                Assert.IsNull(result.ImagesOnFrontSide);
                Assert.IsNull(result.ImagesOnBackSide);
                Assert.IsNull(result.ImagesOnAdditionalSide);
            }
        }
Esempio n. 4
0
        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);
            }
        }