Ejemplo n.º 1
0
        public void TestArtistNotExit()
        {
            var options   = new DbContextOptionsBuilder <MusicSpotDbContext>().UseInMemoryDatabase("artistNotExist").Options;
            var dbContext = new MusicSpotDbContext(options);
            var service   = new ArtistService(dbContext);

            var artist = new Artist
            {
                Id     = 1,
                Name   = "Joni",
                Genre  = "Horror",
                UserId = "aaa"
            };

            dbContext.Artists.Add(artist);
            dbContext.SaveChanges();

            var result = service.ArtistDetails(artist.Id);

            Assert.That(artist.Id, Is.Not.Null);
            Assert.That(result, Is.Not.Null);
            Assert.AreEqual(result.Result.Genre, artist.Genre);
            Assert.AreEqual(result.Result.Name, artist.Name);
            Assert.AreEqual(result.Result.Id, artist.Id);
        }
Ejemplo n.º 2
0
        public void TestAlbumDelete()
        {
            var options   = new DbContextOptionsBuilder <MusicSpotDbContext>().UseInMemoryDatabase("albumDelete").Options;
            var dbContext = new MusicSpotDbContext(options);
            var service   = new AlbumService(dbContext);

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

            dbContext.Albums.Add(album);
            dbContext.SaveChanges();

            var result = service.Delete(album.Id);

            Assert.AreEqual(result, true);
            Assert.AreEqual(service.AlbumExist(album.Id), false);
            Assert.AreNotEqual(result, false);
            Assert.That(album.Id, Is.Not.Null);
            Assert.AreEqual(result, true);
        }
Ejemplo n.º 3
0
        public void TestTracks()
        {
            var options   = new DbContextOptionsBuilder <MusicSpotDbContext>().UseInMemoryDatabase("tracksIndex").Options;
            var dbContext = new MusicSpotDbContext(options);
            var service   = new TrackService(dbContext);

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

            dbContext.Tracks.Add(track);
            dbContext.SaveChanges();

            var result = service.Index("aaa", "Joni", 5, 5);

            Assert.That(result, Is.Not.Null);
            Assert.That(track.Id, Is.Not.Null);
            Assert.AreEqual("aaa", result.Result.UserId);
            Assert.AreNotEqual("bbbaaa", result.Result.UserId);

            Assert.AreNotEqual("aaaa", result.Result.AlbumId);
            Assert.AreNotEqual("aaa", result.Result.SearchTerm);
            Assert.AreEqual("Joni", result.Result.SearchTerm);
            Assert.AreEqual(5, result.Result.PageNum);
            Assert.AreNotEqual("int", result.Result.PageNum);
            Assert.AreEqual(5, result.Result.PageSize);
            Assert.AreNotEqual("aaa", result.Result.PageNum);
        }
Ejemplo n.º 4
0
        public void TestTrackEdit()
        {
            var options   = new DbContextOptionsBuilder <MusicSpotDbContext>().UseInMemoryDatabase("trackEditCorrect").Options;
            var dbContext = new MusicSpotDbContext(options);
            var service   = new TrackService(dbContext);

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

            dbContext.Tracks.Add(track);
            dbContext.SaveChanges();

            var result = service.Edit(track.Id, track.Name, track.Duration, track.AlbumId);

            Assert.AreNotEqual(track, result);
            Assert.AreEqual("Joni", track.Name);
            Assert.AreNotEqual("Joki", track.Name);
            Assert.That(result, Is.Not.Null);
            Assert.That(track.Id, Is.Not.Null);
            Assert.AreEqual(result, true);
        }
Ejemplo n.º 5
0
        public void TestTracksDetails()
        {
            var options   = new DbContextOptionsBuilder <MusicSpotDbContext>().UseInMemoryDatabase("trackDetails").Options;
            var dbContext = new MusicSpotDbContext(options);
            var service   = new TrackService(dbContext);

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

            dbContext.Tracks.Add(track);
            dbContext.SaveChanges();

            var result = service.TrackDetails(track.Id);

            Assert.That(result.Result.Id, Is.Not.Null);
            Assert.That(result, Is.Not.Null);
            Assert.AreEqual("Joni", result.Result.Name);
            Assert.AreNotEqual(2000, result.Result.Name);
            Assert.AreEqual("4:44", result.Result.Duration);
            Assert.AreNotEqual(8, result.Result.AlbumId);
            Assert.AreEqual(track.AlbumId, result.Result.AlbumId);
        }
Ejemplo n.º 6
0
        public void TestTrackCount()
        {
            var options   = new DbContextOptionsBuilder <MusicSpotDbContext>().UseInMemoryDatabase("trackCount").Options;
            var dbContext = new MusicSpotDbContext(options);
            var service   = new TrackService(dbContext);

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

            for (int i = 0; i < 3; i++)
            {
                dbContext.Tracks.Add(track);
            }
            dbContext.SaveChanges();

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

            Assert.AreNotEqual(result, true);
            Assert.AreEqual(result, 1);
            Assert.That(result, Is.Not.Null);
        }
Ejemplo n.º 7
0
        public void TestTrackDelete()
        {
            var options   = new DbContextOptionsBuilder <MusicSpotDbContext>().UseInMemoryDatabase("trackDelete").Options;
            var dbContext = new MusicSpotDbContext(options);
            var service   = new TrackService(dbContext);

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


            dbContext.Tracks.Add(track);
            dbContext.SaveChanges();

            var result = service.Delete(track.Id);

            Assert.AreNotEqual(result, true);
            Assert.AreEqual(service.TrackExist(track.Id), false);
            Assert.AreEqual(result, false);
            Assert.That(track.Id, Is.Not.Null);
        }
Ejemplo n.º 8
0
        public void TestGameNotExit()
        {
            var options   = new DbContextOptionsBuilder <MusicSpotDbContext>().UseInMemoryDatabase("gameNotExist").Options;
            var dbContext = new MusicSpotDbContext(options);
            var service   = new GameService(dbContext);

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

            dbContext.Games.Add(game);
            dbContext.SaveChanges();

            var result = service.GameDetails(game.Id);

            Assert.That(game.Id, Is.Not.Null);
            Assert.That(result, Is.Not.Null);
            Assert.AreEqual(result.Result.Genre, game.Genre);
            Assert.AreEqual(result.Result.Title, game.Title);
            Assert.AreEqual(result.Result.Id, game.Id);
            Assert.AreEqual(result.Result.ImageUrl, game.ImageUrl);
            Assert.AreNotEqual(result.Result.Description, 2000);
        }
Ejemplo n.º 9
0
        public void TestGameDelete()
        {
            var options   = new DbContextOptionsBuilder <MusicSpotDbContext>().UseInMemoryDatabase("gameDelete").Options;
            var dbContext = new MusicSpotDbContext(options);
            var service   = new GameService(dbContext);

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

            dbContext.Games.Add(game);
            dbContext.SaveChanges();

            var result = service.Delete(1);

            Assert.AreEqual(result, true);
            Assert.AreEqual(service.GameExist(1), false);
            Assert.AreNotEqual(result, false);
            Assert.That(game.Id, Is.Not.Null);
        }
Ejemplo n.º 10
0
        public void TestBookNotExit()
        {
            var options   = new DbContextOptionsBuilder <MusicSpotDbContext>().UseInMemoryDatabase("bookNotExist").Options;
            var dbContext = new MusicSpotDbContext(options);
            var service   = new BookService(dbContext);

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

            dbContext.Books.Add(book);
            dbContext.SaveChanges();

            var result = service.BooksDetails(book.Id);

            Assert.That(book.Id, Is.Not.Null);
            Assert.That(result, Is.Not.Null);
            Assert.AreEqual(result.Result.Genre, book.Genre);
            Assert.AreEqual(result.Result.Title, book.Title);
            Assert.AreEqual(result.Result.Id, book.Id);
            Assert.AreEqual(result.Result.ImageUrl, book.ImageUrl);
            Assert.AreNotEqual(result.Result.Description, 2000);
        }
Ejemplo n.º 11
0
        public void TestBookDelete()
        {
            var options   = new DbContextOptionsBuilder <MusicSpotDbContext>().UseInMemoryDatabase("bookDelete").Options;
            var dbContext = new MusicSpotDbContext(options);
            var service   = new BookService(dbContext);

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

            dbContext.Books.Add(book);
            dbContext.SaveChanges();

            var result = service.Delete(1);

            Assert.AreEqual(result, true);
            Assert.AreEqual(service.BookExist(1), false);
            Assert.AreNotEqual(result, false);
            Assert.That(book.Id, Is.Not.Null);
        }
Ejemplo n.º 12
0
        public void TestArtistList()
        {
            var options   = new DbContextOptionsBuilder <MusicSpotDbContext>().UseInMemoryDatabase("artistListCount").Options;
            var dbContext = new MusicSpotDbContext(options);
            var service   = new ArtistService(dbContext);

            var artist = new Artist
            {
                Name   = "joni",
                Genre  = "metal",
                UserId = "jshsdjhdajdh"
            };

            dbContext.Artists.Add(artist);
            dbContext.SaveChanges();

            var result = service.ArtistsList;

            Assert.That(result, Is.Not.Null);
        }
Ejemplo n.º 13
0
        public void TestAllTracks()
        {
            var options   = new DbContextOptionsBuilder <MusicSpotDbContext>().UseInMemoryDatabase("returnTrackNotNull").Options;
            var dbContext = new MusicSpotDbContext(options);
            var service   = new TrackService(dbContext);

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

            dbContext.Tracks.Add(track);
            dbContext.SaveChanges();

            var result = service.AllTracks(4);

            Assert.That(result, Is.Not.Null);
            Assert.AreNotEqual("aaaaaa", result.Result.UserId);
        }
Ejemplo n.º 14
0
        public void TestArtistExist()
        {
            var options   = new DbContextOptionsBuilder <MusicSpotDbContext>().UseInMemoryDatabase("artistExist").Options;
            var dbContext = new MusicSpotDbContext(options);
            var service   = new ArtistService(dbContext);

            var artist = new Artist
            {
                Name   = "joni",
                Genre  = "metal",
                UserId = "aaaaabbbb"
            };

            dbContext.Artists.Add(artist);
            dbContext.SaveChanges();

            var result = service.ArtistExist(artist.Id);

            Assert.AreEqual(result, true);
            Assert.AreNotEqual(result, false);
            Assert.That(artist.Id, Is.Not.Null);
        }
Ejemplo n.º 15
0
        public void TestBooksList()
        {
            var options   = new DbContextOptionsBuilder <MusicSpotDbContext>().UseInMemoryDatabase("booksListCount").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"
            };

            dbContext.Books.Add(book);
            dbContext.SaveChanges();

            var result = service.BooksList(book.UserId);

            Assert.That(result, Is.Not.Null);
            Assert.AreEqual(dbContext.Books.CountAsync().Result, 1);
            Assert.That(book.Id, Is.Not.Null);
        }