[DataRow("PROJECT=p&SERVER=http://s", "hotspot")] // lookup is not case sensitive -> only hotspot is missing public async Task ProcessRequest_MissingParameter_Returns400StatusCode(string wholeQueryString, string missingParamList) { var testLogger = new TestLogger(logToConsole: true); var apiHandlerMock = new Mock <IOpenInIDERequestHandler>(); var context = CreateContext(wholeQueryString); var testSubject = new ShowHotspotOwinRequestHandler(apiHandlerMock.Object, testLogger); // Act await testSubject.ProcessRequest(context); context.Response.StatusCode.Should().Be(400); // Note: passing a variable number of items to a test is messy. Here, it's // simpler to pass a string and split it. var missingParamNames = missingParamList.Split(';'); foreach (var paramName in missingParamNames) { testLogger.AssertPartialOutputStringExists(paramName); } CheckApiHandlerNotCalled(apiHandlerMock); }
[DataRow("project=p&server=http://s&hotspot=h&unknown=oXXX", "http://s", "p", "h", null)] // unknown parameters are ignored public async Task ProcessRequest_ValidRequest_HandlerCalledAndReturns200StatusCode(string wholeQueryString, string expectedServer, string expectedProject, string expectedHotspot, string expectedOrganization) { var apiHandlerMock = new Mock <IOpenInIDERequestHandler>(); var context = CreateContext(wholeQueryString); var testSubject = new ShowHotspotOwinRequestHandler(apiHandlerMock.Object, new TestLogger(logToConsole: true)); // Act await testSubject.ProcessRequest(context); context.Response.StatusCode.Should().Be(200); CheckApiHandlerCalledWithExpectedValues(apiHandlerMock, expectedServer, expectedProject, expectedHotspot, expectedOrganization); }
public async Task ProcessRequest_InvalidServerParameter_Returns400StatusCode() { const string invalidUrl = "NOT_A_URL"; var testLogger = new TestLogger(logToConsole: true); var apiHandlerMock = new Mock <IOpenInIDERequestHandler>(); var context = CreateContext($"server={invalidUrl}&project=any&hotspot=&any"); var testSubject = new ShowHotspotOwinRequestHandler(apiHandlerMock.Object, testLogger); // Act await testSubject.ProcessRequest(context); context.Response.StatusCode.Should().Be(400); testLogger.AssertPartialOutputStringExists(invalidUrl); CheckApiHandlerNotCalled(apiHandlerMock); }