public async Task TestOtherUserCreatesVersion() { var testDB = DbHelper.GetEmptyTestDB(); var ownerId = await UserHelper.CreateInDbAsync(testDB); var card = await CardHelper.CreateAsync(testDB, ownerId); var newVersionCreatorId = await UserHelper.CreateInDbAsync(testDB, subscribeToCardOnEdit : true); using (var dbContext = new MemCheckDbContext(testDB)) { var request = new PreviousVersionCreator(dbContext); await request.RunAsync(card.Id, newVersionCreatorId, RandomHelper.String()); await dbContext.SaveChangesAsync(); } using (var dbContext = new MemCheckDbContext(testDB)) { var previousVersion = await dbContext.CardPreviousVersions.Where(previous => previous.Card == card.Id).SingleAsync(); Assert.AreNotEqual(card.Id, previousVersion.Id); } Assert.IsTrue(await CardSubscriptionHelper.UserIsSubscribedToCardAsync(testDB, newVersionCreatorId, card.Id)); }
public async Task WithUserSubscribingToCardOnEdit() { var testDB = DbHelper.GetEmptyTestDB(); var ownerId = await UserHelper.CreateInDbAsync(testDB, subscribeToCardOnEdit : true); var languageId = await CardLanguagHelper.CreateAsync(testDB); Guid cardGuid = Guid.Empty; using (var dbContext = new MemCheckDbContext(testDB)) { var request = new CreateCard.Request( ownerId, RandomHelper.String(), Array.Empty <Guid>(), RandomHelper.String(), Array.Empty <Guid>(), RandomHelper.String(), Array.Empty <Guid>(), languageId, Array.Empty <Guid>(), Array.Empty <Guid>(), RandomHelper.String()); cardGuid = (await new CreateCard(dbContext.AsCallContext()).RunAsync(request)).CardId; } Assert.IsTrue(await CardSubscriptionHelper.UserIsSubscribedToCardAsync(testDB, ownerId, cardGuid)); }
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 WithAllData() { var testDB = DbHelper.GetEmptyTestDB(); var userWithViewId = await UserHelper.CreateInDbAsync(testDB); var ownerId = await UserHelper.CreateInDbAsync(testDB, subscribeToCardOnEdit : false); var frontSide = RandomHelper.String(); var backSide = RandomHelper.String(); var additionalInfo = RandomHelper.String(); var versionDescription = RandomHelper.String(); var languageId = await CardLanguagHelper.CreateAsync(testDB); var imageOnFrontSideId = await ImageHelper.CreateAsync(testDB, ownerId); var imageOnBackSide1Id = await ImageHelper.CreateAsync(testDB, ownerId); var imageOnBackSide2Id = await ImageHelper.CreateAsync(testDB, ownerId); var imageOnAdditionalInfoId = await ImageHelper.CreateAsync(testDB, ownerId); var tagId = await TagHelper.CreateAsync(testDB); Guid cardGuid = Guid.Empty; using (var dbContext = new MemCheckDbContext(testDB)) { var request = new CreateCard.Request( ownerId, frontSide, new Guid[] { imageOnFrontSideId }, backSide, new Guid[] { imageOnBackSide1Id, imageOnBackSide2Id }, additionalInfo, new Guid[] { imageOnAdditionalInfoId }, languageId, new Guid[] { tagId }, new Guid[] { ownerId, userWithViewId }, versionDescription); cardGuid = (await new CreateCard(dbContext.AsCallContext()).RunAsync(request)).CardId; Assert.AreNotEqual(Guid.Empty, cardGuid); } using (var dbContext = new MemCheckDbContext(testDB)) { var card = dbContext.Cards .Include(c => c.VersionCreator) .Include(c => c.CardLanguage) .Include(c => c.UsersWithView) .Include(c => c.Images) .Include(c => c.TagsInCards) .Single(c => c.Id == cardGuid); Assert.AreEqual(ownerId, card.VersionCreator.Id); Assert.AreEqual(frontSide, card.FrontSide); Assert.AreEqual(backSide, card.BackSide); Assert.AreEqual(additionalInfo, card.AdditionalInfo); Assert.AreEqual(versionDescription, card.VersionDescription); Assert.AreEqual(languageId, card.CardLanguage.Id); Assert.IsTrue(card.UsersWithView.Any(u => u.UserId == ownerId)); Assert.IsTrue(card.UsersWithView.Any(u => u.UserId == userWithViewId)); Assert.AreEqual(ImageInCard.FrontSide, card.Images.Single(i => i.ImageId == imageOnFrontSideId).CardSide); Assert.AreEqual(ImageInCard.BackSide, card.Images.Single(i => i.ImageId == imageOnBackSide1Id).CardSide); Assert.AreEqual(ImageInCard.BackSide, card.Images.Single(i => i.ImageId == imageOnBackSide2Id).CardSide); Assert.AreEqual(ImageInCard.AdditionalInfo, card.Images.Single(i => i.ImageId == imageOnAdditionalInfoId).CardSide); Assert.IsTrue(card.TagsInCards.Any(t => t.TagId == tagId)); Assert.AreEqual(0, card.RatingCount); Assert.AreEqual(0, card.AverageRating); } Assert.IsFalse(await CardSubscriptionHelper.UserIsSubscribedToCardAsync(testDB, ownerId, cardGuid)); }