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

            var card = await CardHelper.CreateAsync(db, user);

            await CardDeletionHelper.DeleteCardAsync(db, user, card.Id);

            await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await CardDeletionHelper.DeleteCardAsync(db, user, card.Id));
        }
Esempio n. 2
0
        public async Task DeletingMustNotDeleteCardNotifications()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var card = await CardHelper.CreateAsync(db, user, new DateTime(2020, 11, 1));

            await CardSubscriptionHelper.CreateAsync(db, user, card.Id);

            using (var dbContext = new MemCheckDbContext(db))
                Assert.AreEqual(1, dbContext.CardNotifications.Count());

            await CardDeletionHelper.DeleteCardAsync(db, user, card.Id, new DateTime(2020, 11, 2));

            using (var dbContext = new MemCheckDbContext(db))
                Assert.AreEqual(1, dbContext.CardNotifications.Count());
        }
Esempio n. 3
0
        public async Task DeleteSuccessfully()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var language = await CardLanguagHelper.CreateAsync(db);

            var creationDate = RandomHelper.Date();
            var card         = await CardHelper.CreateAsync(db, user, language : language, versionDate : creationDate);

            var deletionDate = RandomHelper.Date();
            await CardDeletionHelper.DeleteCardAsync(db, user, card.Id, deletionDate);

            using var dbContext = new MemCheckDbContext(db);
            Assert.IsFalse(dbContext.Cards.Any());
            Assert.AreEqual(2, dbContext.CardPreviousVersions.Count());

            Assert.AreEqual(1, dbContext.CardPreviousVersions.Count(version => version.Card == card.Id && version.PreviousVersion == null));

            var firstVersion = dbContext.CardPreviousVersions
                               .Include(version => version.VersionCreator)
                               .Include(version => version.CardLanguage)
                               .Include(version => version.Tags)
                               .Include(version => version.UsersWithView)
                               .Include(version => version.Images)
                               .Single(version => version.Card == card.Id && version.PreviousVersion == null);

            Assert.AreEqual(CardPreviousVersionType.Creation, firstVersion.VersionType);
            CardComparisonHelper.AssertSameContent(card, firstVersion, true);
            Assert.AreEqual(creationDate, firstVersion.VersionUtcDate);

            var deletionVersion = dbContext.CardPreviousVersions
                                  .Include(version => version.VersionCreator)
                                  .Include(version => version.CardLanguage)
                                  .Include(version => version.Tags)
                                  .Include(version => version.UsersWithView)
                                  .Include(version => version.Images)
                                  .Single(version => version.Card == card.Id && version.PreviousVersion != null);

            Assert.AreEqual(CardPreviousVersionType.Deletion, deletionVersion.VersionType);
            Assert.AreEqual(firstVersion.Id, deletionVersion.PreviousVersion !.Id);
            CardComparisonHelper.AssertSameContent(card, deletionVersion, true);
            Assert.AreEqual(deletionDate, deletionVersion.VersionUtcDate);
        }
Esempio n. 4
0
        public async Task DeleteNonExistingCard()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await CardDeletionHelper.DeleteCardAsync(db, user, Guid.NewGuid()));
        }
Esempio n. 5
0
        public async Task FailIfUserDoesNotExist()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var card = await CardHelper.CreateAsync(db, user);

            using var dbContext = new MemCheckDbContext(db);
            var e = await Assert.ThrowsExceptionAsync <InvalidOperationException>(async() => await CardDeletionHelper.DeleteCardAsync(db, Guid.NewGuid(), card.Id));

            Assert.AreEqual("User not found", e.Message);
        }