public void ShowReturns401WhenUserDoesntOwnList() { var options = new DbContextOptionsBuilder <ReadingListApiContext>() .UseInMemoryDatabase("show_returns_401") .Options; using (var context = new ReadingListApiContext(options)) { ReadingList readingList = new ReadingListFixture().ReadingList(); User user = new UserFixture().User(); User unauthorizedUser = new User { Email = "unauthorized test email", Avatar = "unauthorized test avatar", }; user.ReadingLists.Add(readingList); context.Users.AddRange(new List <User>() { user, unauthorizedUser }); context.SaveChanges(); SessionHelperStub session = new SessionHelperStub(unauthorizedUser); ReadingListController controller = new ReadingListController(context, session); var result = controller.Get(readingList.ReadingListId); Assert.IsType <NotFoundResult>(result); } }
public void ReturnsAReadingList() { var options = new DbContextOptionsBuilder <ReadingListApiContext>() .UseInMemoryDatabase("returns_a_reading_list") .Options; using (var context = new ReadingListApiContext(options)) { User user = new UserFixture().User(); ReadingList readingList = new ReadingListFixture().ReadingList(); user.ReadingLists.Add(readingList); context.Users.Add(user); context.SaveChanges(); SessionHelperStub session = new SessionHelperStub(user); ReadingListController controller = new ReadingListController(context, session); JsonResult result = controller.Get(readingList.ReadingListId) as JsonResult; Assert.Equal(readingList, result.Value); } }