Пример #1
0
        public void AddSheetPart_AddNull_ThrowException()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <LibraryContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new LibraryContext(options);
            ISheetPartRepository sheetPartRepository = new SheetPartRepository(context);

            //Act & Assert
            Assert.ThrowsException <ArgumentNullException>(() => sheetPartRepository.Add(null));
        }
Пример #2
0
        public void UpdateSheetPart_Successful()
        {
            var options = new DbContextOptionsBuilder <LibraryContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new LibraryContext(options);
            ISheetRepository      sheetRepository      = new SheetRepository(context);
            ICategoryRepository   categoryRepository   = new CategoryRepository(context);
            ISheetPartRepository  sheetPartRepository  = new SheetPartRepository(context);
            IInstrumentRepository instrumentRepository = new InstrumentRepository(context);

            //Act
            var category = new CategoryTO {
                Name = "Musique de films"
            };
            var addedCategory = categoryRepository.Add(category);
            var category2     = new CategoryTO {
                Name = "Musique de classique"
            };
            var addedCategory2 = categoryRepository.Add(category2);

            context.SaveChanges();

            var sheet = new SheetTO {
                Name = "BestOf", Arranger = "Jean-Luc", Category = addedCategory, Composer = "Morricone", IsCurrent = false, IsGarde = false, IsIndependance = true
            };
            var sheet2 = new SheetTO {
                Name = "Youg Amadeus", Arranger = "Jan de Haan", Category = addedCategory2, Composer = "Mozart", IsCurrent = true, IsGarde = false, IsIndependance = true
            };
            var addedSheet  = sheetRepository.Add(sheet);
            var addedSheet2 = sheetRepository.Add(sheet2);

            context.SaveChanges();

            var instru = new InstrumentTO {
                Name = "Saxophone"
            };
            var instru2 = new InstrumentTO {
                Name = "Trumpet"
            };
            var instru3 = new InstrumentTO {
                Name = "Flute"
            };
            var addedInstru  = instrumentRepository.Add(instru);
            var addedInstru2 = instrumentRepository.Add(instru2);
            var addedInstru3 = instrumentRepository.Add(instru3);

            context.SaveChanges();
            var sheetPart = new SheetPartTO {
                Instrument = addedInstru, Sheet = addedSheet, Path = @"C:\sheet"
            };
            var sheetPart2 = new SheetPartTO {
                Instrument = addedInstru2, Sheet = addedSheet
            };
            var sheetPart3 = new SheetPartTO {
                Instrument = addedInstru, Sheet = addedSheet2
            };
            var addedSheetPart  = sheetPartRepository.Add(sheetPart);
            var addedSheetPart2 = sheetPartRepository.Add(sheetPart2);
            var addedSheetPart3 = sheetPartRepository.Add(sheetPart3);

            context.SaveChanges();

            //ACT
            addedSheetPart.Instrument = addedInstru3;
            var test = sheetPartRepository.Update(addedSheetPart);

            context.SaveChanges();

            //Assert
            Assert.AreEqual(3, sheetPartRepository.GetAll().Count());
            Assert.AreEqual("Flute", test.Instrument.Name);
        }