private void OpenIdConnectTestSuite(ServerType serverType, RuntimeFlavor donetFlavor, RuntimeArchitecture architecture, string applicationBaseUrl)
        {
            using (_logger.BeginScope("OpenIdConnectTestSuite"))
            {
                _logger.LogInformation("Variation Details : HostType = {hostType}, DonetFlavor = {flavor}, Architecture = {arch}, applicationBaseUrl = {appBase}",
                                       serverType, donetFlavor, architecture, applicationBaseUrl);

                _startParameters = new StartParameters
                {
                    ServerType          = serverType,
                    RuntimeFlavor       = donetFlavor,
                    RuntimeArchitecture = architecture,
                    EnvironmentName     = "OpenIdConnectTesting"
                };

                var stopwatch        = Stopwatch.StartNew();
                var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty);

                _logger.LogInformation("Pointing MusicStore DB to '{connString}'", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName));

                //Override the connection strings using environment based configuration
                Environment.SetEnvironmentVariable("SQLAZURECONNSTR_DefaultConnection", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName));

                _applicationBaseUrl = applicationBaseUrl;
                Process hostProcess    = null;
                bool    testSuccessful = false;

                try
                {
                    hostProcess = DeploymentUtility.StartApplication(_startParameters, _logger);
#if DNX451
                    if (serverType == ServerType.IISNativeModule || serverType == ServerType.IIS)
                    {
                        // Accomodate the vdir name.
                        _applicationBaseUrl += _startParameters.IISApplication.VirtualDirectoryName + "/";
                    }
#endif
                    _httpClientHandler = new HttpClientHandler();
                    _httpClient        = new HttpClient(_httpClientHandler)
                    {
                        BaseAddress = new Uri(_applicationBaseUrl)
                    };

                    HttpResponseMessage response = null;
                    string responseContent       = null;

                    //Request to base address and check if various parts of the body are rendered & measure the cold startup time.
                    Helpers.Retry(() =>
                    {
                        response        = _httpClient.GetAsync(string.Empty).Result;
                        responseContent = response.Content.ReadAsStringAsync().Result;
                        _logger.LogInformation("[Time]: Approximate time taken for application initialization : '{t}' seconds", stopwatch.Elapsed.TotalSeconds);
                    }, logger: _logger);

                    VerifyHomePage(response, responseContent);

                    // OpenIdConnect login.
                    LoginWithOpenIdConnect();

                    stopwatch.Stop();
                    _logger.LogInformation("[Time]: Total time taken for this test variation '{t}' seconds", stopwatch.Elapsed.TotalSeconds);
                    testSuccessful = true;
                }
                finally
                {
                    if (!testSuccessful)
                    {
                        _logger.LogError("Some tests failed. Proceeding with cleanup.");
                    }

                    DeploymentUtility.CleanUpApplication(_startParameters, hostProcess, musicStoreDbName, _logger);
                }
            }
        }
        private void SmokeTestSuite(ServerType serverType, RuntimeFlavor donetFlavor, RuntimeArchitecture architecture, string applicationBaseUrl)
        {
            using (_logger.BeginScope("SmokeTestSuite"))
            {
                _logger.LogInformation("Variation Details : HostType = {hostType}, DonetFlavor = {flavor}, Architecture = {arch}, applicationBaseUrl = {appBase}",
                                       serverType, donetFlavor, architecture, applicationBaseUrl);

                _startParameters = new StartParameters
                {
                    ServerType          = serverType,
                    RuntimeFlavor       = donetFlavor,
                    RuntimeArchitecture = architecture,
                    EnvironmentName     = "SocialTesting"
                };

                var stopwatch        = Stopwatch.StartNew();
                var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty);

                _logger.LogInformation("Pointing MusicStore DB to '{connString}'", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName));

                //Override the connection strings using environment based configuration
                Environment.SetEnvironmentVariable("SQLAZURECONNSTR_DefaultConnection", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName));

                _applicationBaseUrl = applicationBaseUrl;
                Process hostProcess    = null;
                bool    testSuccessful = false;

                try
                {
                    hostProcess = DeploymentUtility.StartApplication(_startParameters, _logger);
#if DNX451
                    if (serverType == ServerType.IISNativeModule || serverType == ServerType.IIS)
                    {
                        // Accomodate the vdir name.
                        _applicationBaseUrl += _startParameters.IISApplication.VirtualDirectoryName + "/";
                    }
#endif
                    _httpClientHandler = new HttpClientHandler();
                    _httpClient        = new HttpClient(_httpClientHandler)
                    {
                        BaseAddress = new Uri(_applicationBaseUrl)
                    };

                    HttpResponseMessage response = null;
                    string responseContent       = null;

                    //Request to base address and check if various parts of the body are rendered & measure the cold startup time.
                    Helpers.Retry(() =>
                    {
                        response        = _httpClient.GetAsync(string.Empty).Result;
                        responseContent = response.Content.ReadAsStringAsync().Result;
                        _logger.LogInformation("[Time]: Approximate time taken for application initialization : '{t}' seconds", stopwatch.Elapsed.TotalSeconds);
                    }, logger: _logger);

                    VerifyHomePage(response, responseContent);

                    //Verify the static file middleware can serve static content
                    VerifyStaticContentServed();

                    //Making a request to a protected resource should automatically redirect to login page
                    AccessStoreWithoutPermissions();

                    //Register a user - Negative scenario where the Password & ConfirmPassword do not match
                    RegisterUserWithNonMatchingPasswords();

                    //Register a valid user
                    var generatedEmail = RegisterValidUser();

                    SignInWithUser(generatedEmail, "Password~1");

                    //Register a user - Negative scenario : Trying to register a user name that's already registered.
                    RegisterExistingUser(generatedEmail);

                    //Logout from this user session - This should take back to the home page
                    SignOutUser(generatedEmail);

                    //Sign in scenarios: Invalid password - Expected an invalid user name password error.
                    SignInWithInvalidPassword(generatedEmail, "InvalidPassword~1");

                    //Sign in scenarios: Valid user name & password.
                    SignInWithUser(generatedEmail, "Password~1");

                    //Change password scenario
                    ChangePassword(generatedEmail);

                    //SignIn with old password and verify old password is not allowed and new password is allowed
                    SignOutUser(generatedEmail);
                    SignInWithInvalidPassword(generatedEmail, "Password~1");
                    SignInWithUser(generatedEmail, "Password~2");

                    //Making a request to a protected resource that this user does not have access to - should automatically redirect to login page again
                    AccessStoreWithoutPermissions(generatedEmail);

                    //Logout from this user session - This should take back to the home page
                    SignOutUser(generatedEmail);

                    //Login as an admin user
                    SignInWithUser("*****@*****.**", "YouShouldChangeThisPassword1!");

                    //Now navigating to the store manager should work fine as this user has the necessary permission to administer the store.
                    AccessStoreWithPermissions();

                    //Create an album
                    var albumName = CreateAlbum();
                    var albumId   = FetchAlbumIdFromName(albumName);

                    //Get details of the album
                    VerifyAlbumDetails(albumId, albumName);

                    //Verify status code pages acts on non-existing items.
                    VerifyStatusCodePages();

                    //Get the non-admin view of the album.
                    GetAlbumDetailsFromStore(albumId, albumName);

                    //Add an album to cart and checkout the same
                    AddAlbumToCart(albumId, albumName);
                    CheckOutCartItems();

                    //Delete the album from store
                    DeleteAlbum(albumId, albumName);

                    //Logout from this user session - This should take back to the home page
                    SignOutUser("Administrator");

                    //Google login
                    LoginWithGoogle();

                    //Facebook login
                    LoginWithFacebook();

                    //Twitter login
                    LoginWithTwitter();

                    //MicrosoftAccountLogin
                    LoginWithMicrosoftAccount();

                    stopwatch.Stop();
                    _logger.LogInformation("[Time]: Total time taken for this test variation '{t}' seconds", stopwatch.Elapsed.TotalSeconds);
                    testSuccessful = true;
                }
                finally
                {
                    if (!testSuccessful)
                    {
                        _logger.LogError("Some tests failed. Proceeding with cleanup.");
                    }

                    DeploymentUtility.CleanUpApplication(_startParameters, hostProcess, musicStoreDbName, _logger);
                }
            }
        }
        public void NtlmAuthenticationTest(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, string applicationBaseUrl)
        {
            using (_logger.BeginScope("NtlmAuthenticationTest"))
            {
                _logger.LogInformation("Variation Details : HostType = {hostType}, RuntimeFlavor = {flavor}, Architecture = {arch}, applicationBaseUrl = {appBase}",
                                       serverType, runtimeFlavor, architecture, applicationBaseUrl);

                _startParameters = new StartParameters
                {
                    ServerType          = serverType,
                    RuntimeFlavor       = runtimeFlavor,
                    RuntimeArchitecture = architecture,
                    EnvironmentName     = "NtlmAuthentication", //Will pick the Start class named 'StartupNtlmAuthentication'
                    ApplicationHostConfigTemplateContent = (serverType == ServerType.IISExpress) ? File.ReadAllText("NtlmAuthentation.config") : null,
                    SiteName = "HooliNtlmAuthentication"        //This is configured in the NtlmAuthentication.config
                };

                var stopwatch        = Stopwatch.StartNew();
                var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty);

                _logger.LogInformation("Pointing Hooli DB to '{connString}'", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName));

                //Override the connection strings using environment based configuration
                Environment.SetEnvironmentVariable("SQLAZURECONNSTR_DefaultConnection", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName));

                _applicationBaseUrl = applicationBaseUrl;
                Process hostProcess    = null;
                bool    testSuccessful = false;

                try
                {
                    hostProcess = DeploymentUtility.StartApplication(_startParameters, _logger);

                    _httpClientHandler = new HttpClientHandler()
                    {
                        UseDefaultCredentials = true
                    };
                    _httpClient = new HttpClient(_httpClientHandler)
                    {
                        BaseAddress = new Uri(applicationBaseUrl)
                    };

                    HttpResponseMessage response = null;
                    string responseContent       = null;

                    //Request to base address and check if various parts of the body are rendered & measure the cold startup time.
                    Helpers.Retry(() =>
                    {
                        response        = _httpClient.GetAsync(string.Empty).Result;
                        responseContent = response.Content.ReadAsStringAsync().Result;
                        _logger.LogInformation("[Time]: Approximate time taken for application initialization : '{t}' seconds", stopwatch.Elapsed.TotalSeconds);
                    }, logger: _logger);

                    VerifyHomePage(response, responseContent, true);

                    //Check if the user name appears in the page
                    Assert.Contains(
                        string.Format("{0}\\{1}", Environment.GetEnvironmentVariable("USERDOMAIN"), Environment.GetEnvironmentVariable("USERNAME")),
                        responseContent, StringComparison.OrdinalIgnoreCase);

                    //Should be able to access the store as the Startup adds necessary permissions for the current user
                    AccessStoreWithPermissions();

                    stopwatch.Stop();
                    _logger.LogInformation("[Time]: Total time taken for this test variation '{t}' seconds", stopwatch.Elapsed.TotalSeconds);
                    testSuccessful = true;
                }
                finally
                {
                    if (!testSuccessful)
                    {
                        _logger.LogError("Some tests failed. Proceeding with cleanup.");
                    }

                    DeploymentUtility.CleanUpApplication(_startParameters, hostProcess, musicStoreDbName, _logger);
                }
            }
        }
        private void Publish_And_Run_Tests(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, string applicationBaseUrl, bool noSource)
        {
            using (_logger.BeginScope("Publish_And_Run_Tests"))
            {
                _logger.LogInformation("Variation Details : HostType = {hostType}, RuntimeFlavor = {flavor}, Architecture = {arch}, applicationBaseUrl = {appBase}",
                                       serverType, runtimeFlavor, architecture, applicationBaseUrl);

                _startParameters = new StartParameters
                {
                    ServerType                    = serverType,
                    RuntimeFlavor                 = runtimeFlavor,
                    RuntimeArchitecture           = architecture,
                    PublishApplicationBeforeStart = true,
                    PublishWithNoSource           = noSource
                };

                var stopwatch        = Stopwatch.StartNew();
                var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty);

                _logger.LogInformation("Pointing MusicStore DB to '{connString}'", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName));

                //Override the connection strings using environment based configuration
                Environment.SetEnvironmentVariable("SQLAZURECONNSTR_DefaultConnection", string.Format(CONNECTION_STRING_FORMAT, musicStoreDbName));

                _applicationBaseUrl = applicationBaseUrl;
                Process hostProcess    = null;
                bool    testSuccessful = false;

                try
                {
                    hostProcess = DeploymentUtility.StartApplication(_startParameters, _logger);

                    _httpClientHandler = new HttpClientHandler()
                    {
                        UseDefaultCredentials = true
                    };
                    _httpClient = new HttpClient(_httpClientHandler)
                    {
                        BaseAddress = new Uri(applicationBaseUrl)
                    };

                    HttpResponseMessage response = null;
                    string responseContent       = null;

                    //Request to base address and check if various parts of the body are rendered & measure the cold startup time.
                    //Add retry logic since tests are flaky on mono due to connection issues
                    Helpers.Retry(() =>
                    {
                        response        = _httpClient.GetAsync(string.Empty).Result;
                        responseContent = response.Content.ReadAsStringAsync().Result;
                        _logger.LogInformation("[Time]: Approximate time taken for application initialization : '{t}' seconds", stopwatch.Elapsed.TotalSeconds);
                    }, logger: _logger);

                    VerifyHomePage(response, responseContent, true);

                    //Static files are served?
                    VerifyStaticContentServed();

                    if (serverType != ServerType.IISExpress)
                    {
                        if (Directory.GetFiles(_startParameters.ApplicationPath, "*.cmd", SearchOption.TopDirectoryOnly).Length > 0)
                        {
                            throw new Exception("publishExclude parameter values are not honored.");
                        }
                    }

                    stopwatch.Stop();
                    _logger.LogInformation("[Time]: Total time taken for this test variation '{t}' seconds.", stopwatch.Elapsed.TotalSeconds);
                    testSuccessful = true;
                }
                finally
                {
                    if (!testSuccessful)
                    {
                        _logger.LogError("Some tests failed. Proceeding with cleanup.");
                    }

                    DeploymentUtility.CleanUpApplication(_startParameters, hostProcess, musicStoreDbName, _logger);
                }
            }
        }
Beispiel #5
0
        //WindowsIdentity not available on CoreCLR
        //[InlineData(ServerType.Helios, KreFlavor.CoreClr, KreArchitecture.x86, "http://localhost:5001/", false)]
        //[InlineData(ServerType.WebListener, KreFlavor.CoreClr, KreArchitecture.x86, "http://localhost:5002/", false)]
        public void NtlmAuthenticationTest(ServerType serverType, KreFlavor kreFlavor, KreArchitecture architecture, string applicationBaseUrl, bool RunTestOnMono = false)
        {
            Console.WriteLine("Variation Details : HostType = {0}, KreFlavor = {1}, Architecture = {2}, applicationBaseUrl = {3}", serverType, kreFlavor, architecture, applicationBaseUrl);

            if (Helpers.SkipTestOnCurrentConfiguration(RunTestOnMono, architecture))
            {
                Assert.True(true);
                return;
            }

            var startParameters = new StartParameters
            {
                ServerType      = serverType,
                KreFlavor       = kreFlavor,
                KreArchitecture = architecture,
                EnvironmentName = "NtlmAuthentication",   //Will pick the Start class named 'StartupNtlmAuthentication'
                ApplicationHostConfigTemplateContent = (serverType == ServerType.Helios) ? File.ReadAllText("NtlmAuthentation.config") : null,
                SiteName = "MusicStoreNtlmAuthentication" //This is configured in the NtlmAuthentication.config
            };

            var testStartTime    = DateTime.Now;
            var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty);

            Console.WriteLine("Pointing MusicStore DB to '{0}'", string.Format(Connection_string_Format, musicStoreDbName));

            //Override the connection strings using environment based configuration
            Environment.SetEnvironmentVariable("SQLAZURECONNSTR_DefaultConnection", string.Format(Connection_string_Format, musicStoreDbName));

            ApplicationBaseUrl = applicationBaseUrl;
            Process hostProcess    = null;
            bool    testSuccessful = false;

            try
            {
                hostProcess = DeploymentUtility.StartApplication(startParameters, musicStoreDbName);

                httpClientHandler = new HttpClientHandler()
                {
                    UseDefaultCredentials = true
                };
                httpClient = new HttpClient(httpClientHandler)
                {
                    BaseAddress = new Uri(applicationBaseUrl)
                };

                //Request to base address and check if various parts of the body are rendered & measure the cold startup time.
                var response                   = httpClient.GetAsync(string.Empty).Result;
                var responseContent            = response.Content.ReadAsStringAsync().Result;
                var initializationCompleteTime = DateTime.Now;
                Console.WriteLine("[Time]: Approximate time taken for application initialization : '{0}' seconds", (initializationCompleteTime - testStartTime).TotalSeconds);
                VerifyHomePage(response, responseContent, true);

                //Check if the user name appears in the page
                Assert.Contains(string.Format("{0}\\{1}", Environment.UserDomainName, Environment.UserName), responseContent, StringComparison.OrdinalIgnoreCase);

                if (serverType != ServerType.Helios)
                {
                    //https://github.com/aspnet/Helios/issues/53
                    //Should be able to access the store as the Startup adds necessary permissions for the current user
                    AccessStoreWithPermissions();
                }

                var testCompletionTime = DateTime.Now;
                Console.WriteLine("[Time]: All tests completed in '{0}' seconds", (testCompletionTime - initializationCompleteTime).TotalSeconds);
                Console.WriteLine("[Time]: Total time taken for this test variation '{0}' seconds", (testCompletionTime - testStartTime).TotalSeconds);
                testSuccessful = true;
            }
            finally
            {
                if (!testSuccessful)
                {
                    Console.WriteLine("Some tests failed. Proceeding with cleanup.");
                }

                DeploymentUtility.CleanUpApplication(startParameters, hostProcess, musicStoreDbName);
            }
        }
Beispiel #6
0
        public void SmokeTestSuite(ServerType serverType, KreFlavor kreFlavor, KreArchitecture architecture, string applicationBaseUrl, bool RunTestOnMono = false)
        {
            Console.WriteLine("Variation Details : HostType = {0}, KreFlavor = {1}, Architecture = {2}, applicationBaseUrl = {3}", serverType, kreFlavor, architecture, applicationBaseUrl);

            if (Helpers.SkipTestOnCurrentConfiguration(RunTestOnMono, architecture))
            {
                Assert.True(true);
                return;
            }

            var startParameters = new StartParameters
            {
                ServerType      = serverType,
                KreFlavor       = kreFlavor,
                KreArchitecture = architecture
            };

            var testStartTime    = DateTime.Now;
            var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty);

            Console.WriteLine("Pointing MusicStore DB to '{0}'", string.Format(Connection_string_Format, musicStoreDbName));

            //Override the connection strings using environment based configuration
            Environment.SetEnvironmentVariable("SQLAZURECONNSTR_DefaultConnection", string.Format(Connection_string_Format, musicStoreDbName));

            ApplicationBaseUrl = applicationBaseUrl;
            Process hostProcess    = null;
            bool    testSuccessful = false;

            try
            {
                hostProcess = DeploymentUtility.StartApplication(startParameters, musicStoreDbName);

                httpClientHandler = new HttpClientHandler();
                httpClient        = new HttpClient(httpClientHandler)
                {
                    BaseAddress = new Uri(applicationBaseUrl)
                };

                //Request to base address and check if various parts of the body are rendered & measure the cold startup time.
                var response                   = httpClient.GetAsync(string.Empty).Result;
                var responseContent            = response.Content.ReadAsStringAsync().Result;
                var initializationCompleteTime = DateTime.Now;
                Console.WriteLine("[Time]: Approximate time taken for application initialization : '{0}' seconds", (initializationCompleteTime - testStartTime).TotalSeconds);
                VerifyHomePage(response, responseContent);

                //Verify the static file middleware can serve static content
                VerifyStaticContentServed();

                //Making a request to a protected resource should automatically redirect to login page
                AccessStoreWithoutPermissions();

                //Register a user - Negative scenario where the Password & ConfirmPassword do not match
                RegisterUserWithNonMatchingPasswords();

                //Register a valid user
                var generatedEmail = RegisterValidUser();

                //Register a user - Negative scenario : Trying to register a user name that's already registered.
                RegisterExistingUser(generatedEmail);

                //Logout from this user session - This should take back to the home page
                SignOutUser(generatedEmail);

                //Sign in scenarios: Invalid password - Expected an invalid user name password error.
                SignInWithInvalidPassword(generatedEmail, "InvalidPassword~1");

                //Sign in scenarios: Valid user name & password.
                SignInWithUser(generatedEmail, "Password~1");

                //Change password scenario
                ChangePassword(generatedEmail);

                //SignIn with old password and verify old password is not allowed and new password is allowed
                SignOutUser(generatedEmail);
                SignInWithInvalidPassword(generatedEmail, "Password~1");
                SignInWithUser(generatedEmail, "Password~2");

                //Making a request to a protected resource that this user does not have access to - should automatically redirect to login page again
                AccessStoreWithoutPermissions(generatedEmail);

                //Logout from this user session - This should take back to the home page
                SignOutUser(generatedEmail);

                //Login as an admin user
                SignInWithUser("*****@*****.**", "YouShouldChangeThisPassword1!");

                //Now navigating to the store manager should work fine as this user has the necessary permission to administer the store.
                AccessStoreWithPermissions();

                //Create an album
                var albumName = CreateAlbum();
                var albumId   = FetchAlbumIdFromName(albumName);

                //Get details of the album
                VerifyAlbumDetails(albumId, albumName);

                //Add an album to cart and checkout the same
                AddAlbumToCart(albumId, albumName);
                CheckOutCartItems();

                //Delete the album from store
                DeleteAlbum(albumId, albumName);

                //Logout from this user session - This should take back to the home page
                SignOutUser("Administrator");

                var testCompletionTime = DateTime.Now;
                Console.WriteLine("[Time]: All tests completed in '{0}' seconds", (testCompletionTime - initializationCompleteTime).TotalSeconds);
                Console.WriteLine("[Time]: Total time taken for this test variation '{0}' seconds", (testCompletionTime - testStartTime).TotalSeconds);
                testSuccessful = true;
            }
            finally
            {
                if (!testSuccessful)
                {
                    Console.WriteLine("Some tests failed. Proceeding with cleanup.");
                }

                DeploymentUtility.CleanUpApplication(startParameters, hostProcess, musicStoreDbName);
            }
        }
        public void PublishAndRunTests(ServerType serverType, KreFlavor kreFlavor, KreArchitecture architecture, string applicationBaseUrl, bool RunTestOnMono = false)
        {
            Console.WriteLine("Variation Details : HostType = {0}, KreFlavor = {1}, Architecture = {2}, applicationBaseUrl = {3}", serverType, kreFlavor, architecture, applicationBaseUrl);

            if (Helpers.SkipTestOnCurrentConfiguration(RunTestOnMono, architecture))
            {
                Assert.True(true);
                return;
            }

            var startParameters = new StartParameters
            {
                ServerType                 = serverType,
                KreFlavor                  = kreFlavor,
                KreArchitecture            = architecture,
                PackApplicationBeforeStart = true
            };

            var testStartTime    = DateTime.Now;
            var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty);

            Console.WriteLine("Pointing MusicStore DB to '{0}'", string.Format(Connection_string_Format, musicStoreDbName));

            //Override the connection strings using environment based configuration
            Environment.SetEnvironmentVariable("SQLAZURECONNSTR_DefaultConnection", string.Format(Connection_string_Format, musicStoreDbName));

            ApplicationBaseUrl = applicationBaseUrl;
            Process hostProcess    = null;
            bool    testSuccessful = false;

            try
            {
                hostProcess = DeploymentUtility.StartApplication(startParameters, musicStoreDbName);

                httpClientHandler = new HttpClientHandler()
                {
                    UseDefaultCredentials = true
                };
                httpClient = new HttpClient(httpClientHandler)
                {
                    BaseAddress = new Uri(applicationBaseUrl)
                };

                HttpResponseMessage response      = null;
                string responseContent            = null;
                var    initializationCompleteTime = DateTime.MinValue;

                //Request to base address and check if various parts of the body are rendered & measure the cold startup time.
                //Add retry logic since tests are flaky on mono due to connection issues
                for (int retryCount = 0; retryCount < 3; retryCount++)
                {
                    try
                    {
                        response                   = httpClient.GetAsync(string.Empty).Result;
                        responseContent            = response.Content.ReadAsStringAsync().Result;
                        initializationCompleteTime = DateTime.Now;
                        Console.WriteLine("[Time]: Approximate time taken for application initialization : '{0}' seconds", (initializationCompleteTime - testStartTime).TotalSeconds);
                        break; //Went through successfully
                    }
                    catch (AggregateException exception)
                    {
                        // Both type exceptions thrown by Mono which are resolved by retry logic
                        if (exception.InnerException is HttpRequestException || exception.InnerException is WebException)
                        {
                            Console.WriteLine("Failed to complete the request with error: {0}", exception.ToString());
                            Console.WriteLine("Retrying request..");
                            Thread.Sleep(1 * 1000); //Wait for a second before retry
                        }
                    }
                }

                VerifyHomePage(response, responseContent, true);

                //Static files are served?
                VerifyStaticContentServed();

                if (serverType != ServerType.Helios)
                {
                    if (Directory.GetFiles(startParameters.ApplicationPath, "*.cmd", SearchOption.TopDirectoryOnly).Length > 0)
                    {
                        throw new Exception("packExclude parameter values are not honored");
                    }
                }

                var testCompletionTime = DateTime.Now;
                Console.WriteLine("[Time]: All tests completed in '{0}' seconds", (testCompletionTime - initializationCompleteTime).TotalSeconds);
                Console.WriteLine("[Time]: Total time taken for this test variation '{0}' seconds", (testCompletionTime - testStartTime).TotalSeconds);
                testSuccessful = true;
            }
            finally
            {
                if (!testSuccessful)
                {
                    Console.WriteLine("Some tests failed. Proceeding with cleanup.");
                }

                DeploymentUtility.CleanUpApplication(startParameters, hostProcess, musicStoreDbName);
            }
        }
Beispiel #8
0
        //[InlineData(ServerType.WebListener, KreFlavor.DesktopClr, KreArchitecture.x86, "http://localhost:5002/", false)]
        //[InlineData(ServerType.Kestrel, KreFlavor.DesktopClr, KreArchitecture.x86, "http://localhost:5004/", true)]
        public void PublishAndRunTests(ServerType serverType, KreFlavor kreFlavor, KreArchitecture architecture, string applicationBaseUrl, bool RunTestOnMono = false)
        {
            Console.WriteLine("Variation Details : HostType = {0}, KreFlavor = {1}, Architecture = {2}, applicationBaseUrl = {3}", serverType, kreFlavor, architecture, applicationBaseUrl);

            if (Helpers.SkipTestOnCurrentConfiguration(RunTestOnMono, architecture))
            {
                Assert.True(true);
                return;
            }

            var startParameters = new StartParameters
            {
                ServerType                 = serverType,
                KreFlavor                  = kreFlavor,
                KreArchitecture            = architecture,
                PackApplicationBeforeStart = true
            };

            var testStartTime    = DateTime.Now;
            var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty);

            Console.WriteLine("Pointing MusicStore DB to '{0}'", string.Format(Connection_string_Format, musicStoreDbName));

            //Override the connection strings using environment based configuration
            Environment.SetEnvironmentVariable("SQLAZURECONNSTR_DefaultConnection", string.Format(Connection_string_Format, musicStoreDbName));

            ApplicationBaseUrl = applicationBaseUrl;
            Process hostProcess    = null;
            bool    testSuccessful = false;

            try
            {
                hostProcess = DeploymentUtility.StartApplication(startParameters, musicStoreDbName);

                httpClientHandler = new HttpClientHandler()
                {
                    UseDefaultCredentials = true
                };
                httpClient = new HttpClient(httpClientHandler)
                {
                    BaseAddress = new Uri(applicationBaseUrl)
                };

                //Request to base address and check if various parts of the body are rendered & measure the cold startup time.
                var response                   = httpClient.GetAsync(string.Empty).Result;
                var responseContent            = response.Content.ReadAsStringAsync().Result;
                var initializationCompleteTime = DateTime.Now;
                Console.WriteLine("[Time]: Approximate time taken for application initialization : '{0}' seconds", (initializationCompleteTime - testStartTime).TotalSeconds);
                VerifyHomePage(response, responseContent, true);

                //Static files are served?
                VerifyStaticContentServed();

                var testCompletionTime = DateTime.Now;
                Console.WriteLine("[Time]: All tests completed in '{0}' seconds", (testCompletionTime - initializationCompleteTime).TotalSeconds);
                Console.WriteLine("[Time]: Total time taken for this test variation '{0}' seconds", (testCompletionTime - testStartTime).TotalSeconds);
                testSuccessful = true;
            }
            finally
            {
                if (!testSuccessful)
                {
                    Console.WriteLine("Some tests failed. Proceeding with cleanup.");
                }

                DeploymentUtility.CleanUpApplication(startParameters, hostProcess, musicStoreDbName);
            }
        }