public void Delete_Access_Token_Invalid_User() { var controller = new AuthController(_dbCtx); var creds = new LoginCredentials() { Username = "******", Password = "******" }; var result = controller.LoginUser(creds) as ObjectResult; var token = ((AuthResponse)result.Value).ResponseToken; var httpContext = new DefaultHttpContext(); httpContext.Request.Headers[_config.authHeader] = $"Bearer {token}"; var controllerContext = new ControllerContext() { HttpContext = httpContext }; var canvasController = new CanvasAccessTokenController(_dbCtx); canvasController.ControllerContext = controllerContext; var patToDelete = _dbCtx.PersonalAccessTokens.Where(x => x.TokenName.Equals("Choc Chip Cupcake")).FirstOrDefault(); canvasController.DeleteAccessToken(patToDelete.Id); var outcome = _dbCtx.PersonalAccessTokens.Where(x => x.Id == patToDelete.Id).FirstOrDefault() != null; Assert.True(outcome); }
public void Get_Access_Tokens_Invalid_User() { var controller = new AuthController(_dbCtx); var creds = new LoginCredentials() { Username = "******", Password = "******" }; var result = controller.LoginUser(creds) as ObjectResult; var token = ((AuthResponse)result.Value).ResponseToken; var httpContext = new DefaultHttpContext(); httpContext.Request.Headers[_config.authHeader] = $"Bearer {token}"; var controllerContext = new ControllerContext() { HttpContext = httpContext }; var canvasController = new CanvasAccessTokenController(_dbCtx); canvasController.ControllerContext = controllerContext; var response = canvasController.GetUserAccessTokens(); var objResult = response as ObjectResult; var objValue = (ListResponse <CanvasPersonalAccessToken>)objResult.Value; var outcome = objValue.ListContent == null; Assert.True(outcome); }
public void Edit_Access_Token_Invalid_User() { var controller = new AuthController(_dbCtx); var creds = new LoginCredentials() { Username = "******", Password = "******" }; var result = controller.LoginUser(creds) as ObjectResult; var token = ((AuthResponse)result.Value).ResponseToken; var httpContext = new DefaultHttpContext(); httpContext.Request.Headers[_config.authHeader] = $"Bearer {token}"; var controllerContext = new ControllerContext() { HttpContext = httpContext }; var canvasController = new CanvasAccessTokenController(_dbCtx); canvasController.ControllerContext = controllerContext; var tokenToUpdate = _dbCtx.PersonalAccessTokens.Where(x => x.TokenName.Equals("Nolen1")).FirstOrDefault(); var updatedInfo = new CanvasPersonalAccessToken() { Id = tokenToUpdate.Id, TokenName = tokenToUpdate.TokenName, AccessToken = tokenToUpdate.AccessToken, AppUserId = tokenToUpdate.AppUserId, RowVersion = tokenToUpdate.RowVersion }; updatedInfo.TokenName = "Nolen31"; canvasController.EditAccessToken(updatedInfo); var updatedToken = _dbCtx.PersonalAccessTokens.Where(x => x.TokenName.Equals("Nolen31")).FirstOrDefault(); var outcome = updatedToken == null; Assert.True(outcome); }
public void Get_Access_Token_Valid_But_Wrong_User() { var controller = new AuthController(_dbCtx); var creds = new LoginCredentials() { Username = "******", Password = "******" }; var result = controller.LoginUser(creds) as ObjectResult; var token = ((AuthResponse)result.Value).ResponseToken; var httpContext = new DefaultHttpContext(); httpContext.Request.Headers[_config.authHeader] = $"Bearer {token}"; var controllerContext = new ControllerContext() { HttpContext = httpContext }; var canvasController = new CanvasAccessTokenController(_dbCtx); canvasController.ControllerContext = controllerContext; var tokenToGet = _dbCtx.PersonalAccessTokens.Where(x => x.TokenName.Equals("FirstToken")).FirstOrDefault(); var response = canvasController.GetUserAccessTokenById(tokenToGet.Id); var objResult = response as ObjectResult; var objValue = (ObjectResponse <CanvasPersonalAccessToken>)objResult.Value; var tokenRetreived = objValue.Value; var outcome = tokenRetreived == null; Assert.True(outcome); }
public void Add_Access_Token_Invalid_User() { var controller = new AuthController(_dbCtx); var creds = new LoginCredentials() { Username = "******", Password = "******" }; var result = controller.LoginUser(creds) as ObjectResult; var token = ((AuthResponse)result.Value).ResponseToken; var httpContext = new DefaultHttpContext(); httpContext.Request.Headers[_config.authHeader] = $"Bearer {token}"; var controllerContext = new ControllerContext() { HttpContext = httpContext }; var canvasController = new CanvasAccessTokenController(_dbCtx); canvasController.ControllerContext = controllerContext; canvasController.AddCanvasToken(new CanvasToken() { TokenName = "NewToken2", ApiKey = _canvasTokenHelper.CanvasTokenGenerator() }); var tokenAdded = _dbCtx.PersonalAccessTokens.Where(x => x.TokenName.Equals("NewToken2")).FirstOrDefault(); var outcome = tokenAdded == null; Assert.True(outcome); }