コード例 #1
0
        public void GlossaryServiceShouldAddNewItemAndSearch()
        {
            using (var context = new GlossaryDbContext(Options))
            {
                var service = new GlossaryService(context);
                var t       = Task.Run(async() => await service.Create(Fake1)).Result;
            }

            GlossaryItem Inserted;

            // Use a separate instance of the context to verify correct data was saved to database
            using (var context = new GlossaryDbContext(Options))
            {
                var service = new GlossaryService(context);
                Inserted = Task.Run(async() => await service.Get(Fake1.Id)).Result;
                Assert.AreEqual(Fake1.Id, Inserted.Id);
            }
        }
コード例 #2
0
        public void GlosssaryServicesShouldUpdateAndDeleteanItem()
        {
            using (var context = new GlossaryDbContext(Options))
            {
                var service = new GlossaryService(context);
                var t       = Task.Run(async() => await service.Create(Fake1)).Result;
            }

            GlossaryItem Updated;

            // Use a separate instance of the context to verify correct data was saved to database
            using (var context = new GlossaryDbContext(Options))
            {
                var service = new GlossaryService(context);
                var i       = Task.Run(async() => await service.Update(new GlossaryItem {
                    Id = Fake1.Id, Term = "Updated", Definition = "Updated"
                })).Result;
                Updated = Task.Run(async() => await service.Get(Fake1.Id)).Result;
                Assert.AreEqual(Updated.Id, Fake1.Id);
                Assert.AreEqual(Updated.Term, "Updated");
                Assert.AreEqual(Updated.Definition, "Updated");
            }
        }
コード例 #3
0
        public void GlosssaryServicesShouldReturnTheListOfItems()
        {
            var options = new DbContextOptionsBuilder <GlossaryDbContext>()
                          .UseInMemoryDatabase(databaseName: "List_database")
                          .Options;

            using (var context = new GlossaryDbContext(options))
            {
                var service1 = new GlossaryService(context);
                var t1       = Task.Run(async() => await service1.Create(Fake1)).Result;
                var t2       = Task.Run(async() => await service1.Create(Fake2)).Result;
                var t3       = Task.Run(async() => await service1.Create(Fake3)).Result;
            }

            var items = new List <GlossaryItem>();

            // Use a separate instance of the context to verify correct data was saved to database
            using (var context1 = new GlossaryDbContext(options))
            {
                var service2 = new GlossaryService(context1);
                items = Task.Run(async() => await service2.Get("")).Result;
                Assert.AreEqual(items.Count, 3);
            }
        }
コード例 #4
0
 public GlossaryService(GlossaryDbContext context)
 {
     _context = context;
 }
コード例 #5
0
 public CustomGlossaryService(GlossaryDbContext glossaryDbContext)
 {
     db = glossaryDbContext;
 }