Exemple #1
0
        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"]);
            }
        }
Exemple #2
0
        public async Task Validate_TestEndCalled_ISmokeTestProviderRegistered_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;
            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.EndCalled);
            }
        }