public async Task UpdateDescription()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var name       = RandomHelper.String();
            var source     = RandomHelper.String();
            var uploadDate = RandomHelper.Date();
            var image      = await ImageHelper.CreateAsync(db, user, name : name, source : source, lastChangeUtcDate : uploadDate);

            var newDescription     = RandomHelper.String();
            var runDate            = RandomHelper.Date(uploadDate);
            var versionDescription = RandomHelper.String();

            using (var dbContext = new MemCheckDbContext(db))
            {
                var request = new UpdateImageMetadata.Request(image, user, name, source, newDescription, versionDescription);
                await new UpdateImageMetadata(dbContext.AsCallContext(), runDate).RunAsync(request);
            }

            using (var dbContext = new MemCheckDbContext(db))
            {
                var fromDb = await dbContext.Images.Include(img => img.Owner).SingleAsync();

                Assert.AreEqual(image, fromDb.Id);
                Assert.AreEqual(name, fromDb.Name);
                Assert.AreEqual(user, fromDb.Owner.Id);
                Assert.AreEqual(newDescription, fromDb.Description);
                Assert.AreEqual(source, fromDb.Source);
                Assert.AreEqual(uploadDate, fromDb.InitialUploadUtcDate);
                Assert.AreEqual(runDate, fromDb.LastChangeUtcDate);
                Assert.AreEqual(versionDescription, fromDb.VersionDescription);
                Assert.AreEqual(ImageVersionType.Changes, fromDb.VersionType);
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> Update(Guid imageId, [FromBody] UpdateRequestModel request)
        {
            if (request.ImageName == null)
            {
                return(BadRequest(UploadImageResultViewModel.Failure(localizer["NameNotSet"].Value, false, localizer)));
            }
            if (request.Description == null)
            {
                return(BadRequest(UploadImageResultViewModel.Failure(localizer["DescriptionNotSet"].Value, false, localizer)));
            }
            if (request.Source == null)
            {
                return(BadRequest(UploadImageResultViewModel.Failure(localizer["SourceNotSet"].Value, false, localizer)));
            }
            if (request.VersionDescription == null)
            {
                return(BadRequest(UploadImageResultViewModel.Failure(localizer["VersionDescriptionNotSet"].Value, false, localizer)));
            }

            try
            {
                var user = await userManager.GetUserAsync(HttpContext.User);

                var applicationRequest = new UpdateImageMetadata.Request(imageId, user, request.ImageName, request.Source, request.Description, request.VersionDescription);
                await new UpdateImageMetadata(dbContext, localizer).RunAsync(applicationRequest);
                var toastText = $"{localizer["SuccessfullyUpdatedImage"]} '{request.ImageName}'";
                return(Ok(new { ToastText = toastText, ToastTitle = localizer["Success"] }));
            }
            catch (Exception e)
            {
                return(ControllerError.BadRequest(e, this));
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> Update(Guid imageId, [FromBody] UpdateRequestModel request)
        {
            CheckBodyParameter(request);
            var userId = await UserServices.UserIdFromContextAsync(HttpContext, userManager);

            var applicationRequest = new UpdateImageMetadata.Request(imageId, userId, request.ImageName, request.Source, request.Description, request.VersionDescription);

            await new UpdateImageMetadata(callContext).RunAsync(applicationRequest);
            var toastText = $"{Get("SuccessfullyUpdatedImage")} '{request.ImageName}'";

            return(ControllerResultWithToast.Success(toastText, this));
        }
        public async Task NameAlreadyUsed()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var name = RandomHelper.String();
            await ImageHelper.CreateAsync(db, user, name : name);

            var imageToRename = await ImageHelper.CreateAsync(db, user);

            using var dbContext = new MemCheckDbContext(db);
            var request = new UpdateImageMetadata.Request(imageToRename, user, name, RandomHelper.String(), RandomHelper.String(), RandomHelper.String());
            await Assert.ThrowsExceptionAsync <RequestInputException>(async() => await new UpdateImageMetadata(dbContext.AsCallContext()).RunAsync(request));
        }
        public async Task NoChange()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var name        = RandomHelper.String();
            var source      = RandomHelper.String();
            var description = RandomHelper.String();
            var image       = await ImageHelper.CreateAsync(db, user, name : name, source : source, description : description);

            using var dbContext = new MemCheckDbContext(db);
            var request = new UpdateImageMetadata.Request(image, user, name, source, description, RandomHelper.String());
            await Assert.ThrowsExceptionAsync <RequestInputException>(async() => await new UpdateImageMetadata(dbContext.AsCallContext()).RunAsync(request));
        }
        public async Task UpdateByAnotherUser()
        {
            var db   = DbHelper.GetEmptyTestDB();
            var user = await UserHelper.CreateInDbAsync(db);

            var image = await ImageHelper.CreateAsync(db, user);

            var otherUser = await UserHelper.CreateInDbAsync(db);

            using (var dbContext = new MemCheckDbContext(db))
            {
                var request = new UpdateImageMetadata.Request(image, otherUser, RandomHelper.String(), RandomHelper.String(), RandomHelper.String(), RandomHelper.String());
                await new UpdateImageMetadata(dbContext.AsCallContext()).RunAsync(request);
            }

            using (var dbContext = new MemCheckDbContext(db))
            {
                var fromDb = await dbContext.Images.Include(img => img.Owner).SingleAsync();

                Assert.AreEqual(image, fromDb.Id);
                Assert.AreEqual(otherUser, fromDb.Owner.Id);
            }
        }