コード例 #1
0
 private void InitialiseSingleConnection(ITest test)
 {
     if (test is TestFixture)
     {
         SingleConnectionAuthInfo = SingleConnectionAuthSpec == null
             ? AuthenticationInfoProvider.Current.DefaultAuthInfo
             : AuthenticationInfoProvider.Current.Manager.GetAuthenticationInfo(SingleConnectionAuthSpec);
         var credentials = SingleConnectionAuthInfo.Users.ContainsKey("mainUser")
             ? SingleConnectionAuthInfo.Users["mainUser"]
             : SingleConnectionAuthInfo.Users.First().Value;
         SharedSession = GetClient(test.Id).CreateSession(PrivateAuthentication.WithCredentials(credentials.Company.Name, credentials.Login, credentials.Password));
         SharedSession.Authenticate();
         var connection = new AuthApiConnection();
         if (!((test.Properties.Get(TestCaseExAttribute.SuppressAuthenticationParameterName) as bool?).GetValueOrDefault(false)))
         {
             connection.Authenticate(SharedSession.Authentication().Session);
         }
         else
         {
             connection.SuppressAuthentication = true;
         }
         test.Properties.Add(AuthApiConnectionParameterName, connection);
     }
     else if (test is TestMethod)
     {
         ITest parentFixture = test.Parent;
         while (!(parentFixture is TestFixture))
         {
             parentFixture = parentFixture.Parent;
         }
         test.Properties.Add(AuthApiConnectionParameterName, parentFixture.Properties.Get(AuthApiConnectionParameterName));
     }
 }
コード例 #2
0
        private AuthApiConnection PrepareConnection(ITest test, MultiItemAuthenticationInfo data)
        {
            var credentials = data.Users.ContainsKey("mainUser") ? data.Users["mainUser"] : data.Users.First().Value;
            var connection  = new AuthApiConnection();

            if (!((test.Properties.Get(TestCaseExAttribute.SuppressAuthenticationParameterName) as bool?).GetValueOrDefault(false)))
            {
                connection.Authenticate(credentials.Company.Name, credentials.Login, credentials.Password);
            }
            else
            {
                connection.SuppressAuthentication = true;
            }

            return(connection);
        }
コード例 #3
0
 private void DisposeAuthenticationInfo(ITest test)
 {
     if (test.Parent != null && test.Parent.Properties.ContainsKey(AuthenticationInfoPropertyName))
     {
         var valuesList = test.Parent.Properties[AuthenticationInfoPropertyName] as IList <object>;
         if (valuesList != null && valuesList.Count == 1 && valuesList.Single() as MultiItemAuthenticationInfo == authenticationInfo)
         {
             return;
         }
     }
     if (authenticationInfo != null && !string.IsNullOrEmpty(AuthenticationDataSpec))
     {
         authenticationInfo.Dispose();
         authenticationInfo = null;
     }
 }
コード例 #4
0
 private static Dictionary <string, string> GetCompanyIdUrlParameter(MultiItemAuthenticationInfo creds)
 {
     return(creds == null ? null : new Dictionary <string, string> {
         ["companyId"] = creds.Companies.Single().Value.Partition
     });
 }
コード例 #5
0
        public static void PerformJsonValidationTest <T>(AuthApiConnection connection, string propertyName, ParameterType parameterType, InputType inputType, T request, MultiItemAuthenticationInfo creds, string endpoint = null)
        {
            var handler  = new DefaultManager(connection);
            var response = handler.Send(request,
                                        additionalSettings: new DefaultManager.AdditionalRequestSettings
            {
                Endpoint      = endpoint,
                UrlParameters = GetCompanyIdUrlParameter(creds)
            },        // creds != null ? GetCompanyIdUrlParameter(creds) : null,
                                        transformation: (obj) => ValidationTestData.ParamTypeToInputMap[parameterType][inputType](obj, propertyName));

            var expectedError           = TestContext.CurrentContext.Test.Properties.Get(ValidationTestData.ExpectedErrorCodePropertyName) as string;
            var expectedField           = TestContext.CurrentContext.Test.Properties.Get(ValidationTestData.ExpectedErrorFieldPropertyName) as string;
            var expectedRedirectContent = "/auth/login?errorCode=PAR_INV";

            if (string.IsNullOrEmpty(expectedError))
            {
                var expectedHttpCode = Convert.ToInt32(TestContext.CurrentContext.Test.Properties.Get(ValidationTestData.ExpectedHttpCodeSuccessPropertyName));
                PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(expectedHttpCode));
            }
            else
            {
                var expectedHttpCode = Convert.ToInt32(TestContext.CurrentContext.Test.Properties.Get(ValidationTestData.ExpectedHttpCodeFailPropertyName));
                //PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(expectedHttpCode).And.ContainsError(expectedError, expectedField));
                PrAssert.That(response, PrIs.WithHttpCode(expectedHttpCode));
                PrAssert.That(response.Result.ToString().Contains(expectedRedirectContent), PrIs.True);
                PrAssert.That(response.Errors, Has.Count.EqualTo(1));
            }
        }