public async Task CreateArtistAsyncShouldReturnFalseIfArtistWithSameNameBiographyAndBDateAlreadyExists()
        {
            var input = new CreateArtistInputModel
            {
                FullName  = "artist1",
                Biography = "biography1",
                BirthDate = DateTime.Parse("25 July 2019"),
                PhotoLink = "photo1",
            };

            await dbContext.Artists.AddAsync(new Artist
            {
                FullName  = "artist1",
                Biography = "biography1",
                BirthDate = DateTime.Parse("25 July 2019"),
                PhotoLink = "photo1",
            });

            await dbContext.SaveChangesAsync();

            var artistService = new ArtistService(dbContext, mapper);

            var actualResult = await artistService.CreateArtistAsync(input);

            Assert.False(actualResult);
            Assert.True(dbContext.Artists.Count() == 1);
        }
        public async Task <IActionResult> Create(CreateArtistInputModel input)
        {
            if (!ModelState.IsValid)
            {
                return(View(input));
            }

            if (!await artistService.CreateArtistAsync(input))
            {
                return(View(input));
            }

            return(Redirect(redirectArtistsAllAndOrder));
        }
Ejemplo n.º 3
0
        public async Task <bool> CreateArtistAsync(CreateArtistInputModel input)
        {
            if (await dbContext.Artists.AnyAsync(artist => artist.FullName == input.FullName && artist.Biography == input.Biography && artist.BirthDate == artist.BirthDate))
            {
                return(false);
            }

            var artistForDb = mapper.Map <CreateArtistInputModel, Artist>(input);

            await dbContext.Artists.AddAsync(artistForDb);

            await dbContext.SaveChangesAsync();

            return(true);
        }
        public async Task CreateArtistAsyncShouldSetPhotoLinkIfNoneIsProvided(string photoLink)
        {
            var input = new CreateArtistInputModel
            {
                FullName  = "artist1",
                Biography = "biography1",
                BirthDate = DateTime.Parse("25 July 2019"),
                PhotoLink = photoLink,
            };

            var artistService = new ArtistService(dbContext, mapper);

            var actualResult = await artistService.CreateArtistAsync(input);

            Assert.True(actualResult);
            Assert.True(dbContext.Artists.Count() == 1);
            Assert.True(dbContext.Artists.First().PhotoLink == GlobalConstants.noArtistImage);
        }
        public async Task CreateArtistAsyncShouldAddArtistToDbIfInputIsValid()
        {
            var input = new CreateArtistInputModel
            {
                FullName  = "artist1",
                Biography = "biography1",
                BirthDate = DateTime.Parse("25 July 2019"),
                PhotoLink = "photo1",
            };

            var artistService = new ArtistService(dbContext, mapper);

            var actualResult = await artistService.CreateArtistAsync(input);

            Assert.True(actualResult);
            Assert.True(dbContext.Artists.Count() == 1);
            Assert.True(dbContext.Artists.First().FullName == "artist1");
            Assert.True(dbContext.Artists.First().Biography == "biography1");
            Assert.True(dbContext.Artists.First().BirthDate == DateTime.Parse("25 July 2019"));
            Assert.True(dbContext.Artists.First().PhotoLink == "photo1");
        }