Implements the methods to Authenticate and Singout a particular user
Inheritance: ApiController
        public void Return_BadRequest_SignOut_When_Callback_Is_NUll()
        {
            // Prepare
            HttpResponseMessage httpResponseMessage = null;
            string callbackUrl = null;
            var authenticationController = new AuthenticationController();
            authenticationController.Request = new HttpRequestMessage(HttpMethod.Get, string.Empty);

            // Perform

            httpResponseMessage = authenticationController.SignOut(callbackUrl);

            // Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, httpResponseMessage.StatusCode, "Stataus is not as expected(Bad Request)");
        }
        public void Allow_SignOut()
        {
            // Prepare
            HttpResponseMessage httpResponseMessage = null;
            string issuer = "https://unittest.accesscontrol.windows.net/v2/wsfederation";
            string wtrealm = "urn:dataonboardingapi:unittest";
            string callbackUrl = "http://unittest:123/landingpage";
            string apiUrl = "http://unittest-api-dataonboarding.cloudapp.net";

            using (ShimsContext.Create())
            {
                ShimDiagnosticsProvider.AllInstances.WriteInformationTraceTraceEventIdString = (diagnosticsProvider, traceEventId, message) => { };
                ShimFederatedAuthentication.WSFederationAuthenticationModuleGet = () =>
                {
                    var wsFederationAuthenticationModule = new ShimWSFederationAuthenticationModule();
                    wsFederationAuthenticationModule.SignOutBoolean = (param) =>
                    {
                    };

                    return wsFederationAuthenticationModule;
                };

                ShimFederatedAuthentication.FederationConfigurationGet = () =>
                    {
                        var federationConfiguration = new ShimFederationConfiguration();
                        federationConfiguration.WsFederationConfigurationGet = () =>
                            {
                                var acsConfig = new ShimWsFederationConfiguration();
                                acsConfig.RealmGet = () =>
                                    {
                                        return wtrealm;
                                    };

                                acsConfig.IssuerGet = ()=>
                                    {
                                        return issuer; ;
                                    };

                                return acsConfig;
                            };

                        return federationConfiguration;
                    };

                var authenticationController = new AuthenticationController();

                authenticationController.Request = new HttpRequestMessage(HttpMethod.Get, apiUrl);

                // Perform
                httpResponseMessage = authenticationController.SignOut(callbackUrl);
            }

            // Assert
            Assert.AreEqual(HttpStatusCode.Moved, httpResponseMessage.StatusCode, "Stataus is not as expected(Moved)");
            string wReply = string.Format("{0}/SignOutCallback?callback={1}", apiUrl, callbackUrl);

            string expectedCallbackUrl = string.Format("{0}?wa=wsignout1.0&wreply={1}&wtrealm={2}", issuer, HttpUtility.UrlEncode(wReply), wtrealm);

            Assert.AreEqual(HttpUtility.UrlDecode(expectedCallbackUrl), HttpUtility.UrlDecode(httpResponseMessage.Headers.Location.ToString()));
        }
        public void Allow_SignOutCallBack()
        {
            // Prepare
            HttpResponseMessage httpResponseMessage = null;
            string callbackUrl = "http://unittest:123/landingpage";
            var authenticationController = new AuthenticationController();
            authenticationController.Request = new HttpRequestMessage(HttpMethod.Get, string.Empty);

            // Perform
            httpResponseMessage = authenticationController.SignOutCallback(callbackUrl);

            // Assert
            Assert.AreEqual(HttpStatusCode.Moved, httpResponseMessage.StatusCode, "Stataus is not as expected(Moved)");
            Assert.AreEqual(callbackUrl, HttpUtility.UrlDecode(httpResponseMessage.Headers.Location.ToString()));

            // Check FedAuth cookie
            bool cookieExists = false;
            string[] cookies = (string[]) httpResponseMessage.Headers.GetValues("set-cookie");
            foreach (string cookie in cookies)
            {
                if (cookie.Contains("FedAuth"))
                {
                    cookieExists = true;
                    string[] attributes = cookie.Split(';');
                    DateTime expiryDate = Convert.ToDateTime(attributes[1].Substring(attributes[1].LastIndexOf('=') + 1));
                    Assert.IsTrue(DateTime.Now > expiryDate, "FedAuth cookie is not set to expire");
                }
            }

            Assert.IsTrue(cookieExists, "FedAuth cookie doese not exist");
        }