public void Test_Retries_Execute_And_Should_Fail() { var expectedCode = 403; try { var transport = new FakeJsonTransport(); transport.SetReturn(this.Fixture.GetBadLoginJson()); transport.SetReturn(this.Fixture.GetBadLoginJson()); transport.SetReturn(this.Fixture.GetBadLoginJson()); transport.SetReturn(this.Fixture.GetBadLoginJson()); var loginMan = new LoginManager("user", "password", transport); var retry = new HttpRetry(transport, loginMan, 3); var codeGetter = new FakeCodeGetter(expectedCode); var stream = new MemoryStream(); var result = retry.Invoke(this.Fixture.GetApiUrl(), stream, "", null); Assert.Fail("Expected ApiException"); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ApiException)); Assert.AreEqual(((ApiException)ex).HttpStatusCode, expectedCode); } }
public void Test_Retries_Execute_And_Should_Fail() { var expectedCode = -10001; try { var transport = new FakeJsonTransport(); transport.SetReturn(this.Fixture.GetBadLoginJson()); transport.SetReturn(this.Fixture.GetBadLoginJson()); transport.SetReturn(this.Fixture.GetBadLoginJson()); transport.SetReturn(this.Fixture.GetBadLoginJson()); var loginMan = new LoginManager("user", "password", transport); var retry = new RpcRetry(transport, loginMan, 3); var argMaker = new AutoTokenArgMaker("fooarg"); var codeGetter = new FakeCodeGetter(expectedCode); var result = retry.Invoke("method", argMaker, codeGetter); Assert.Fail("Expected ApiException"); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ApiException)); Assert.AreEqual(((ApiException)ex).AgileStatusCode, expectedCode); } }
public void Test_Retries_Execute_And_Can_Complete_Successfully() { var returnMe = new JsonNumber("0"); var transport = new FakeJsonTransport(); transport.SetReturn(this.Fixture.GetBadLoginJson()); transport.SetReturn(this.Fixture.GetBadLoginJson()); transport.SetReturn(this.Fixture.GetGoodLoginJson()); transport.SetReturn(returnMe); var loginMan = new LoginManager("user", "password", transport); var retry = new RpcRetry(transport, loginMan, 3); var argMaker = new AutoTokenArgMaker("fooarg"); var codeGetter = new NullCodeGetter(); var result = retry.Invoke("method", argMaker, codeGetter); Assert.AreEqual(result, returnMe); }
public void Test_Login_Tokens_Are_Reset_If_Expired() { var transport = new FakeJsonTransport(); transport.SetReturn(this.Fixture.GetGoodLoginJson("oldtoken")); transport.SetReturn(new JsonNumber("-10001")); transport.SetReturn(this.Fixture.GetGoodLoginJson("newtoken")); transport.SetReturn(new JsonNumber("0")); var loginMan = new LoginManager(this.Fixture.GetUser(), this.Fixture.GetPassword(), transport); var rpcRetry = new RpcRetry(transport, loginMan); var httpRetry = new HttpRetry(transport, loginMan); var client = new ApiClient(this.Fixture.GetApiUrl(), rpcRetry, httpRetry, loginMan); var result = client.Login(); var oldToken = result.Token; client.DeleteFile("/notrealatall.txt"); Assert.AreNotEqual(oldToken, this.Client.GetToken()); }
public void Test_Retries_Execute_And_Can_Complete_Successfully() { var returnMe = new WebHeaderCollection(); returnMe.Add("X-Agile-Status", "0"); var transport = new FakeJsonTransport(); transport.SetReturn(this.Fixture.GetBadLoginJson()); transport.SetReturn(this.Fixture.GetBadLoginJson()); transport.SetReturn(this.Fixture.GetGoodLoginJson()); transport.SetReturn(returnMe); var loginMan = new LoginManager("user", "password", transport); var retry = new HttpRetry(transport, loginMan, 3); var codeGetter = new NullCodeGetter(); var stream = new MemoryStream(new byte[] { 100 }); var result = retry.Invoke("http://", stream, "", new Dictionary <string, string>()); Assert.AreEqual(result, returnMe); }