Exemplo n.º 1
0
        public ActionResult <CustomResponseModel> UpdateSong([FromForm] SongUpdateModel songUpdateModel, [Required] string songId)
        {
            string labelId = new SongDataAccess().JwtTokenValidation(songUpdateModel.JwtToken);

            if (labelId == "")
            {
                return(Unauthorized(new CustomResponseModel()
                {
                    Code = "401", Phrase = "Unauthorized", Message = "Invalid Jwt Token"
                }));
            }
            if (new SongDataAccess().IsLabel(labelId))
            {
                songUpdateModel.SongId = songId;
                if (new SongDataAccess().UpdateSong(songUpdateModel))
                {
                    return(Ok(new CustomResponseModel()
                    {
                        Code = "200", Phrase = "OK", Message = "Song Updated"
                    }));
                }
            }
            else
            {
                return(Unauthorized(new CustomResponseModel()
                {
                    Code = "401", Phrase = "Unauthorized", Message = "Song Updater Must be a Label"
                }));
            }
            return(BadRequest(new CustomResponseModel()
            {
                Code = "400", Phrase = "BadRequest", Message = "Song Update Failed"
            }));
        }
Exemplo n.º 2
0
        public async Task <Song> InsertAsync(SongUpdateModel song)
        {
            var result = await Context.AddAsync(Mapper.Map <DataAccess.Entities.Song>(song));

            await Context.SaveChangesAsync();

            return(Mapper.Map <Song>(result.Entity));
        }
Exemplo n.º 3
0
        public async Task EditSong(SongUpdateModel songModel)
        {
            var json = JsonSerializer.Serialize <SongUpdateModel>(songModel);

            Console.WriteLine(json);
            var content = new StringContent(json, Encoding.UTF8, "application/json-patch+json");
            await HttpClient.PatchAsync("api/v1/song/", content);
        }
Exemplo n.º 4
0
        public async Task <Song> UpdateAsync(SongUpdateModel song)
        {
            var existing = await Get(song);

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

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

            return(Mapper.Map <Song>(result));
        }
        public async Task CreateAsyncSuccessful()
        {
            var song     = new SongUpdateModel();
            var expected = new Song();

            var albumGetService = new Mock <IAlbumGetService>();

            albumGetService.Setup(x => x.ValidateAsync(song));

            var songDataAccess = new Mock <ISongDataAccess>();

            songDataAccess.Setup(x => x.InsertAsync(song)).ReturnsAsync(expected);

            var songCreateService = new SongCreateService(songDataAccess.Object, albumGetService.Object);

            var result = await songCreateService.CreateAsync(song);

            result.Should().Be(expected);
        }
Exemplo n.º 6
0
        public async Task CreateAsync_AlbumValidationSucceed_CreatesSong()
        {
            // Arrange
            var songUpdateModel = new SongUpdateModel();
            var expected        = new Song();

            var albumGetService = new Mock <IAlbumGetService>();

            albumGetService.Setup(x => x.ValidateAsync(songUpdateModel));

            var songDataAccess = new Mock <ISongDataAccess>();

            songDataAccess.Setup(x => x.InsertAsync(songUpdateModel)).ReturnsAsync(expected);

            var songCreateService = new SongCreateService(songDataAccess.Object, albumGetService.Object);

            // Act
            var result = await songCreateService.CreateAsync(songUpdateModel);

            // Assert
            result.Should().Be(expected);
        }
        public async Task CreateAsyncFailed()
        {
            var fixture  = new Fixture();
            var song     = new SongUpdateModel();
            var expected = fixture.Create <string>();

            var albumGetService = new Mock <IAlbumGetService>();

            albumGetService
            .Setup(x => x.ValidateAsync(song))
            .Throws(new InvalidOperationException(expected));

            var songDataAccess = new Mock <ISongDataAccess>();

            var songCreateService = new SongCreateService(songDataAccess.Object, albumGetService.Object);

            var action = new Func <Task>(() => songCreateService.CreateAsync(song));

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

            songDataAccess.Verify(x => x.InsertAsync(song), Times.Never);
        }
Exemplo n.º 8
0
 public async Task<Song> CreateAsync(SongUpdateModel song)
 {
     await AlbumGetService.ValidateAsync(song);
     return await SongDataAccess.InsertAsync(song);
 }
Exemplo n.º 9
0
        public async Task <Song> UpdateAsync(SongUpdateModel song)
        {
            await AlbumGetService.ValidateAsync(song);

            return(await SongDataAccess.UpdateAsync(song));
        }