Ejemplo n.º 1
0
        public void GetInstrumentById_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.GetById(1);
            var result2 = instrumentRepository.GetById(2);
            var result3 = instrumentRepository.GetById(3);

            //Assert
            Assert.AreEqual("Saxophone", result.Name);
            Assert.AreEqual("Trumpet", result2.Name);
            Assert.AreEqual("Flute", result3.Name);
        }
        public void GetByIdTest()
        {
            InstrumentRepository repo       = new InstrumentRepository();
            C_Instrument         instrument = repo.GetById(1);

            Assert.IsNotNull(instrument);
            Assert.IsNotNull(instrument.Name);
            Assert.IsNotNull(instrument.Description);
            Assert.IsNotNull(instrument.IconUrl);
        }
Ejemplo n.º 3
0
        public void GetInstrumentById_ProvidingNonExistingId_ThrowException()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <LibraryContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

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

            //Act & Assert
            Assert.ThrowsException <ArgumentNullException>(() => instrumentRepository.GetById(14));
        }