public void Registered_User_Can_Get_Collections() { // Spoof an authenticated user by generating a ClaimsPrincipal var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, "FIREBASE_USER1"), }, "TestAuthentication")); // Spoof UserController var controller = new CollectionController(_fakeUserRepo.Object, _fakeCollectionRepo.Object, _fakeProjColRepo.Object); controller.ControllerContext = new ControllerContext(); // Required to create the controller controller.ControllerContext.HttpContext = new DefaultHttpContext { User = user }; // Pretend the user is making a request to the controller // Attempt to Get this User's posts var response = controller.GetByUserId(); // Returns Ok Assert.IsType <OkObjectResult>(response); }
public void Anonymous_User_Can_Not_Get_Collections() { // Spoof an authenticated user by generating a ClaimsPrincipal var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, "FIREBASE_USER666"), }, "TestAuthentication")); // Spoof UserController var controller = new CollectionController(_fakeUserRepo.Object, _fakeCollectionRepo.Object, _fakeProjColRepo.Object); controller.ControllerContext = new ControllerContext(); // Required to create the controller controller.ControllerContext.HttpContext = new DefaultHttpContext { User = user }; // Pretend the user is making a request to the controller // Attempt to Get this User's collections var response = controller.GetByUserId(); // Returns Ok Assert.IsType <NotFoundResult>(response); // Verify we never called the repo method _fakeCollectionRepo.Verify(r => r.Get(It.IsAny <int>()), Times.Never()); }