public void DeleteInstrument_Successful()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <LibraryContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new LibraryContext(options);
            IInstrumentRepository instrumentRepository = new InstrumentRepository(context);

            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();

            //Act
            var result = instrumentRepository.Delete(AddedInstru);

            context.SaveChanges();
            //Assert
            Assert.AreEqual(2, instrumentRepository.GetAll().Count());
        }
Example #2
0
        private void BtnClearCount_Click(object sender, System.EventArgs e)
        {
            var instrumentRepository = new InstrumentRepository();
            var instruments          = instrumentRepository.Get();

            foreach (var instrument in instruments)
            {
                instrumentRepository.Delete(instrument);
            }

            instrumentRepository.AddDefaultInstrument();
        }
        public void DeleteInstrument_ProvidingNull_ThrowException()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <LibraryContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new LibraryContext(options);
            IInstrumentRepository instrumentRepository = new InstrumentRepository(context);

            var instrument = new InstrumentTO {
                Name = "Saxophone"
            };

            //Act & Assert
            Assert.ThrowsException <ArgumentException>(() => instrumentRepository.Delete(instrument));
        }
        public async void DeleteSelectedInstrument(Instrument instrument)
        {
            var existing = await _instrumentRepository.GetInstrumentAsync(instrument.Code);

            if (existing == null)
            {
                return;
            }

            _instrumentRepository.Delete(existing);

            if (await _instrumentRepository.SaveChangesAsync())
            {
                WindowLoaded();
                MessageBox.Show("Deleted Successfully", "Done");
                UpdateInstrument = new Instrument();
            }
        }