Ejemplo n.º 1
0
        public void SaveValidIdTest()
        {
            ICRUDTestDBContextProvider cRUDTestDBContextProvider = new CRUDTestDBContextProvider(Guid.NewGuid().ToString());
            var context = cRUDTestDBContextProvider.GetContext();
            var album   = new Album
            {
                Title   = "TestAlbumTitle",
                AlbumId = 1
            };

            context.Add(album);
            context.SaveChanges();

            AlbumBE albumBE = new AlbumBE(cRUDTestDBContextProvider);

            albumBE.Load(1);
            albumBE.Title = "TestAlbumTitleChanged";
            albumBE.Save();

            AlbumBE albumBE2 = new AlbumBE(cRUDTestDBContextProvider);

            albumBE2.Load(1);
            Assert.IsTrue(albumBE2.Id == 1);
            Assert.IsTrue(albumBE2.Title == "TestAlbumTitleChanged");
        }
Ejemplo n.º 2
0
        public void AlbumCountTest()
        {
            ICRUDTestDBContextProvider cRUDTestDBContextProvider = new CRUDTestDBContextProvider(Guid.NewGuid().ToString());
            var context = cRUDTestDBContextProvider.GetContext();
            var artist  = new Artist
            {
                ArtistId = 1
            };
            var album = new Album {
                AlbumId = 1, ArtistId = 1, Title = "TestAlbumTitle"
            };

            context.Add(artist);
            context.Add(album);
            context.SaveChanges();

            ArtistBE artistBE = new ArtistBE(cRUDTestDBContextProvider);

            artistBE.Load(1);
            Assert.IsTrue(artistBE.AlbumCount == 1);

            AlbumBE albumBE = new AlbumBE(cRUDTestDBContextProvider);

            albumBE.New();
            albumBE.Title = "TestAlbumTitle";
            artistBE.AddToAlbum(albumBE);
            albumBE.Save();

            ArtistBE artistBE2 = new ArtistBE(cRUDTestDBContextProvider);

            artistBE2.Load(1);
            Assert.IsTrue(artistBE2.AlbumCount == 2);
        }
Ejemplo n.º 3
0
        public void AddToAlbumTest()
        {
            ICRUDTestDBContextProvider cRUDTestDBContextProvider = new CRUDTestDBContextProvider(Guid.NewGuid().ToString());
            var context = cRUDTestDBContextProvider.GetContext();
            var artist  = new Artist
            {
                ArtistId = 1
            };
            var album = new Album {
                AlbumId = 1, Title = "TestAlbumTitle"
            };

            context.Add(artist);
            context.Add(album);
            context.SaveChanges();

            AlbumBE  albumBE  = new AlbumBE(cRUDTestDBContextProvider);
            ArtistBE artistBE = new ArtistBE(cRUDTestDBContextProvider);

            artistBE.Load(1);
            albumBE.Load(1);
            artistBE.AddToAlbum(albumBE);
            albumBE.Save();

            artistBE.Load(1);
            var AlbumBECollection = artistBE.GetAlbums();

            Assert.IsTrue(AlbumBECollection.First().Id == 1);
            Assert.IsTrue(AlbumBECollection.First().ArtistId == 1);
        }
Ejemplo n.º 4
0
        public void SaveWithoutIdTest()
        {
            ICRUDTestDBContextProvider cRUDTestDBContextProvider = new CRUDTestDBContextProvider(Guid.NewGuid().ToString());
            AlbumBE albumBE = new AlbumBE(cRUDTestDBContextProvider);

            albumBE.New();
            albumBE.Title = "TestAlbumTitle";
            albumBE.Save();

            Assert.IsTrue(albumBE.Id != default);
        }
Ejemplo n.º 5
0
        public void Put([FromBody] AlbumBEDTO albumBEDTO)
        {
            AlbumBE albumBE = new AlbumBE(cRUDTestDBContextProvider);

            albumBE.Load(albumBEDTO.Id);
            mapper.Map <AlbumBEDTO, AlbumBE>(albumBEDTO, albumBE);
            if (ModelState.IsValid)
            {
                albumBE.Save();
            }
        }