public void BadEggValidationInvalidRouteProvider() { ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory()); TestHttpRequest httpRequest = new TestHttpRequest(); TestHttpResponse httpResponse = new TestHttpResponse(); IPluginClassesService pluginServices = new pm.PluginServices(_testPluginBadEgg) as IPluginClassesService; IPluginHelperService pluginHelperServices = _testPluginBadEgg.GetRequiredService <IPluginHelperService>(); IPluginTypesService pluginTypesService = _testPluginBadEgg.GetRequiredService <IPluginTypesService>(); INotificationService notificationService = _testPluginBadEgg.GetRequiredService <INotificationService>(); IIpValidation iPValidation = new TestIPValidation(); TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse); httpRequest.SetContext(httpContext); MockLoginProvider loginProvider = new MockLoginProvider(); MockClaimsProvider claimsProvider = new MockClaimsProvider(pluginServices); TestAuthenticationService authenticationService = new TestAuthenticationService(); RequestDelegate requestDelegate = async(context) => { await Task.Delay(0); }; RouteDataServices routeDataServices = new RouteDataServices(); BadEggMiddleware badEgg = new BadEggMiddleware(requestDelegate, null, routeDataServices, pluginHelperServices, pluginTypesService, iPValidation, settingsProvider, notificationService); }
public async Task RetrieveUniqueId_InvalidRequest_SiteId_Returns404() { ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory()); TestHttpRequest httpRequest = new TestHttpRequest(); httpRequest.Path = "/smokeTest/SiteId"; TestHttpResponse httpResponse = new TestHttpResponse(); IPluginHelperService pluginHelperServices = _testPluginSmokeTest.GetRequiredService <IPluginHelperService>(); IPluginTypesService pluginTypesService = _testPluginSmokeTest.GetRequiredService <IPluginTypesService>(); TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse); ILogger logger = new Logger(); using (WebSmokeTestMiddleware sut = new WebSmokeTestMiddleware(null, pluginHelperServices, pluginTypesService, settingsProvider, logger)) { List <WebSmokeTestItem> smokeTests = sut.SmokeTests; Assert.IsTrue(smokeTests.Count > 1); await sut.Invoke(httpContext); Assert.AreEqual(404, httpResponse.StatusCode); } }
public void BadEggValidationInvalidRequestDelegate() { ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory()); TestHttpRequest httpRequest = new TestHttpRequest(); TestHttpResponse httpResponse = new TestHttpResponse(); IPluginClassesService pluginServices = new pm.PluginServices(_testPluginBadEgg) as IPluginClassesService; IPluginHelperService pluginHelperServices = _testPluginBadEgg.GetRequiredService <IPluginHelperService>(); IPluginTypesService pluginTypesService = _testPluginBadEgg.GetRequiredService <IPluginTypesService>(); INotificationService notificationService = _testPluginBadEgg.GetRequiredService <INotificationService>(); IIpValidation iPValidation = new TestIPValidation(); TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse); httpRequest.SetContext(httpContext); MockLoginProvider loginProvider = new MockLoginProvider(); MockClaimsProvider claimsProvider = new MockClaimsProvider(pluginServices); TestAuthenticationService authenticationService = new TestAuthenticationService(); ActionDescriptorCollection actionDescriptorCollection = new ActionDescriptorCollection(new List <ActionDescriptor>(), 1); TestActionDescriptorCollectionProvider testActionDescriptorCollectionProvider = new TestActionDescriptorCollectionProvider(actionDescriptorCollection); RouteDataServices routeDataServices = new RouteDataServices(); BadEggMiddleware badEgg = new BadEggMiddleware(null, testActionDescriptorCollectionProvider, routeDataServices, pluginHelperServices, pluginTypesService, iPValidation, settingsProvider, notificationService); }
public async Task Validate_TestEndCalled_ISmokeTestProviderNotRegistered_Void() { ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory()); TestHttpRequest httpRequest = new TestHttpRequest(); httpRequest.Path = "/smokeTest/end/"; TestHttpResponse httpResponse = new TestHttpResponse(); IPluginHelperService pluginHelperServices = _testPluginSmokeTest.GetRequiredService <IPluginHelperService>(); IPluginTypesService pluginTypesService = _testPluginSmokeTest.GetRequiredService <IPluginTypesService>(); IServiceCollection serviceCollection = new ServiceCollection() as IServiceCollection; TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse, serviceCollection.BuildServiceProvider()); ILogger logger = new Logger(); bool nextDelegateCalled = false; RequestDelegate requestDelegate = async(context) => { nextDelegateCalled = true; await Task.Delay(0); }; using (WebSmokeTestMiddleware sut = new WebSmokeTestMiddleware(requestDelegate, pluginHelperServices, pluginTypesService, settingsProvider, logger)) { List <WebSmokeTestItem> smokeTests = sut.SmokeTests; Assert.IsTrue(smokeTests.Count > 1); await sut.Invoke(httpContext); Assert.IsFalse(nextDelegateCalled); Assert.AreEqual(200, httpResponse.StatusCode); Assert.IsNull(httpResponse.ContentType); } }
public async Task BadEggValidationSuccess() { ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory()); TestHttpRequest httpRequest = new TestHttpRequest(); TestHttpResponse httpResponse = new TestHttpResponse(); IPluginClassesService pluginServices = new pm.PluginServices(_testPluginBadEgg) as IPluginClassesService; IPluginHelperService pluginHelperServices = _testPluginBadEgg.GetRequiredService <IPluginHelperService>(); IPluginTypesService pluginTypesService = _testPluginBadEgg.GetRequiredService <IPluginTypesService>(); INotificationService notificationService = _testPluginBadEgg.GetRequiredService <INotificationService>(); IIpValidation iPValidation = new TestIPValidation(); TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse); httpRequest.SetContext(httpContext); MockLoginProvider loginProvider = new MockLoginProvider(); MockClaimsProvider claimsProvider = new MockClaimsProvider(pluginServices); TestAuthenticationService authenticationService = new TestAuthenticationService(); bool nextDelegateCalled = false; RequestDelegate requestDelegate = async(context) => { nextDelegateCalled = true; await Task.Delay(0); }; ActionDescriptorCollection actionDescriptorCollection = new ActionDescriptorCollection(new List <ActionDescriptor>(), 1); TestActionDescriptorCollectionProvider testActionDescriptorCollectionProvider = new TestActionDescriptorCollectionProvider(actionDescriptorCollection); RouteDataServices routeDataServices = new RouteDataServices(); BadEggMiddleware badEgg = new BadEggMiddleware(requestDelegate, testActionDescriptorCollectionProvider, routeDataServices, pluginHelperServices, pluginTypesService, iPValidation, settingsProvider, notificationService); await badEgg.Invoke(httpContext); Assert.IsTrue(nextDelegateCalled); }
public async Task LoginAutoLoginFromHeadersInvalidEncoding() { ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory()); LoginControllerSettings loginControllerSettings = settingsProvider.GetSettings <LoginControllerSettings>(nameof(LoginPlugin)); TestHttpRequest httpRequest = new TestHttpRequest(); TestHttpResponse httpResponse = new TestHttpResponse(); IPluginClassesService pluginServices = new pm.PluginServices(_testPluginLogin) as IPluginClassesService; TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse); httpRequest.SetContext(httpContext); MockLoginProvider loginProvider = new MockLoginProvider(); MockClaimsProvider claimsProvider = new MockClaimsProvider(pluginServices); TestAuthenticationService authenticationService = new TestAuthenticationService(); RequestDelegate requestDelegate = async(context) => { await Task.Delay(0); }; httpRequest.Headers.Add(SharedPluginFeatures.Constants.HeaderAuthorizationName, "Basic blahblahblah"); LoginMiddleware login = new LoginMiddleware(requestDelegate, loginProvider, settingsProvider, claimsProvider); await login.Invoke(httpContext, authenticationService); Assert.AreEqual(400, httpContext.Response.StatusCode); Assert.IsFalse(authenticationService.SignInAsyncCalled); }
public async Task LoginFromCookieValueCookieValidLoginUserFound() { ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory()); LoginControllerSettings loginControllerSettings = settingsProvider.GetSettings <LoginControllerSettings>(nameof(LoginPlugin)); TestRequestCookieCollection cookies = new TestRequestCookieCollection(); cookies.AddCookie("RememberMe", Shared.Utilities.Encrypt("123", loginControllerSettings.EncryptionKey)); TestHttpRequest httpRequest = new TestHttpRequest(cookies); TestHttpResponse httpResponse = new TestHttpResponse(); IPluginClassesService pluginServices = new pm.PluginServices(_testPluginLogin) as IPluginClassesService; TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse); httpRequest.SetContext(httpContext); MockLoginProvider loginProvider = new MockLoginProvider(); MockClaimsProvider claimsProvider = new MockClaimsProvider(pluginServices); TestAuthenticationService authenticationService = new TestAuthenticationService(); RequestDelegate requestDelegate = async(context) => { await Task.Delay(0); }; LoginMiddleware login = new LoginMiddleware(requestDelegate, loginProvider, settingsProvider, claimsProvider); await login.Invoke(httpContext, authenticationService); TestResponseCookies responseCookies = httpResponse.Cookies as TestResponseCookies; Assert.IsNotNull(responseCookies); Assert.IsTrue(authenticationService.SignInAsyncCalled); }
public async Task LoginAutoLoginFromHeadersInvalidUsernameAndPassword() { ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory()); LoginControllerSettings loginControllerSettings = settingsProvider.GetSettings <LoginControllerSettings>(nameof(LoginPlugin)); TestHttpRequest httpRequest = new TestHttpRequest(); TestHttpResponse httpResponse = new TestHttpResponse(); IPluginClassesService pluginServices = new pm.PluginServices(_testPluginLogin) as IPluginClassesService; TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse); httpRequest.SetContext(httpContext); MockLoginProvider loginProvider = new MockLoginProvider(); MockClaimsProvider claimsProvider = new MockClaimsProvider(pluginServices); TestAuthenticationService authenticationService = new TestAuthenticationService(); RequestDelegate requestDelegate = async(context) => { await Task.Delay(0); }; string encoded = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes("Miley:Cyrus")); httpRequest.Headers.Add(SharedPluginFeatures.Constants.HeaderAuthorizationName, "Basic " + encoded); LoginMiddleware login = new LoginMiddleware(requestDelegate, loginProvider, settingsProvider, claimsProvider); await login.Invoke(httpContext, authenticationService); Assert.IsFalse(authenticationService.SignInAsyncCalled); }
public void InitialiseSmokeTestPluginManager() { InitializeSmokeTestPluginManager(); ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory()); WebSmokeTestSettings settings = settingsProvider.GetSettings <WebSmokeTestSettings>(nameof(WebSmokeTest)); EncryptionKey = settings.EncryptionKey; }
public void LoginNullLoginProviderValue() { IPluginClassesService pluginServices = new pm.PluginServices(_testPluginLogin) as IPluginClassesService; ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory()); MockClaimsProvider claimsProvider = new MockClaimsProvider(pluginServices); RequestDelegate requestDelegate = async(context) => { await Task.Delay(0); }; LoginMiddleware login = new LoginMiddleware(requestDelegate, null, settingsProvider, claimsProvider); }
public void LoginNullRequestDelegateValue() { IPluginClassesService pluginServices = new pm.PluginServices(_testPluginLogin) as IPluginClassesService; MockLoginProvider loginProvider = new MockLoginProvider(); ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory()); MockClaimsProvider claimsProvider = new MockClaimsProvider(pluginServices); LoginMiddleware login = new LoginMiddleware(null, loginProvider, settingsProvider, claimsProvider); }
public async Task Validate_TestStartCalled_ISmokeTestProviderRegistered_Returns_NvpCodecValues() { ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory()); TestHttpRequest httpRequest = new TestHttpRequest(); httpRequest.Path = "/smokeTest/Start/"; TestHttpResponse httpResponse = new TestHttpResponse(); IPluginHelperService pluginHelperServices = _testPluginSmokeTest.GetRequiredService <IPluginHelperService>(); IPluginTypesService pluginTypesService = _testPluginSmokeTest.GetRequiredService <IPluginTypesService>(); IServiceCollection serviceCollection = new ServiceCollection() as IServiceCollection; NVPCodec codecValues = new NVPCodec(); codecValues.Add("username", "admin"); MockSmokeTestProvider smokeTestProvider = new MockSmokeTestProvider(codecValues); serviceCollection.AddSingleton <ISmokeTestProvider>(smokeTestProvider); TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse, serviceCollection.BuildServiceProvider()); ILogger logger = new Logger(); bool nextDelegateCalled = false; RequestDelegate requestDelegate = async(context) => { nextDelegateCalled = true; await Task.Delay(0); }; using (WebSmokeTestMiddleware sut = new WebSmokeTestMiddleware(requestDelegate, pluginHelperServices, pluginTypesService, settingsProvider, logger)) { List <WebSmokeTestItem> smokeTests = sut.SmokeTests; Assert.IsTrue(smokeTests.Count > 1); await sut.Invoke(httpContext); Assert.IsFalse(nextDelegateCalled); Assert.AreEqual(200, httpResponse.StatusCode); Assert.IsNull(httpResponse.ContentType); Assert.IsTrue(smokeTestProvider.StartCalled); byte[] data = new byte[httpResponse.Body.Length]; httpResponse.Body.Position = 0; httpResponse.Body.Read(data, 0, data.Length); string test = Decrypt(Encoding.UTF8.GetString(data), EncryptionKey); Assert.IsFalse(String.IsNullOrEmpty(test)); NVPCodec codec = new NVPCodec(); codec.Decode(test); Assert.AreEqual(1, codec.AllKeys.Length); Assert.IsTrue(codec.AllKeys.Contains("username")); Assert.AreEqual("admin", codec["username"]); } }
public async Task LoginNullContextValue() { IPluginClassesService pluginServices = new pm.PluginServices(_testPluginLogin) as IPluginClassesService; MockLoginProvider loginProvider = new MockLoginProvider(); ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory()); MockClaimsProvider claimsProvider = new MockClaimsProvider(pluginServices); TestAuthenticationService authenticationService = new TestAuthenticationService(); RequestDelegate requestDelegate = async(context) => { await Task.Delay(0); }; LoginMiddleware login = new LoginMiddleware(requestDelegate, loginProvider, settingsProvider, claimsProvider); await login.Invoke(null, authenticationService); }
public void LoadSmokeTests() { ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory()); IPluginHelperService pluginHelperServices = _testPluginSmokeTest.GetRequiredService <IPluginHelperService>(); IPluginTypesService pluginTypesService = _testPluginSmokeTest.GetRequiredService <IPluginTypesService>(); ILogger logger = new Logger(); using (WebSmokeTestMiddleware sut = new WebSmokeTestMiddleware(null, pluginHelperServices, pluginTypesService, settingsProvider, logger)) { List <WebSmokeTestItem> smokeTests = sut.SmokeTests; Assert.IsTrue(smokeTests.Count > 1); } }
public async Task BadEggValidationIgnoreValidation() { ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory()); BadEggSettings badEggSettings = settingsProvider.GetSettings <BadEggSettings>(SharedPluginFeatures.Constants.BadEggSettingsName); TestHttpRequest httpRequest = new TestHttpRequest(); TestHttpResponse httpResponse = new TestHttpResponse(); IPluginClassesService pluginServices = new pm.PluginServices(_testPluginBadEgg) as IPluginClassesService; IPluginHelperService pluginHelperServices = _testPluginBadEgg.GetRequiredService <IPluginHelperService>(); IPluginTypesService pluginTypesService = _testPluginBadEgg.GetRequiredService <IPluginTypesService>(); INotificationService notificationService = _testPluginBadEgg.GetRequiredService <INotificationService>(); IIpValidation iPValidation = new TestIPValidation(); IIpManagement ipManagement = _testPluginBadEgg.GetRequiredService <IIpManagement>(); TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse); httpRequest.SetContext(httpContext); MockLoginProvider loginProvider = new MockLoginProvider(); MockClaimsProvider claimsProvider = new MockClaimsProvider(pluginServices); TestAuthenticationService authenticationService = new TestAuthenticationService(); bool nextDelegateCalled = false; RequestDelegate requestDelegate = async(context) => { nextDelegateCalled = true; await Task.Delay(0); }; ActionDescriptorCollection actionDescriptorCollection = new ActionDescriptorCollection(new List <ActionDescriptor>(), 1); TestActionDescriptorCollectionProvider testActionDescriptorCollectionProvider = new TestActionDescriptorCollectionProvider(actionDescriptorCollection); RouteDataServices routeDataServices = new RouteDataServices(); httpRequest.Headers.Add(SharedPluginFeatures.Constants.BadEggValidationIgnoreHeaderName, badEggSettings.IgnoreValidationHeaderCode); BadEggMiddleware badEgg = new BadEggMiddleware(requestDelegate, testActionDescriptorCollectionProvider, routeDataServices, pluginHelperServices, pluginTypesService, iPValidation, settingsProvider, notificationService); await badEgg.Invoke(httpContext); Assert.IsTrue(httpContext.Response.Headers.ContainsKey(Constants.BadEggValidationIgnoreHeaderName)); Assert.AreEqual(httpContext.Response.Headers[Constants.BadEggValidationIgnoreHeaderName], Boolean.TrueString); Assert.IsTrue(nextDelegateCalled); Assert.AreEqual(200, httpContext.Response.StatusCode); }
public async Task RetrieveUniqueId_ValidRequest_Count_Enabled_Returns200() { ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory()); TestHttpRequest httpRequest = new TestHttpRequest(); httpRequest.Path = "/smokeTest/Count/"; TestHttpResponse httpResponse = new TestHttpResponse(); IPluginHelperService pluginHelperServices = _testPluginSmokeTest.GetRequiredService <IPluginHelperService>(); IPluginTypesService pluginTypesService = _testPluginSmokeTest.GetRequiredService <IPluginTypesService>(); TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse); ILogger logger = new Logger(); bool nextDelegateCalled = false; RequestDelegate requestDelegate = async(context) => { nextDelegateCalled = true; await Task.Delay(0); }; using (WebSmokeTestMiddleware sut = new WebSmokeTestMiddleware(requestDelegate, pluginHelperServices, pluginTypesService, settingsProvider, logger)) { List <WebSmokeTestItem> smokeTests = sut.SmokeTests; Assert.IsTrue(smokeTests.Count > 1); Assert.IsFalse(nextDelegateCalled); await sut.Invoke(httpContext); Assert.AreEqual(200, httpResponse.StatusCode); byte[] data = new byte[httpResponse.Body.Length]; httpResponse.Body.Position = 0; httpResponse.Body.Read(data, 0, data.Length); string count = Decrypt(Encoding.UTF8.GetString(data), EncryptionKey); if (Int32.TryParse(count, out int actualCount)) { Assert.IsTrue(actualCount > 1); } else { throw new InvalidCastException("Failed to convert returned count"); } } }
public async void LoginNullAuthenticationValueOnInvoke() { TestRequestCookieCollection cookies = new TestRequestCookieCollection(); cookies.AddCookie("RememberMe", "1"); TestHttpRequest httpRequest = new TestHttpRequest(cookies); TestHttpResponse httpResponse = new TestHttpResponse(); IPluginClassesService pluginServices = new pm.PluginServices(_testPluginLogin) as IPluginClassesService; TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse); MockLoginProvider loginProvider = new MockLoginProvider(); ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory()); MockClaimsProvider claimsProvider = new MockClaimsProvider(pluginServices); RequestDelegate requestDelegate = async(context) => { await Task.Delay(0); }; LoginMiddleware login = new LoginMiddleware(requestDelegate, loginProvider, settingsProvider, claimsProvider); await login.Invoke(httpContext, null); }
public async Task Validate_TestStartCalled_ISmokeTestProviderNotRegistered_Returns_EmptyString() { ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory()); TestHttpRequest httpRequest = new TestHttpRequest(); httpRequest.Path = "/smokeTest/Start/"; TestHttpResponse httpResponse = new TestHttpResponse(); IPluginHelperService pluginHelperServices = _testPluginSmokeTest.GetRequiredService <IPluginHelperService>(); IPluginTypesService pluginTypesService = _testPluginSmokeTest.GetRequiredService <IPluginTypesService>(); TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse, _testPluginSmokeTest.GetServiceProvider()); ILogger logger = new Logger(); bool nextDelegateCalled = false; RequestDelegate requestDelegate = async(context) => { nextDelegateCalled = true; await Task.Delay(0); }; using (WebSmokeTestMiddleware sut = new WebSmokeTestMiddleware(requestDelegate, pluginHelperServices, pluginTypesService, settingsProvider, logger)) { List <WebSmokeTestItem> smokeTests = sut.SmokeTests; Assert.IsTrue(smokeTests.Count > 1); await sut.Invoke(httpContext); Assert.IsFalse(nextDelegateCalled); Assert.AreEqual(200, httpResponse.StatusCode); Assert.IsNull(httpResponse.ContentType); byte[] data = new byte[httpResponse.Body.Length]; httpResponse.Body.Position = 0; httpResponse.Body.Read(data, 0, data.Length); string test = Decrypt(Encoding.UTF8.GetString(data), EncryptionKey); Assert.IsTrue(String.IsNullOrEmpty(test)); } }
public async Task RetrieveUniqueId_ValidRequest_RetrieveTest_Enabled_Returns200() { ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory()); TestHttpRequest httpRequest = new TestHttpRequest(); httpRequest.Path = "/smokeTest/Test/1"; TestHttpResponse httpResponse = new TestHttpResponse(); IPluginHelperService pluginHelperServices = _testPluginSmokeTest.GetRequiredService <IPluginHelperService>(); IPluginTypesService pluginTypesService = _testPluginSmokeTest.GetRequiredService <IPluginTypesService>(); TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse); ILogger logger = new Logger(); bool nextDelegateCalled = false; RequestDelegate requestDelegate = async(context) => { nextDelegateCalled = true; await Task.Delay(0); }; using (WebSmokeTestMiddleware sut = new WebSmokeTestMiddleware(requestDelegate, pluginHelperServices, pluginTypesService, settingsProvider, logger)) { List <WebSmokeTestItem> smokeTests = sut.SmokeTests; Assert.IsTrue(smokeTests.Count > 1); await sut.Invoke(httpContext); Assert.IsFalse(nextDelegateCalled); Assert.AreEqual(200, httpResponse.StatusCode); Assert.AreEqual("application/json", httpResponse.ContentType); byte[] data = new byte[httpResponse.Body.Length]; httpResponse.Body.Position = 0; httpResponse.Body.Read(data, 0, data.Length); string test = Decrypt(Encoding.UTF8.GetString(data), EncryptionKey); Assert.IsTrue(test.Contains("Please try again")); Assert.IsTrue(test.Contains("Method\":\"POST") || test.Contains("Method\":\"GET")); } }
public async Task RetrieveUniqueId_ValidRequest_SiteId_Disabled_Returns200() { ISettingsProvider settingsProvider = new pm.DefaultSettingProvider(Directory.GetCurrentDirectory()); TestHttpRequest httpRequest = new TestHttpRequest(); httpRequest.Path = "/smokeTest/SiteId/"; TestHttpResponse httpResponse = new TestHttpResponse(); IPluginHelperService pluginHelperServices = _testPluginSmokeTest.GetRequiredService <IPluginHelperService>(); IPluginTypesService pluginTypesService = _testPluginSmokeTest.GetRequiredService <IPluginTypesService>(); TestHttpContext httpContext = new TestHttpContext(httpRequest, httpResponse); ILogger logger = new Logger(); bool nextDelegateCalled = false; RequestDelegate requestDelegate = async(context) => { nextDelegateCalled = true; await Task.Delay(0); }; using (WebSmokeTestMiddleware sut = new WebSmokeTestMiddleware(requestDelegate, pluginHelperServices, pluginTypesService, settingsProvider, logger)) { sut.Enabled = false; List <WebSmokeTestItem> smokeTests = sut.SmokeTests; Assert.IsTrue(smokeTests.Count > 1); await sut.Invoke(httpContext); Assert.IsTrue(nextDelegateCalled); Assert.AreEqual(200, httpResponse.StatusCode); byte[] data = new byte[httpResponse.Body.Length]; httpResponse.Body.Position = 0; httpResponse.Body.Read(data, 0, data.Length); string id = Encoding.UTF8.GetString(data); Assert.AreEqual("", id); } }