コード例 #1
0
        public async void GetHardDrivesFromDatabaseTest()
        {
            var options = new DbContextOptionsBuilder <CheapWareContext>()
                          .UseInMemoryDatabase(databaseName: "GetHardDrivesFromDatabase")
                          .Options;
            var harddrive = new HardDrives {
                Name = "test name", Category = "SSD", Size = "500GB", Speed = "7200RPM", Price = 100.99M
            };
            List <HardDrive> listofharddrives = null;

            using (var context = new CheapWareContext(options))
            {
                context.Add(harddrive);
                context.SaveChanges();
            }

            using (var context = new CheapWareContext(options))
            {
                var service = new ComputerRepo(context);
                listofharddrives = await service.GetHardDrives();
            }


            using (var context = new CheapWareContext(options))
            {
                Assert.Single(listofharddrives);
                Assert.Equal("test name", context.HardDrives.Single().Name);
            }
        }