public IActionResult GetTerms() { List <string> terms = _glossaryService.Get() //< Gets all the glosarries .Select(_glossary => _glossary.Term) //< Selects only the term .ToList(); //< Converts to a list return(Ok(terms)); }
public GlossaryDetail Get(GlossaryCriteria criteria) { using (var uow = UnitOfWorkFactory.Create <NovelContext>()) { var service = new GlossaryService(uow); var detail = service.Get(criteria); detail.Summarize = service.View <Summarize>().Where(w => w.SourceTable == R.SourceTable.GLOSSARY && w.SourceID == detail.ID).SingleOrDefault() ?? new Summarize(); detail.UserAction = new UserActionFacade().Get(new ViewForm { UserID = criteria.ByUserID, SourceID = detail.ID, SourceTable = R.SourceTable.GLOSSARY }); return(detail); } }
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); } }