Esempio n. 1
0
        public async Task Patch_ThrowsValidationException_ReturnsBadRequestResult()
        {
            var mock   = AutoMock.GetLoose();
            var artist = new ArtistDetailsDto();

            mock.Mock <IArtistService>().Setup(x => x.UpdateArtistAsync(1, artist)).Throws <ValidationException>();
            mock.Mock <IArtistService>().Setup(x => x.DetailsAsync(1)).Returns(Task.FromResult(artist));

            var controller = mock.Create <ArtistController>();
            var result     = await controller.Patch(1, new JsonPatchDocument <ArtistDetailsDto>());

            Assert.IsType <BadRequestObjectResult>(result);
        }
Esempio n. 2
0
        public async Task Post_AddsArtist()
        {
            var mock   = AutoMock.GetLoose();
            var artist = new ArtistDetailsDto()
            {
                FirstName = "Adam", LastName = "Test"
            };
            var controller = mock.Create <ArtistController>();
            var result     = await controller.Post(artist);

            Assert.IsType <CreatedResult>(result);
            mock.Mock <IArtistService>().Verify(x => x.AddArtistAsync(artist));
        }
Esempio n. 3
0
        public async Task Put_UpdatesArtist()
        {
            var mock   = AutoMock.GetLoose();
            var artist = new ArtistDetailsDto()
            {
                FirstName = "Adam", LastName = "Test"
            };
            var controller = mock.Create <ArtistController>();
            var result     = await controller.Put(1, artist);

            Assert.IsType <CreatedResult>(result);
            mock.Mock <IArtistService>().Verify(x => x.UpdateArtistAsync(1, artist), Times.Once);
        }
Esempio n. 4
0
        public async Task <ActionResult> Post([FromBody] ArtistDetailsDto artist)
        {
            try
            {
                await _artistService.AddArtistAsync(artist).ConfigureAwait(true);
            }
            catch (ValidationException)
            {
                return(ValidationProblem());
            }

            return(Created(nameof(Get), null));
        }
Esempio n. 5
0
        public async Task Post_InvalidArtist_ReturnsBadRequestResult()
        {
            var mock   = AutoMock.GetLoose();
            var artist = new ArtistDetailsDto()
            {
                FirstName = "", LastName = "Test"
            };
            var controller = mock.Create <ArtistController>();

            mock.Mock <IArtistService>().Setup(x => x.AddArtistAsync(artist)).Throws <ValidationException>();
            var result = await controller.Post(artist);

            Assert.IsType <BadRequestObjectResult>(result);
        }
Esempio n. 6
0
        public async Task Put_ArtistNotFound_ReturnsNotFoundResult()
        {
            var mock   = AutoMock.GetLoose();
            var artist = new ArtistDetailsDto()
            {
                FirstName = "Adam", LastName = "Test"
            };

            mock.Mock <IArtistService>().Setup(x => x.UpdateArtistAsync(1, artist)).Throws <NullReferenceException>();
            var controller = mock.Create <ArtistController>();
            var result     = await controller.Put(1, artist);

            Assert.IsType <NotFoundResult>(result);
        }
Esempio n. 7
0
        public async Task Patch_ValidCall()
        {
            var mock   = AutoMock.GetLoose();
            var artist = new ArtistDetailsDto();
            var patch  = mock.Create <JsonPatchDocument <ArtistDetailsDto> >();

            mock.Mock <IArtistService>().Setup(x => x.DetailsAsync(1)).Returns(Task.FromResult(artist));

            var controller = mock.Create <ArtistController>();

            var result = await controller.Patch(1, patch);

            mock.Mock <IArtistService>().Verify(x => x.UpdateArtistAsync(1, artist), Times.Once);
            Assert.IsType <CreatedResult>(result);
        }
Esempio n. 8
0
        public async Task GetArtist_ProperId_ReturnsArtist()
        {
            var mock   = AutoMock.GetLoose();
            var artist = new ArtistDetailsDto()
            {
                FirstName = "Adam", LastName = "Test"
            };

            mock.Mock <IArtistService>().Setup(x => x.DetailsAsync(1)).Returns(Task.FromResult(artist));
            var controller = mock.Create <ArtistController>();
            var result     = await controller.GetArtist(1);

            var resultArtist = Assert.IsType <ArtistDetailsDto>(result.Value);

            Assert.Equal(artist.FirstName, resultArtist.FirstName);
            Assert.Equal(artist.LastName, resultArtist.LastName);
        }
Esempio n. 9
0
        public async Task <ActionResult> Put(int id, [FromBody] ArtistDetailsDto artist)
        {
            try
            {
                await _artistService.UpdateArtistAsync(id, artist).ConfigureAwait(true);
            }
            catch (NullReferenceException)
            {
                return(NotFound());
            }
            catch (ValidationException ex)
            {
                return(ValidationProblem(new ValidationProblemDetails()
                {
                    Detail = ex.Message
                }));
            }

            return(Created(nameof(GetArtist), id));
        }
Esempio n. 10
0
        public static Artist CreateArtist(string displayname, string firstname, string lastname, ArtistDetailsDto artistDetailsDto)
        {
            Artist artist = new Artist(displayname, firstname, lastname);

            artist.CreateArtistDetails(artistDetailsDto.StageName);

            return(artist);
        }