コード例 #1
0
        public async void GetRamByNameTest()
        {
            var options = new DbContextOptionsBuilder <CheapWareContext>()
                          .UseInMemoryDatabase(databaseName: "GetRamByNameDatabase")
                          .Options;
            var ram1 = new Rams {
                Name = "test name1", Speed = "1700 Mghrtz", Size = "8GB", Price = 110.99M
            };
            var ram2 = new Rams {
                Name = "test name2", Speed = "1900 Mghrtz", Size = "16GB", Price = 150.99M
            };

            Ram ram = null;

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

            using (var context = new CheapWareContext(options))
            {
                var service = new ComputerRepo(context);
                ram = await service.GetRamByName("test name1");
            }

            using (var context = new CheapWareContext(options))
            {
                Assert.Equal("1700 Mghrtz", ram.Speed);
                Assert.Equal("8GB", ram.Size);
                Assert.Equal(110.99M, ram.Price);
            }
        }