public async Task LoggingEndpoint_NoHeader() { // Arrange var request = new LoggingEndpointRequest(); _controller.Request = new HttpRequestMessage(); // Act var response = await _controller.LoggingEndpoint(request); // Assert //N/A }
public async Task <LoggingEndpointResponse> AddLog(LoggingEndpointRequest logData) { var log = new Log { Logger = logData.Logger, Level = logData.Level, Message = logData.Message, ApplicationId = logData.ApplicationId }; var response = await Add(log); return(new LoggingEndpointResponse { Success = response != null }); }
public async Task LoggingEndpoint_InvalidToken() { // Arrange var request = new LoggingEndpointRequest(); _controller.Request = new HttpRequestMessage(); _controller.Request.Headers.Add("access_token", new List <string> { "token" }); _mock.Setup(x => x.CheckAccessToken("token")).Returns(false); // Act var response = await _controller.LoggingEndpoint(request); // Assert //N/A }
public async Task LoggingEndpoint_NullResponse() { // Arrange var request = new LoggingEndpointRequest(); _controller.Request = new HttpRequestMessage(); _controller.Request.Headers.Add("access_token", new List <string> { "token" }); _mock.Setup(x => x.CheckAccessToken("token")).Returns(true); _mock.Setup(x => x.UpdateNCheckLimitExceeded("token")).Returns(false); _mock.Setup(x => x.AddLog(request)).ReturnsAsync(null); // Act var response = await _controller.LoggingEndpoint(request); // Assert //N/A }
public async Task <LoggingEndpointResponse> LoggingEndpoint(LoggingEndpointRequest request) { if (request == null) { throw new HttpResponseException(new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, Content = new StringContent(Constants.HttpResponse_400) }); } var re = Request; var headers = re.Headers; if (headers.Contains(Constants.Header_AccessToken)) { try { var token = headers.GetValues(Constants.Header_AccessToken).First(); //Check token bool isValidToken = _logService.CheckAccessToken(token); if (!isValidToken) { throw new HttpResponseException(new HttpResponseMessage { StatusCode = HttpStatusCode.Forbidden, Content = new StringContent(Constants.HttpResponse_403) }); } //Check if (_logService.UpdateNCheckLimitExceeded(token)) { throw new HttpResponseException(new HttpResponseMessage { StatusCode = HttpStatusCode.Forbidden, Content = new StringContent(Constants.HttpResponse_403_LimitExceeded) }); } //Add log LoggingEndpointResponse response = await _logService.AddLog(request); if (response == null) { throw new HttpResponseException(new HttpResponseMessage { StatusCode = HttpStatusCode.Forbidden, Content = new StringContent(Constants.HttpResponse_403) }); } //Response return(response); } catch (Exception) { throw new HttpResponseException(new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError, Content = new StringContent(Constants.HttpResponse_500) }); } } throw new HttpResponseException(new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, Content = new StringContent(Constants.HttpResponse_400) }); }