Example #1
0
        public async Task AdditionalSideImageDiff()
        {
            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 card = await CardHelper.CreateAsync(db, userId, originalVersionDate, language : language, additionalSideImages : originalVersionImage.AsArray(), versionDescription : originalVersionDescription);

            var newVersionDate        = RandomHelper.Date(originalVersionDate);
            var newVersionDescription = RandomHelper.String();
            var newVersionImageName   = RandomHelper.String();
            var newVersionImage       = await ImageHelper.CreateAsync(db, userId, newVersionImageName);

            using (var dbContext = new MemCheckDbContext(db))
                await new UpdateCard(dbContext.AsCallContext(), newVersionDate).RunAsync(UpdateCardHelper.RequestForAdditionalSideImageChange(card, newVersionImage.AsArray(), 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(newVersionImageName, originalVersionImageName), result.ImagesOnAdditionalSide);
                Assert.IsNull(result.FrontSide);
                Assert.IsNull(result.BackSide);
                Assert.IsNull(result.Language);
                Assert.IsNull(result.AdditionalInfo);
                Assert.IsNull(result.Tags);
                Assert.IsNull(result.UsersWithView);
                Assert.IsNull(result.ImagesOnFrontSide);
                Assert.IsNull(result.ImagesOnBackSide);
            }
        }