public void TestGetGoals() { var options = new DbContextOptionsBuilder <MyPracticeJournalContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; using (var db = new MyPracticeJournalContext(options)) { db.Goals.Add(new Goal { Name = "One" }); db.Goals.Add(new Goal { Name = "Two" }); db.Goals.Add(new Goal { Name = "Three" }); db.SaveChanges(); } // Use a clean instance of the context to run the test using (var context = new MyPracticeJournalContext(options)) { var service = new GoalService(_mapper, context); var result = service.GetGoal(1); Assert.IsNotNull(result); } }
public void TestCreateGoal() { var options = new DbContextOptionsBuilder <MyPracticeJournalContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; using (var db = new MyPracticeJournalContext(options)) { var goalService = new GoalService(_mapper, db); var goalDto = new GoalDto { Name = "One", Description = "Desc One" }; goalService.CreateGoal(goalDto); } using (var db = new MyPracticeJournalContext(options)) { Assert.AreEqual(1, db.Goals.Count()); Assert.AreEqual("One", db.Goals.Single().Name); } }
public ReportService(IMapper mapper, MyPracticeJournalContext db) { _mapper = mapper; _db = db; }
public MyWeekService(IMapper mapper, MyPracticeJournalContext db) { _mapper = mapper; _db = db; }