コード例 #1
0
        public TrackRepository(VinylStoreDbContext context)
        {
            this.context = context;

            if (this.context is null)
            {
                throw new ArgumentNullException($"TrackRepository : {nameof(context)} is empty");
            }
        }
コード例 #2
0
        public void NullArtistIdIsSubmitted_ThrowException()
        {
            var options = new DbContextOptionsBuilder <VinylStoreDbContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using (var context = new VinylStoreDbContext(options))
            {
                var artistRepository = new ArtistRepository(context);

                Assert.ThrowsException <ArgumentNullException>(() => artistRepository.GetById(Guid.Empty));
            }
        }
コード例 #3
0
ファイル: Insert.cs プロジェクト: patrick-peycker/VinylStore
        public void NullInserted_ThrowException()
        {
            var options = new DbContextOptionsBuilder <VinylStoreDbContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using (var context = new VinylStoreDbContext(options))
            {
                var albumRepository = new AlbumRepository(context);

                // Assert

                Assert.ThrowsException <ArgumentNullException>(() => albumRepository.Insert(null));
            }
        }
コード例 #4
0
 public ArtistRepository(VinylStoreDbContext context)
 {
     this.context = context ?? throw new ArgumentNullException(nameof(context));
 }
コード例 #5
0
 public Cart(VinylStoreDbContext context)
 {
     this.context = context;
 }
コード例 #6
0
        public void AddCorrectArtistThenRetrieveId()
        {
            var options = new DbContextOptionsBuilder <VinylStoreDbContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using (var context = new VinylStoreDbContext(options))
            {
                var artistRepository = new ArtistRepository(context);

                // Arrange

                var artist = new Artist
                {
                    Id      = new Guid("a74b1b7f-71a5-4011-9441-d0b5e4122711"),
                    Name    = "Radiohead",
                    Country = "GB",
                    Type    = "Group",

                    Albums = new List <Album>
                    {
                        new Album
                        {
                            Id    = new Guid("943aa9da-7dc7-4a4a-a95e-2ffa707b6858"),
                            Title = "OK Computer",

                            Tracks = new List <Track>
                            {
                                new Track
                                {
                                    Id       = new Guid("9f9cf187-d6f9-437f-9d98-d59cdbd52757"),
                                    Title    = "Paranoid Android",
                                    Position = 2,
                                    Number   = "A2",
                                    Length   = new DateTime(383506)
                                }
                            }
                        },

                        new Album
                        {
                            Id    = new Guid("a58f4eb2-9829-37d5-b46c-e8163038e0f5"),
                            Title = "In Rainbows",

                            Tracks = new List <Track>
                            {
                                new Track
                                {
                                    Id       = new Guid("90125ce1-1330-394c-b5ee-56f0cb2e1d50"),
                                    Title    = "15 Step",
                                    Position = 1,
                                    Number   = "A1",
                                    Length   = new DateTime(238120)
                                }
                            }
                        }
                    }
                };

                // Assert

                var artistAdded = artistRepository.Insert(artist);
                context.SaveChanges();

                var result = artistRepository.GetById(artistAdded.Id);

                // Assert
                Assert.IsNotNull(result);

                Assert.AreEqual(new Guid("a74b1b7f-71a5-4011-9441-d0b5e4122711"), result.Id);

                Assert.AreEqual(2, result.Albums.Count());

                Assert.AreEqual("Paranoid Android", result.Albums.FirstOrDefault(a => a.Id == new Guid("943aa9da-7dc7-4a4a-a95e-2ffa707b6858")).Tracks.FirstOrDefault(t => t.Id == new Guid("9f9cf187-d6f9-437f-9d98-d59cdbd52757")).Title);

                Assert.AreEqual("15 Step", result.Albums.FirstOrDefault(a => a.Id == new Guid("a58f4eb2-9829-37d5-b46c-e8163038e0f5")).Tracks.FirstOrDefault(t => t.Id == new Guid("90125ce1-1330-394c-b5ee-56f0cb2e1d50")).Title);
            }
        }
コード例 #7
0
        public void AddTwoArtistsThenRetrieveTheCorrectOne()
        {
            var options = new DbContextOptionsBuilder <VinylStoreDbContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using (var context = new VinylStoreDbContext(options))
            {
                var artistRepository = new ArtistRepository(context);

                // Arrange

                var artist01 = new Artist
                {
                    Id      = new Guid("a74b1b7f-71a5-4011-9441-d0b5e4122711"),
                    Name    = "Radiohead",
                    Country = "GB",
                    Type    = "Group",

                    Albums = new List <Album>
                    {
                        new Album
                        {
                            Id       = new Guid("943aa9da-7dc7-4a4a-a95e-2ffa707b6858"),
                            Title    = "OK Computer",
                            Quantity = 0,

                            Tracks = new List <Track>
                            {
                                new Track
                                {
                                    Id       = new Guid("9f9cf187-d6f9-437f-9d98-d59cdbd52757"),
                                    Title    = "Paranoid Android",
                                    Position = 2,
                                    Number   = "A2",
                                    Length   = new DateTime(383506),
                                }
                            }
                        },

                        new Album
                        {
                            Id       = new Guid("a58f4eb2-9829-37d5-b46c-e8163038e0f5"),
                            Title    = "In Rainbows",
                            Quantity = 0,

                            Tracks = new List <Track>
                            {
                                new Track
                                {
                                    Id       = new Guid("90125ce1-1330-394c-b5ee-56f0cb2e1d50"),
                                    Title    = "15 Step",
                                    Position = 1,
                                    Number   = "A1",
                                    Length   = new DateTime(238120)
                                }
                            }
                        }
                    }
                };

                var artist01Added = artistRepository.Insert(artist01);
                context.SaveChanges();

                var artist02 = new Artist
                {
                    Id   = new Guid("5b11f4ce-a62d-471e-81fc-a69a8278c7da"),
                    Name = "Nirvana",

                    Albums = new List <Album>
                    {
                        new Album
                        {
                            Id       = new Guid("80d84b5b-62a0-42fb-bc97-10702e166b3b"),
                            Title    = "Nevermind",
                            Quantity = 3
                        }
                    }
                };

                var artist02Added = artistRepository.Insert(artist02);
                context.SaveChanges();

                // Assert

                var result = artistRepository.GetArtistsWithAlbumsInStock();

                // Assert
                Assert.AreEqual(1, result.Count);
                Assert.AreEqual("Nevermind", result.FirstOrDefault(a => a.Id == new Guid("5b11f4ce-a62d-471e-81fc-a69a8278c7da")).Albums.FirstOrDefault(a => a.Id == new Guid("80d84b5b-62a0-42fb-bc97-10702e166b3b")).Title);
            }
        }
コード例 #8
0
 public VinylStoreUnitOfWork(VinylStoreDbContext Context)
 {
     this.Context = Context ?? throw new ArgumentNullException(nameof(Context));
 }
コード例 #9
0
 public CartItemRepository(VinylStoreDbContext context)
 {
     this.context = context ?? throw new ArgumentNullException($"CartItemRepository : {nameof(context)} is empty");
 }
コード例 #10
0
ファイル: Insert.cs プロジェクト: patrick-peycker/VinylStore
        public void CorrectAlbumsInserted()
        {
            var options = new DbContextOptionsBuilder <VinylStoreDbContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using (var context = new VinylStoreDbContext(options))
            {
                var artistRepository = new ArtistRepository(context);
                var albumRepository  = new AlbumRepository(context);

                // Arrange - Act
                var artist = new Artist
                {
                    Id      = new Guid("a74b1b7f-71a5-4011-9441-d0b5e4122711"),
                    Name    = "Radiohead",
                    Country = "GB",
                    Type    = "Group"
                };

                var artistAdded = artistRepository.Insert(artist);
                context.SaveChanges();


                var album01 = new Album
                {
                    ArtistId = new Guid("a74b1b7f-71a5-4011-9441-d0b5e4122711"),

                    Id    = new Guid("fe77a154-63da-4c0d-899c-3d8731e2d2c2"),
                    Title = "A Moon Shaped Pool",

                    Tracks = new List <Track>
                    {
                        new Track
                        {
                            Id       = new Guid("c59df3ae-60b3-4b66-962c-7cc3c4484d20"),
                            Title    = "Burn the Witch",
                            Position = 1,
                            Number   = "A1",
                            Length   = new DateTime(220000)
                        }
                    }
                };

                var resultAlbum01 = albumRepository.Insert(album01);
                context.SaveChanges();

                var album02 = new Album
                {
                    ArtistId = new Guid("a74b1b7f-71a5-4011-9441-d0b5e4122711"),

                    Id    = new Guid("9ae924e1-8a6c-4d61-acb6-6f004adf8559"),
                    Title = "The Bends",

                    Tracks = new List <Track>
                    {
                        new Track
                        {
                            Id       = new Guid("49bb3701-1b75-4232-8999-ff5318adf676"),
                            Title    = "Planet Telex",
                            Position = 1,
                            Number   = "A1",
                            Length   = new DateTime(259200)
                        }
                    }
                };

                var resultAlbum02 = albumRepository.Insert(album02);
                context.SaveChanges();

                // Assert
                Assert.IsNotNull(resultAlbum01);
                Assert.IsNotNull(resultAlbum02);

                Assert.AreEqual(new Guid("fe77a154-63da-4c0d-899c-3d8731e2d2c2"), resultAlbum01.Id);
                Assert.AreEqual(new Guid("9ae924e1-8a6c-4d61-acb6-6f004adf8559"), resultAlbum02.Id);

                Assert.AreEqual(1, resultAlbum01.Tracks.Count);
                Assert.AreEqual(1, resultAlbum02.Tracks.Count);

                Assert.AreEqual("Burn the Witch", resultAlbum01.Tracks.FirstOrDefault(t => t.Id == new Guid("c59df3ae-60b3-4b66-962c-7cc3c4484d20")).Title);

                Assert.AreEqual("Planet Telex", resultAlbum02.Tracks.FirstOrDefault(t => t.Id == new Guid("49bb3701-1b75-4232-8999-ff5318adf676")).Title);
            }
        }