public void GetAllTest() { InstrumentRepository repo = new InstrumentRepository(); List <C_Instrument> instruments = repo.GetAll(); Assert.IsTrue(instruments.Count > 0); }
public IEnumerable <Instrument> GetAll() { InstrumentRepository instrumentRepository = new InstrumentRepository(); var retorno = instrumentRepository.GetAll(); return(retorno); }
public void AddInstrument_AddExistingInstrument_DoNotInsertTwiceInDb() { //Arrange var options = new DbContextOptionsBuilder <LibraryContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new LibraryContext(options); IInstrumentRepository instrumentRepository = new InstrumentRepository(context); //Act var instru = new InstrumentTO { Name = "Saxophone" }; var instru2 = new InstrumentTO { Id = 2, Name = "Saxophone" }; var result = instrumentRepository.Add(instru); var result2 = instrumentRepository.Add(instru2); context.SaveChanges(); //Assert Assert.IsNotNull(result); Assert.AreEqual(1, instrumentRepository.GetAll().Count()); }
public void UpdateInstrument_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 AddedInstru.Name = "PouetPouet"; var test = instrumentRepository.Update(AddedInstru); context.SaveChanges(); //Assert Assert.AreEqual(3, instrumentRepository.GetAll().Count()); Assert.AreEqual("PouetPouet", test.Name); }
public async Task <List <Instrument> > GetAllAsync() { using (var instruments = new InstrumentRepository()) { return(await(from instrument in instruments.GetAll() select instrument).ToListAsync()); } }
public async Task <Instrument> FindByIdAsync(int id) { using (var instruments = new InstrumentRepository()) { return(await(from instrument in instruments.GetAll() where instrument.Id == id select instrument).FirstAsync()); } }
public IActionResult Index() { return(View(_repository.GetAll())); }