public void TestCreateTrackCount()
        {
            var options   = new DbContextOptionsBuilder <MusicSpotDbContext>().UseInMemoryDatabase("createTracksReturnCount").Options;
            var dbContext = new MusicSpotDbContext(options);
            var service   = new TrackService(dbContext);

            var track = new Track
            {
                Name     = "Joni",
                Duration = "4:44",
                AlbumId  = 4
            };

            for (int i = 1; i < 5; i++)
            {
                service.Create(track.Name, track.Duration, track.AlbumId);

                dbContext.SaveChanges();
            }

            dbContext.SaveChanges();

            int result = dbContext.Tracks.CountAsync().Result;

            Assert.AreEqual(4, result);
            Assert.AreNotEqual(16, result);
            Assert.AreNotEqual("int", result);
            Assert.That(result, Is.Not.Null);
            Assert.That(track.Id, Is.Not.Null);

            dbContext.Remove(track);
        }
        public void TestCreateMovieCount()
        {
            var options   = new DbContextOptionsBuilder <MusicSpotDbContext>().UseInMemoryDatabase("createMovieReturnCount").Options;
            var dbContext = new MusicSpotDbContext(options);
            var service   = new MovieService(dbContext);

            var movie = new Movie
            {
                Title       = "Speed",
                Genre       = "Action",
                ImageUrl    = "aaa",
                Year        = 1998,
                Description = "some description",
                UserId      = "aaa"
            };

            for (int i = 1; i < 5; i++)
            {
                service.Create(movie.Title, movie.Genre, movie.ImageUrl, movie.Year, movie.Description, movie.UserId);

                dbContext.SaveChanges();
            }

            dbContext.SaveChanges();

            int result = dbContext.Movies.CountAsync().Result;

            Assert.AreEqual(4, result);
            Assert.AreNotEqual(14, result);
            Assert.AreNotEqual("aa", result);
            Assert.That(result, Is.Not.Null);
            Assert.That(movie.Id, Is.Not.Null);

            dbContext.Remove(movie);
        }
Beispiel #3
0
        public void TestCreateAlbumsCount()
        {
            var options   = new DbContextOptionsBuilder <MusicSpotDbContext>().UseInMemoryDatabase("createAlbumsReturnCount").Options;
            var dbContext = new MusicSpotDbContext(options);
            var service   = new AlbumService(dbContext);

            var album = new Album
            {
                Name            = "Joni",
                ImageUrl        = "aaaa",
                Year            = 2000,
                Format          = "LP",
                MediaCondition  = "G+",
                SleeveCondition = "NM",
                Notes           = "some notes",
                ArtistId        = 7
            };

            for (int i = 1; i < 5; i++)
            {
                service.Create(album.Name, album.ImageUrl, album.Year, album.Format, album.MediaCondition, album.SleeveCondition, album.Notes, album.ArtistId);

                dbContext.SaveChanges();
            }

            dbContext.SaveChanges();

            int result = dbContext.Albums.CountAsync().Result;

            Assert.AreEqual(4, result);
            Assert.That(result, Is.Not.Null);
            Assert.That(album.Id, Is.Not.Null);

            dbContext.Remove(album);
        }
Beispiel #4
0
        public void TestCreateGamesCount()
        {
            var options   = new DbContextOptionsBuilder <MusicSpotDbContext>().UseInMemoryDatabase("createGamesReturnCount").Options;
            var dbContext = new MusicSpotDbContext(options);
            var service   = new GameService(dbContext);

            var game = new Game
            {
                Title       = "FIFA",
                Genre       = "Sport",
                ImageUrl    = "aaa",
                Description = "some description",
                UserId      = "aaa"
            };

            for (int i = 1; i < 5; i++)
            {
                service.Create(game.Title, game.Genre, game.ImageUrl, game.Description, game.UserId);

                dbContext.SaveChanges();
            }

            dbContext.SaveChanges();

            int result = dbContext.Games.CountAsync().Result;

            Assert.AreEqual(4, result);
            Assert.That(result, Is.Not.Null);
            Assert.That(game.Id, Is.Not.Null);

            dbContext.Remove(game);
        }
Beispiel #5
0
        public void TestCreateBooksCount()
        {
            var options   = new DbContextOptionsBuilder <MusicSpotDbContext>().UseInMemoryDatabase("createBooksReturnCount").Options;
            var dbContext = new MusicSpotDbContext(options);
            var service   = new BookService(dbContext);

            var book = new Book
            {
                Title       = "It",
                Genre       = "Horror",
                ImageUrl    = "aaa",
                Description = "some description",
                UserId      = "aaa"
            };

            for (int i = 1; i < 5; i++)
            {
                service.Create(book.Title, book.Genre, book.ImageUrl, book.Description, book.UserId);

                dbContext.SaveChanges();
            }

            dbContext.SaveChanges();

            int result = dbContext.Books.CountAsync().Result;

            Assert.AreEqual(4, result);
            Assert.That(result, Is.Not.Null);
            Assert.That(book.Id, Is.Not.Null);

            dbContext.Remove(book);
        }
Beispiel #6
0
        public bool Delete(int gameId)
        {
            var game = _context.Games.Find(gameId);

            if (game == null)
            {
                return(false);
            }

            _context.Remove(game);
            _context.SaveChangesAsync();

            return(true);
        }
Beispiel #7
0
        public bool Delete(int albumId)
        {
            var album = _context.Albums.Find(albumId);

            if (album == null)
            {
                return(false);
            }

            _context.Remove(album);
            _context.SaveChangesAsync();

            return(true);
        }
Beispiel #8
0
        public bool Delete(int artistId)
        {
            var artist = _context.Artists.Find(artistId);

            if (artist == null)
            {
                return(false);
            }

            _context.Remove(artist);
            _context.SaveChangesAsync();

            return(true);
        }
Beispiel #9
0
        public bool Delete(int bookId)
        {
            var book = _context.Books.Find(bookId);

            if (book == null)
            {
                return(false);
            }

            _context.Remove(book);
            _context.SaveChangesAsync();

            return(true);
        }
Beispiel #10
0
        public bool Delete(int movieId)
        {
            var movie = _context.Movies.Find(movieId);

            if (movie == null)
            {
                return(false);
            }

            _context.Remove(movie);
            _context.SaveChangesAsync();

            return(true);
        }
Beispiel #11
0
        public bool Delete(int id)
        {
            var track = _context.Albums.Find(id);

            if (track == null)
            {
                return(false);
            }

            _context.Remove(track);
            _context.SaveChangesAsync();

            return(true);
        }