コード例 #1
0
        public async Task Should_Allow_Multiple_Requests_With_Single_HttpClient()
        {
            var responseString = @"{
	    ""Name"": ""Shawn"",
	    ""Id"": 1
        }";
            var api            = new MandrillApi("");

            RespondWith(api, HttpStatusCode.OK, responseString);
            await api.Post <SampleObject>("", new SamplePayload());

            await api.Post <SampleObject>("", new SamplePayload());
        }
コード例 #2
0
    public async Task Should_Throw_TimeOut_Exception_When_Timing_Out()
    {
      httpClient.SimulateTimeout();

      var api = new MandrillApi("");
      Assert.Throws<TimeoutException>(async () => await api.Post<object>("", new SamplePayload()));
    }
コード例 #3
0
        public async Task Should_Throw_TimeOut_Exception_When_Timing_Out()
        {
            httpClient.SimulateTimeout();

            var api = new MandrillApi("");

            Assert.Throws <TimeoutException>(async() => await api.Post <object>("", new SamplePayload()));
        }
コード例 #4
0
ファイル: PostTests.cs プロジェクト: stuisme/Mandrill-dotnet
        public async Task Should_Throw_Mandrill_Exception_When_Serialization_Error()
        {
            string responseString = @"<html></html>";

            var api = new MandrillApi("");

            RespondWith(api, HttpStatusCode.OK, responseString);

            var ex      = Assert.Throws <MandrillException>(async() => await api.Post <object>("", new SamplePayload()));
            var content = await ex.HttpResponseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);

            Assert.AreEqual(responseString, content);
        }
コード例 #5
0
    public async Task Should_Serialize_Response_When_Json_Content_Is_Recieved()
    {
      string responseString = @"{
	      ""Name"": ""Shawn"",
	      ""Id"": 1
      }";
      var api = new MandrillApi("");
      RespondWith(api, HttpStatusCode.OK, responseString);

      SampleObject response = await api.Post<SampleObject>("", new SamplePayload());

      Assert.AreEqual("Shawn", response.Name);
      Assert.AreEqual(1, response.Id);
    }
コード例 #6
0
        public async Task Should_Serialize_Response_When_Json_Content_Is_Recieved()
        {
            string responseString = @"{
	      ""Name"": ""Shawn"",
	      ""Id"": 1
      }";
            var    api            = new MandrillApi("");

            RespondWith(api, HttpStatusCode.OK, responseString);

            SampleObject response = await api.Post <SampleObject>("", new SamplePayload());

            Assert.AreEqual("Shawn", response.Name);
            Assert.AreEqual(1, response.Id);
        }
コード例 #7
0
    public async Task Should_Throw_Mandrill_Exception_When_Server_Error()
    {
      string responseString = @"{
	      ""code"": ""501"",
	      ""message"": ""m1"",
	      ""name"": ""n1"",
	      ""status"": ""s1""
      }";

      var api = new MandrillApi("");
      RespondWith(api, HttpStatusCode.InternalServerError, responseString);

      var ex = Assert.Throws<MandrillException>(async () => await api.Post<object>("", new SamplePayload()));
      Assert.AreEqual(501, ex.Error.Code);
      Assert.AreEqual("m1", ex.Error.Message);
      Assert.AreEqual("n1", ex.Error.Name);
      Assert.AreEqual("s1", ex.Error.Status);
    }
コード例 #8
0
        public async Task Should_Throw_Mandrill_Exception_When_Server_Error()
        {
            string responseString = @"{
	      ""code"": ""501"",
	      ""message"": ""m1"",
	      ""name"": ""n1"",
	      ""status"": ""s1""
      }";

            httpClient.RespondWith(500, responseString);

            var api = new MandrillApi("");
            var ex  = Assert.Throws <MandrillException>(async() => await api.Post <object>("", new SamplePayload()));

            Assert.AreEqual(501, ex.Error.Code);
            Assert.AreEqual("m1", ex.Error.Message);
            Assert.AreEqual("n1", ex.Error.Name);
            Assert.AreEqual("s1", ex.Error.Status);
        }
コード例 #9
0
        public async Task Should_Throw_Mandrill_Exception_When_Server_Error()
        {
            var responseString = @"{
	      ""code"": ""501"",
	      ""message"": ""m1"",
	      ""name"": ""n1"",
	      ""status"": ""s1""
      }";

            var api = new MandrillApi("");

            RespondWith(api, HttpStatusCode.InternalServerError, responseString);

            var ex = await Assert.ThrowsAsync <MandrillException>(async() => await api.Post <object>("", new SamplePayload()));

            Assert.Equal(501, ex.Error.Code);
            Assert.Equal("m1", ex.Error.Message);
            Assert.Equal("n1", ex.Error.Name);
            Assert.Equal("s1", ex.Error.Status);
        }
コード例 #10
0
    public async Task Should_Throw_Mandrill_Exception_When_Serialization_Error()
    {
      string responseString = @"<html></html>";

      var api = new MandrillApi("");
      RespondWith(api, HttpStatusCode.OK, responseString);

      var ex = Assert.Throws<MandrillException>(async () => await api.Post<object>("", new SamplePayload()));
      var content = await ex.HttpResponseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);
      Assert.AreEqual(responseString, content);
    }