Exemplo n.º 1
0
        /// <summary>
        /// Helper to execute Sync Http tests
        /// </summary>
        /// <param name="testWebApplication">The test application for which tests are to be executed</param>
        /// <param name="expectedCount">number of expected RDD calls to be made by the test application </param>
        /// <param name="count">number to RDD calls to be made by the test application </param>
        /// <param name="accessTimeMax">approximate maximum time taken by RDD Call.  </param>
        private void ExecuteSyncSqlTests(TestWebApplication testWebApplication, int expectedCount, int count, TimeSpan accessTimeMax)
        {
            testWebApplication.DoTest(
                application =>
            {
                application.ExecuteAnonymousRequest(QueryStringOutboundSql + count);

                //// The above request would have trigged RDD module to monitor and create RDD telemetry
                //// Listen in the fake endpoint and see if the RDDTelemtry is captured

                var allItems = DeploymentAndValidationTools.SdkEventListener.ReceiveAllItemsDuringTimeOfType <TelemetryItem <RemoteDependencyData> >(DeploymentAndValidationTools.SleepTimeForSdkToSendEvents).ToArray();
                var sqlItems = allItems.Where(i => i.data.baseData.type == "SQL").ToArray();


                Assert.AreEqual(
                    expectedCount,
                    sqlItems.Length,
                    "Total Count of Remote Dependency items for SQL collected is wrong.");

                foreach (var sqlItem in sqlItems)
                {
                    string spName = "GetTopTenMessages";
                    this.Validate(
                        sqlItem,
                        ResourceNameSQLToDevApm,
                        spName,
                        accessTimeMax, successFlagExpected: true,
                        sqlErrorCodeExpected: "0",
                        sqlErrorMessageExpected: null);
                }
            });
        }
        /// <summary>
        /// Helper to execute Sync Http tests
        /// </summary>
        /// <param name="testWebApplication">The test application for which tests are to be executed</param>
        /// <param name="success">indicates if the tests should test success or failure case</param>
        /// <param name="count">number to RDD calls to be made by the test application.  </param>
        /// <param name="accessTimeMax">approximate maximum time taken by RDD Call.  </param>
        private void ExecuteSyncHttpPostTests(TestWebApplication testWebApplication, bool success, int count, TimeSpan accessTimeMax, string resultCodeExpected)
        {
            testWebApplication.DoTest(
                application =>
            {
                var queryString          = success ? QueryStringOutboundHttpPost : QueryStringOutboundHttpPostFailed;
                var resourceNameExpected = success ? ResourceNameHttpToBing : ResourceNameHttpToFailedRequest;
                application.ExecuteAnonymousRequest(queryString + count);

                //// The above request would have trigged RDD module to monitor and create RDD telemetry
                //// Listen in the fake endpoint and see if the RDDTelemtry is captured
                var allItems  = DeploymentAndValidationTools.SdkEventListener.ReceiveAllItemsDuringTimeOfType <TelemetryItem <RemoteDependencyData> >(DeploymentAndValidationTools.SleepTimeForSdkToSendEvents);
                var httpItems = allItems.Where(i => i.data.baseData.type == "Http").ToArray();

                // Validate the RDD Telemetry properties
                Assert.AreEqual(
                    count,
                    httpItems.Length,
                    "Total Count of Remote Dependency items for HTTP collected is wrong.");

                foreach (var httpItem in httpItems)
                {
                    this.Validate(httpItem, resourceNameExpected, accessTimeMax, success, "POST", resultCodeExpected);
                }
            });
        }
        /// <summary>
        /// Helper to execute Azure SDK tests.
        /// </summary>
        /// <param name="testWebApplication">The test application for which tests are to be executed.</param>
        /// <param name="count">number to RDD calls to be made by the test application.</param>
        /// <param name="type"> type of azure call.</param>
        /// <param name="expectedUrl">expected url for azure call.</param>
        private void ExecuteAzureSDKTests(TestWebApplication testWebApplication, int count, string type, string expectedUrl)
        {
            testWebApplication.DoTest(
                application =>
            {
                application.ExecuteAnonymousRequest(string.Format(QueryStringOutboundAzureSdk, type, count));

                //// The above request would have trigged RDD module to monitor and create RDD telemetry
                //// Listen in the fake endpoint and see if the RDDTelemtry is captured
                var allItems  = DeploymentAndValidationTools.SdkEventListener.ReceiveAllItemsDuringTimeOfType <TelemetryItem <RemoteDependencyData> >(DeploymentAndValidationTools.SleepTimeForSdkToSendEvents);
                var httpItems = allItems.Where(i => i.data.baseData.type == "Http").ToArray();
                int countItem = 0;

                foreach (var httpItem in httpItems)
                {
                    TimeSpan accessTime = TimeSpan.Parse(httpItem.data.baseData.duration);
                    Assert.IsTrue(accessTime.TotalMilliseconds >= 0, "Access time should be above zero for azure calls");

                    string actualSdkVersion = httpItem.tags[new ContextTagKeys().InternalSdkVersion];
                    Assert.IsTrue(actualSdkVersion.Contains(DeploymentAndValidationTools.ExpectedSDKPrefix), "Actual version:" + actualSdkVersion);

                    var url = httpItem.data.baseData.data;
                    if (url.Contains(expectedUrl))
                    {
                        countItem++;
                    }
                    else
                    {
                        Assert.Fail("ExecuteAzureSDKTests.url not matching for " + url);
                    }
                }

                Assert.IsTrue(countItem >= count, "Azure " + type + " access captured " + countItem + " is less than " + count);
            });
        }
        /// <summary>
        /// Verify ExceptionStatistics is collected
        /// </summary>
        private void TestExceptionStatisctics(TestWebApplication testApplication)
        {
            //testApplication.DoTest(
            //    (application, platform) =>
            //    {
            //        // Throw 1 handled and 1 unhandled exception
            //        const string queryString = "handledCount=1&isUnhandled=true";
            //        const string pageName = "PageThrowsExceptions.aspx";

            //        application.ExecuteAnonymousRequest(pageName, queryString);

            //        //// The above request would have trigged APMC into action and APMC should have collected exception statistics
            //        //// AIC/SDK requests for this every 5 seconds and sends to the fake end point.
            //        //// Listen in the fake endpoint and see if the exception statistics telemtry is captured
            //        //// Sleep for some secs to give SDK the time to sent the events to Fake DataPlatform.
            //        Thread.Sleep(10000);

            //        var allItems = platform.GetAllReceivedDataItems();

            //        var items = allItems.Where(i => i.GetFieldValue("name").Equals("Microsoft.ApplicationInsights.Metric")).ToArray();

            //        // We should recieve 1 item for unhandled exception and 1 for handled exception
            //        Assert.AreEqual(2, items.Length, "Total Count of Exception Statistics items collected in wrong.");
            //    });
        }
        private void ExecuteSyncHttpClientTests(TestWebApplication testWebApplication, TimeSpan accessTimeMax, string resultCodeExpected)
        {
            testWebApplication.DoTest(
                application =>
            {
                var queryString          = "?type=httpClient&count=1";
                var resourceNameExpected = new Uri("http://www.google.com/404");
                application.ExecuteAnonymousRequest(queryString);

                //// The above request would have trigged RDD module to monitor and create RDD telemetry
                //// Listen in the fake endpoint and see if the RDDTelemtry is captured
                var allItems  = DeploymentAndValidationTools.SdkEventListener.ReceiveAllItemsDuringTimeOfType <TelemetryItem <RemoteDependencyData> >(DeploymentAndValidationTools.SleepTimeForSdkToSendEvents);
                var httpItems = allItems.Where(i => i.data.baseData.type == "Http").ToArray();

                Assert.AreEqual(
                    1,
                    httpItems.Length,
                    "Total Count of Remote Dependency items for HTTP collected is wrong.");

                foreach (var httpItem in httpItems)
                {
                    // This is a call to google.com/404 which will fail but typically takes longer time. So accesstime can more than normal.
                    this.Validate(httpItem, resourceNameExpected, accessTimeMax.Add(TimeSpan.FromSeconds(15)), false, "GET", resultCodeExpected);
                }
            });
        }
Exemplo n.º 6
0
        public void UnloadWebModules(Type moduleType){
            ReactiveModuleBase.Unload(moduleType);
            using var application = new TestWebApplication(moduleType, false);
            application.AddModule((ModuleBase) moduleType.CreateInstance(), nameof(UnloadWebModules));

            application.Modules.FirstOrDefault(m => m.GetType()==moduleType).ShouldBeNull();
        }
        /// <summary>
        /// Helper to execute Azure SDK tests.
        /// </summary>
        /// <param name="testWebApplication">The test application for which tests are to be executed.</param>
        /// <param name="count">number to RDD calls to be made by the test application.</param>
        /// <param name="type"> type of azure call.</param>
        /// <param name="expectedUrl">expected url for azure call.</param>
        private void ExecuteAzureSDKTests(TestWebApplication testWebApplication, int count, string type, string expectedUrl)
        {
            testWebApplication.DoTest(
                (application) =>
            {
                application.ExecuteAnonymousRequest(string.Format(QueryStringOutboundAzureSdk, type, count));

                //// The above request would have trigged RDD module to monitor and create RDD telemetry
                //// Listen in the fake endpoint and see if the RDDTelemtry is captured
                var allItems  = sdkEventListener.ReceiveAllItemsDuringTimeOfType <TelemetryItem <RemoteDependencyData> >(SleepTimeForSdkToSendEvents);
                var httpItems = allItems.Where(i => i.Data.BaseData.DependencyKind == RemoteDependencyKind.Http).ToArray();
                int countItem = 0;

                foreach (var httpItem in httpItems)
                {
                    var accessTime = httpItem.Data.BaseData.Value;
                    Assert.IsTrue(accessTime >= 0, "Access time should be above zero for azure calls");

                    var url = httpItem.Data.BaseData.Name;
                    if (url.Contains(expectedUrl))
                    {
                        countItem++;
                    }
                    else
                    {
                        Assert.Fail("ExecuteAzureSDKTests.url not matching for " + url);
                    }
                }

                Assert.IsTrue(countItem >= count, "Azure " + type + " access captured " + countItem + " is less than " + count);
            });
        }
        /// <summary>
        /// Helper to execute Sync Http tests
        /// </summary>
        /// <param name="testWebApplication">The test application for which tests are to be executed</param>
        /// <param name="success">indicates if the tests should test success or failure case</param>
        /// <param name="count">number to RDD calls to be made by the test application.  </param>
        /// <param name="accessTimeMax">approximate maximum time taken by RDD Call.  </param>
        private void ExecuteSyncHttpPostTests(TestWebApplication testWebApplication, bool success, int count, TimeSpan accessTimeMax)
        {
            testWebApplication.DoTest(
                (application) =>
            {
                var queryString            = success == true ? QueryStringOutboundHttpPost : QueryStringOutboundHttpPostFailed;
                var resourceNameExpected   = success == true ? ResourceNameHttpToBing : ResourceNameHttpToFailedRequest;
                string commandNameExpected = string.Empty;
                application.ExecuteAnonymousRequest(queryString + count);

                //// The above request would have trigged RDD module to monitor and create RDD telemetry
                //// Listen in the fake endpoint and see if the RDDTelemtry is captured
                var allItems  = sdkEventListener.ReceiveAllItemsDuringTimeOfType <TelemetryItem <RemoteDependencyData> >(SleepTimeForSdkToSendEvents);
                var httpItems = allItems.Where(i => i.Data.BaseData.DependencyKind == RemoteDependencyKind.Http).ToArray();

                // Validate the RDD Telemetry properties
                Assert.AreEqual(
                    count,
                    httpItems.Length,
                    "Total Count of Remote Dependency items for HTTP collected is wrong.");
                foreach (var httpItem in httpItems)
                {
                    this.ValidateRddTelemetryValues(httpItem, resourceNameExpected, commandNameExpected, 1, accessTimeMax, success, false);
                }
            });
        }
        /// <summary>
        /// Helper to execute Sync Http tests
        /// </summary>
        /// <param name="testWebApplication">The test application for which tests are to be executed</param>
        /// <param name="success">indicates if the tests should test success or failure case</param>
        /// <param name="expectedCount">number of expected RDD calls to be made by the test application </param>
        /// <param name="count">number to RDD calls to be made by the test application </param>
        /// <param name="accessTimeMax">approximate maximum time taken by RDD Call.  </param>
        private void ExecuteSyncSqlTests(TestWebApplication testWebApplication, bool success, int expectedCount, int count, TimeSpan accessTimeMax)
        {
            testWebApplication.DoTest(
                (application) =>
            {
                application.ExecuteAnonymousRequest(QueryStringOutboundSql + count);

                //// The above request would have trigged RDD module to monitor and create RDD telemetry
                //// Listen in the fake endpoint and see if the RDDTelemtry is captured

                var allItems = sdkEventListener.ReceiveAllItemsDuringTimeOfType <TelemetryItem <RemoteDependencyData> >(SleepTimeForSdkToSendEvents);
                var sqlItems = allItems.Where(i => i.Data.BaseData.DependencyKind == RemoteDependencyKind.SQL).ToArray();


                Assert.AreEqual(
                    expectedCount,
                    sqlItems.Length,
                    "Total Count of Remote Dependency items for SQL collected is wrong.");

                foreach (var sqlItem in sqlItems)
                {
                    string spName = "GetTopTenMessages";
                    this.ValidateRddTelemetryValues(sqlItem, ResourceNameSQLToDevApm + " | " + spName, spName, expectedCount, accessTimeMax, true, false);
                }
            });
        }
        /// <summary>
        /// Initializes static members of the <see cref="RddTests"/> class.
        /// </summary>
        static RddTests()
        {
            aspx451TestWebApplication = new TestWebApplication
            {
                AppName       = "Aspx451",
                Port          = Aspx451Port,
                IsRedFieldApp = false
            };

            aspx451TestWebApplicationWin32 = new TestWebApplication
            {
                AppName       = "Aspx451Win32",
                Port          = Aspx451PortWin32,
                IsRedFieldApp = false
            };
        }
Exemplo n.º 11
0
        /// <summary>
        /// Helper to execute Async http test which uses async,await pattern (.NET 4.5 or higher only)
        /// </summary>
        /// <param name="testWebApplication">The test application for which tests are to be executed</param>
        /// <param name="success">indicates if the tests should test success or failure case</param>
        private void ExecuteAsyncAwaitTests(TestWebApplication testWebApplication, bool success)
        {
            var resourceNameExpected = success ? ResourceNameHttpToBing : ResourceNameHttpToFailedRequest;

            testWebApplication.DoTest(
                application =>
            {
                application.ExecuteAnonymousRequest(success ? QueryStringOutboundHttpAsyncAwait1 : QueryStringOutboundHttpAsyncAwait1Failed);

                //// The above request would have trigged RDD module to monitor and create RDD telemetry
                //// Listen in the fake endpoint and see if the RDDTelemtry is captured

                var allItems  = DeploymentAndValidationTools.SdkEventListener.ReceiveAllItemsDuringTimeOfType <TelemetryItem <RemoteDependencyData> >(DeploymentAndValidationTools.SleepTimeForSdkToSendEvents);
                var httpItems = allItems.Where(i => i.data.baseData.type == "Http").ToArray();

                // Validate the RDD Telemetry properties
                Assert.AreEqual(
                    1,
                    httpItems.Length,
                    "Total Count of Remote Dependency items for HTTP collected is wrong.");
                this.Validate(httpItems[0], resourceNameExpected, AccessTimeMaxHttpInitial, success, "GET");
            });
        }
 /// <summary>
 /// Helper to execute Sync Http tests
 /// </summary>
 /// <param name="testWebApplication">The test application for which tests are to be executed</param>
 /// <param name="success">indicates if the tests should test success or failure case</param>
 /// <param name="count">number to RDD calls to be made by the test application </param>
 /// <param name="accessTimeMax">approximate maximum time taken by RDD Call.  </param>
 private void ExecuteSyncSqlTests(TestWebApplication testWebApplication, bool success, int count, TimeSpan accessTimeMax)
 {
     this.ExecuteSyncSqlTests(testWebApplication, success, count, count, accessTimeMax);
 }