public async Task ShouldUpdateAlbum()
        {
            var existingItem = await SendAsync(new FetchAlbumDetailByNameQuery { Name = testAlbum.Name });

            var command = new UpdateAlbumCommand
            {
                Artist = "ArtistUpdated",
                Label  = "LabelUpdated",
                Name   = "ITestUpdatedAlbum-" + DateTime.Now.ToString(),
                Stock  = 10,
                TypeId = 2,
                Id     = existingItem.Id
            };

            await SendAsync(command);

            var result = await SendAsync(new FetchAlbumDetailByIdQuery { Id = existingItem.Id });

            Assert.NotNull(result);
            Assert.Equal(command.Name, result.Name);
            Assert.Equal(command.Label, result.Label);
            Assert.Equal(command.Stock, result.Stock);
            Assert.Equal(command.TypeId, result.TypeId);
            Assert.Equal(command.Artist, result.Artist);
        }
示例#2
0
        public ICommandResult Handle(UpdateAlbumCommand command)
        {
            var categoryQuery = _categoryRepository.GetById(command.CategoryId);
            var genderQuery   = _genderRepository.GetById(command.GenderId);

            Gender   gender   = new Gender(genderQuery.Id, genderQuery.Title, genderQuery.Description);
            Category category = new Category(categoryQuery.Id, categoryQuery.Title, categoryQuery.Description);
            Album    album    = new Album(command.Id, command.Title, gender, category, command.Image);

            AddNotifications(album.Notifications);

            if (Invalid)
            {
                return(new CommandResult(false, MessagesUtil.FormFail, Notifications));
            }

            bool result = _repository.Update(album);

            if (!result)
            {
                return(new CommandResult(false, MessagesUtil.UpdateError, Notifications));
            }

            return(new CommandResult(true, MessagesUtil.CreatedSuccess));
        }
示例#3
0
        public async void UpdateAlbumCommand_ShouldUpdateEntryInDatabase()
        {
            //Arange
            var mapper          = new Mock <IMapper>();
            var albumRepository = new Mock <IAlbumRepository>();

            var command = new UpdateAlbumCommand
            {
                Artist = "test",
                Label  = "hello",
                Name   = "Robot",
                Stock  = 1,
                TypeId = 1,
                Id     = 1
            };
            var album = new Album
            {
                Artist = "test",
                Label  = "hello",
                Name   = "Robot",
                Stock  = 1,
                TypeId = 1,
                Id     = 1
            };

            mapper.Setup(x => x.Map <Album>(command)).Returns(album);
            albumRepository.Setup(x => x.UpdateAlbum(album)).Returns(Task.CompletedTask);
            var handler = new UpdateAlbumHandler(albumRepository.Object, mapper.Object);

            //Act
            var x = await handler.Handle(command, new System.Threading.CancellationToken());

            //Asert
            albumRepository.Verify(albRep => albRep.UpdateAlbum(album));
        }
示例#4
0
 public async Task <ActionResult> CreateOrUpdateAlbum([FromBody] UpdateAlbumCommand updateAlbumRequest)
 {
     if (updateAlbumRequest.Id > 0)
     {
         await Mediator.Send(updateAlbumRequest);
     }
     else
     {
         var album = this.mapper.Map <AddNewAlbumCommand>(updateAlbumRequest);
         await Mediator.Send(album);
     }
     return(Ok());
 }
 public async Task ShouldThrowErrorForInvalidId()
 {
     var command = new UpdateAlbumCommand
     {
         Artist = "Artist",
         Label  = "Label",
         Name   = "name",
         Stock  = 0,
         TypeId = 1,
         Id     = 0
     };
     await Assert.ThrowsAsync <ValidationException>(() => SendAsync(command));
 }
示例#6
0
        public async Task <bool> UpdateAlbum(AlbumModel album)
        {
            var command = new UpdateAlbumCommand
            {
                AlbumId   = album.Id,
                AlbumName = album.Name,
                Type      = (int)album.Type,
                Stock     = album.Inventory.Stock,
                Artist    = new ArtistModel {
                    Name = album.Artists.FirstOrDefault()?.Name
                }
            };

            var result = await _mediator.Send(command);

            return(result);
        }
        public async Task ShouldThrowErrorForBadRequest(string name, string label, string artist, int typeId, int stock)
        {
            var existingItem = await SendAsync(new FetchAlbumDetailByNameQuery { Name = testAlbum.Name });

            var command = new UpdateAlbumCommand
            {
                Artist = artist,
                Label  = label,
                Name   = name,
                Stock  = stock,
                TypeId = typeId,
                Id     = existingItem.Id
            };
            await Assert.ThrowsAsync <ValidationException>(() => SendAsync(command));

            var result = await SendAsync(new FetchAlbumDetailByIdQuery { Id = existingItem.Id });

            Assert.NotNull(result);
            Assert.NotEqual(command.Name, result.Name);
            Assert.NotEqual(command.Label, result.Label);
            Assert.NotEqual(command.Stock, result.Stock);
            Assert.NotEqual(command.TypeId, result.TypeId);
            Assert.NotEqual(command.Artist, result.Artist);
        }
示例#8
0
 public ICommandResult Update([FromBody] UpdateAlbumCommand command)
 {
     return(_handler.Handle(command));
 }
        public async Task <ActionResult <ResponseWrapper> > UpdateAlbumAsync([FromBody] UpdateAlbumCommand command)
        {
            var result = await _mediator.Send(command);

            return(Ok(ResponseWrapper.CreateOkResponseWrapper(result)));
        }
示例#10
0
 public Task <AlbumList> Put([FromBody] UpdateAlbumCommand command)
 {
     return(Mediator.Send(command));
 }