Пример #1
0
        protected override void Seed(TestRockstars.DAL.DatabaseContext context)
        {
            JSONParser        parse            = new JSONParser();
            SongsRepository   songRepository   = new SongsRepository(context);
            ArtistsRepository artistRepository = new ArtistsRepository(context);

            artistRepository.ClearArtists();
            songRepository.ClearSongs();
            songRepository.AddSong(parse.GetSongs().ToArray());
            artistRepository.AddArtist(parse.GetArtists().ToArray());
        }
        public void AddArtist()
        {
            var mockSet = new Mock <DbSet <Artist> >();

            var mockContext = new Mock <DatabaseContext>();

            mockContext.Setup(m => m.Artists).Returns(mockSet.Object);

            var service = new ArtistsRepository(mockContext.Object);

            service.AddArtist(testArtist);

            mockSet.Verify(m => m.Add(testArtist), Times.Once());
            mockContext.Verify(m => m.SaveChanges(), Times.Once());
        }
        public async Task <IHttpActionResult> PostArtist(Artist artist)
        {
            if (artistRepository.GetArtists().Where(a => a.Name.Equals(artist.Name)).Count() > 0)
            {
                return(BadRequest("That name already exists!"));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            artistRepository.AddArtist(artist);
            await artistRepository.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = artist.Id }, artist));
        }