示例#1
0
 /// <exception cref="System.Exception"/>
 protected internal virtual void _testAuthentication(Authenticator authenticator,
                                                     bool doPost)
 {
     Start();
     try
     {
         Uri url = new Uri(GetBaseURL());
         AuthenticatedURL.Token token = new AuthenticatedURL.Token();
         NUnit.Framework.Assert.IsFalse(token.IsSet());
         AuthenticatorTestCase.TestConnectionConfigurator connConf = new AuthenticatorTestCase.TestConnectionConfigurator
                                                                         ();
         AuthenticatedURL  aUrl = new AuthenticatedURL(authenticator, connConf);
         HttpURLConnection conn = aUrl.OpenConnection(url, token);
         Assert.True(connConf.invoked);
         string tokenStr = token.ToString();
         if (doPost)
         {
             conn.SetRequestMethod("POST");
             conn.SetDoOutput(true);
         }
         conn.Connect();
         if (doPost)
         {
             TextWriter writer = new OutputStreamWriter(conn.GetOutputStream());
             writer.Write(Post);
             writer.Close();
         }
         Assert.Equal(HttpURLConnection.HttpOk, conn.GetResponseCode());
         if (doPost)
         {
             BufferedReader reader = new BufferedReader(new InputStreamReader(conn.GetInputStream
                                                                                  ()));
             string echo = reader.ReadLine();
             Assert.Equal(Post, echo);
             NUnit.Framework.Assert.IsNull(reader.ReadLine());
         }
         aUrl = new AuthenticatedURL();
         conn = aUrl.OpenConnection(url, token);
         conn.Connect();
         Assert.Equal(HttpURLConnection.HttpOk, conn.GetResponseCode());
         Assert.Equal(tokenStr, token.ToString());
     }
     finally
     {
         Stop();
     }
 }
示例#2
0
        public virtual void TestConnectionConfigurator()
        {
            HttpURLConnection conn = Org.Mockito.Mockito.Mock <HttpURLConnection>();

            Org.Mockito.Mockito.When(conn.GetResponseCode()).ThenReturn(HttpURLConnection.HttpUnauthorized
                                                                        );
            ConnectionConfigurator connConf = Org.Mockito.Mockito.Mock <ConnectionConfigurator
                                                                        >();

            Org.Mockito.Mockito.When(connConf.Configure(Org.Mockito.Mockito.Any <HttpURLConnection
                                                                                 >())).ThenReturn(conn);
            Authenticator    authenticator = Org.Mockito.Mockito.Mock <Authenticator>();
            AuthenticatedURL aURL          = new AuthenticatedURL(authenticator, connConf);

            aURL.OpenConnection(new Uri("http://foo"), new AuthenticatedURL.Token());
            Org.Mockito.Mockito.Verify(connConf).Configure(Org.Mockito.Mockito.Any <HttpURLConnection
                                                                                    >());
        }