Exemplo n.º 1
0
        public async Task CreateAsync_ArtistValidationFailed_ThrowsError()
        {
            // Arrange
            var fixture          = new Fixture();
            var albumUpdateModel = new AlbumUpdateModel();
            var expected         = fixture.Create <string>();

            var artistGetService = new Mock <IArtistGetService>();

            artistGetService
            .Setup(x => x.ValidateAsync(albumUpdateModel))
            .Throws(new InvalidOperationException(expected));

            var albumDataAccess = new Mock <IAlbumDataAccess>();

            var albumCreateService = new AlbumCreateService(albumDataAccess.Object, artistGetService.Object);

            // Act
            var action = new Func <Task>(() => albumCreateService.CreateAsync(albumUpdateModel));

            // Assert
            await action.Should().ThrowAsync <InvalidOperationException>().WithMessage(expected);

            albumDataAccess.Verify(x => x.InsertAsync(albumUpdateModel), Times.Never);
        }
Exemplo n.º 2
0
        //UPDATE ALBUM
        public bool UpdateAlbum(AlbumUpdateModel albumUpdateModel)
        {
            if (albumUpdateModel.CoverImage != null)
            {
                albumUpdateModel.CoverImageUrl = UploadAlbumCoverImage(albumUpdateModel.CoverImage, albumUpdateModel.Id);
            }
            else
            {
                albumUpdateModel.CoverImageUrl = null;
            }
            var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("albums");
            var filter     = Builders <BsonDocument> .Filter.Eq("AlbumId", albumUpdateModel.Id) & Builders <BsonDocument> .Filter.Eq("LabelId", albumUpdateModel.LabelId);

            var update = Builders <BsonDocument> .Update.Set("AlbumId", albumUpdateModel.Id);

            foreach (PropertyInfo prop in albumUpdateModel.GetType().GetProperties())
            {
                var value = albumUpdateModel.GetType().GetProperty(prop.Name).GetValue(albumUpdateModel, null);
                if ((prop.Name != "Id") && (prop.Name != "JwtToken") && (prop.Name != "CoverImage"))
                {
                    if (value != null)
                    {
                        update = update.Set(prop.Name, value);
                    }
                }
            }
            if (collection.UpdateOne(filter, update).ModifiedCount > 0)
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 3
0
 public ActionResult <CustomResponseModel> UpdateAlbum([FromForm] AlbumUpdateModel albumUpdateModel, [Required] string albumId)
 {
     albumUpdateModel.LabelId = new AlbumDataAccess().JwtTokenValidation(albumUpdateModel.JwtToken);
     albumUpdateModel.Id      = albumId;
     if (albumUpdateModel.LabelId == "")
     {
         return(Unauthorized(new CustomResponseModel()
         {
             Code = "401", Phrase = "Unauthorized", Message = "Invalid Jwt Token"
         }));
     }
     if (new AlbumDataAccess().IsLabel(albumUpdateModel.LabelId))
     {
         if (new AlbumDataAccess().UpdateAlbum(albumUpdateModel))
         {
             return(Ok(new CustomResponseModel()
             {
                 Code = "200", Phrase = "OK", Message = "Album Updated"
             }));
         }
     }
     return(BadRequest(new CustomResponseModel()
     {
         Code = "400", Phrase = "BadRequest", Message = "Album Updation Failed"
     }));
 }
Exemplo n.º 4
0
        public async Task <Album> InsertAsync(AlbumUpdateModel album)
        {
            var result = await Context.AddAsync(Mapper.Map <DataAccess.Entities.Album>(album));

            await Context.SaveChangesAsync();

            return(Mapper.Map <Album>(result.Entity));
        }
Exemplo n.º 5
0
        public async Task <ActionResult> PutAlbum([FromRoute] int albumId, [FromBody] AlbumUpdateModel albumUpdateModel)
        {
            var albumUpdateDTO = mapper.Map <AlbumUpdateDTO>(albumUpdateModel,
                                                             opt => { opt.Items["albumId"] = albumId; opt.Items["userId"] = UserId; });

            await albumService.UpdateAlbumAsync(albumUpdateDTO);

            return(Ok());
        }
Exemplo n.º 6
0
        public async Task <Album> UpdateAsync(AlbumUpdateModel album)
        {
            var existing = await Get(album);

            var result = Mapper.Map(album, existing);

            Context.Update(result);
            await Context.SaveChangesAsync();

            return(Mapper.Map <Album>(result));
        }
        public void PutAlbum_Should_ReturnOk()
        {
            var albumId    = 1;
            var albumModel = new AlbumUpdateModel {
                Name = "name", Description = "desc"
            };

            mockService.Setup(s => s.UpdateAlbumAsync(It.Is <AlbumUpdateDTO>(dto =>
                                                                             dto.Name == albumModel.Name && dto.Description == albumModel.Description))).Verifiable();

            controller.PutAlbum(albumId, albumModel).Result.Should().BeOfType <OkResult>();
            mockService.Verify();
        }
Exemplo n.º 8
0
        public HttpStatusCode Update(FormCollection formCollection)
        {
            AlbumUpdateModel albumUpdateModel = new AlbumUpdateModel();
            string           jsonString       = formCollection["albumEdit"];

            albumUpdateModel = JsonConvert.DeserializeObject <AlbumUpdateModel>(jsonString);
            PhotoAlbum album = new PhotoAlbum();

            album.Description  = albumUpdateModel.AlbumDescription;
            album.Title        = albumUpdateModel.AlbumName;
            album.PhotoAlbumId = albumUpdateModel.AlbumId;

            if (photoAlbumsDb.Update(album))
            {
                return(HttpStatusCode.OK);
            }
            else
            {
                return(HttpStatusCode.BadRequest);
            }
        }
Exemplo n.º 9
0
        public async Task CreateAsync_ArtistValidationSucceed_CreatesAlbum()
        {
            // Arrange
            var albumUpdateModel = new AlbumUpdateModel();
            var expected         = new Album();

            var artistGetService = new Mock <IArtistGetService>();

            artistGetService.Setup(x => x.ValidateAsync(albumUpdateModel));

            var albumDataAccess = new Mock <IAlbumDataAccess>();

            albumDataAccess.Setup(x => x.InsertAsync(albumUpdateModel)).ReturnsAsync(expected);

            var albumCreateService = new AlbumCreateService(albumDataAccess.Object, artistGetService.Object);

            // Act
            var result = await albumCreateService.CreateAsync(albumUpdateModel);

            // Assert
            result.Should().Be(expected);
        }
Exemplo n.º 10
0
 public async Task <RequestEngineResult> MarkUnAvailable([FromBody] AlbumUpdateModel model)
 {
     return(await _engine.MarkUnavailable(model.Id));
 }
Exemplo n.º 11
0
 public async Task <RequestEngineResult> ApproveAlbum([FromBody] AlbumUpdateModel model)
 {
     return(await _engine.ApproveAlbumById(model.Id));
 }
Exemplo n.º 12
0
        public async Task <Album> UpdateAsync(AlbumUpdateModel album)
        {
            await ArtistGetService.ValidateAsync(album);

            return(await AlbumDataAccess.UpdateAsync(album));
        }
Exemplo n.º 13
0
 public Task <Album> UpdateAsync(AlbumUpdateModel album)
 {
     return(AlbumDataAccess.UpdateAsync(album));
 }
Exemplo n.º 14
0
 public Task <Album> CreateAsync(AlbumUpdateModel album)
 {
     return(AlbumDataAccess.InsertAsync(album));
 }