public void Get_Collection_For_Id_Not_In_Db_Returns_Not_Found() { // 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 collection not in db var response = controller.GetByCollectionId(666); // Returns Ok Assert.IsType <NotFoundResult>(response); }
public void Anonymous_User_Can_Not_Get_Collection_By_Id() { // 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 someone's collection var response = controller.GetByCollectionId(2); // Returns Ok Assert.IsType <NotFoundResult>(response); // Verify we never called the repo method _fakeCollectionRepo.Verify(r => r.GetByCollectionId(It.IsAny <int>()), Times.Never()); }