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); } }
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"); } }
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); } }
public GlossaryService(GlossaryDbContext context) { _context = context; }
public CustomGlossaryService(GlossaryDbContext glossaryDbContext) { db = glossaryDbContext; }