示例#1
0
        public void Get_by_email()
        {
            // Arrange
            var email = "*****@*****.**";

            var apiResponse = @"[
				{
					'created': 1443651125,
					'email': '*****@*****.**',
					'reason': '550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient\'s email address for typos or unnecessary spaces. Learn more at  https://support.google.com/mail/answer/6596 o186si2389584ioe.63 - gsmtp ',
					'status': '5.1.1'
				}
			]"            ;
            var mockClient  = new Mock <IClient>(MockBehavior.Strict);

            mockClient.Setup(c => c.GetAsync($"{ENDPOINT}/{email}", It.IsAny <CancellationToken>()))
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(apiResponse)
            });

            var bounces = new Bounces(mockClient.Object);

            // Act
            var result = bounces.GetAsync(email, CancellationToken.None).Result;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Length);
            Assert.AreEqual("*****@*****.**", result[0].EmailAddress);
            Assert.AreEqual("5.1.1", result[0].Status);
        }
        public void Get_by_email()
        {
            // Arrange
            var email = "*****@*****.**";

            var mockRepository = new MockRepository(MockBehavior.Strict);
            var mockClient     = mockRepository.Create <IClient>();

            mockClient
            .Setup(c => c.GetAsync($"{ENDPOINT}/{email}", It.IsAny <CancellationToken>()))
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MULTIPLE_BOUNCES_JSON)
            }).
            Verifiable();

            var bounces = new Bounces(mockClient.Object, ENDPOINT);

            // Act
            var result = bounces.GetAsync(email, CancellationToken.None).Result;

            // Assert
            result.ShouldNotBeNull();
            result.Length.ShouldBe(2);
        }
        public void Get_between_startdate_and_enddate()
        {
            // Arrange
            var start = new DateTime(2015, 6, 8, 0, 0, 0, DateTimeKind.Utc);
            var end   = new DateTime(2015, 9, 30, 23, 59, 59, DateTimeKind.Utc);

            var mockRepository = new MockRepository(MockBehavior.Strict);
            var mockClient     = mockRepository.Create <IClient>();

            mockClient
            .Setup(c => c.GetAsync($"{ENDPOINT}?start_time={start.ToUnixTime()}&end_time={end.ToUnixTime()}", It.IsAny <CancellationToken>()))
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(MULTIPLE_BOUNCES_JSON)
            })
            .Verifiable();

            var bounces = new Bounces(mockClient.Object, ENDPOINT);

            // Act
            var result = bounces.GetAsync(start, end, CancellationToken.None).Result;

            // Assert
            result.ShouldNotBeNull();
            result.Length.ShouldBe(2);
        }
示例#4
0
        public async Task GetAsync_by_email()
        {
            // Arrange
            var email = "*****@*****.**";

            var mockHttp = new MockHttpMessageHandler();

            mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri(ENDPOINT, email)).Respond("application/json", MULTIPLE_BOUNCES_JSON);

            var client  = Utils.GetFluentClient(mockHttp);
            var bounces = new Bounces(client);

            // Act
            var result = await bounces.GetAsync(email, null, CancellationToken.None).ConfigureAwait(false);

            // Assert
            mockHttp.VerifyNoOutstandingExpectation();
            mockHttp.VerifyNoOutstandingRequest();
            result.ShouldNotBeNull();
            result.Length.ShouldBe(2);
        }
示例#5
0
        public void Get_between_startdate_and_enddate()
        {
            // Arrange
            var start = new DateTime(2015, 6, 8, 0, 0, 0, DateTimeKind.Utc);
            var end   = new DateTime(2015, 9, 30, 23, 59, 59, DateTimeKind.Utc);

            var apiResponse = @"[
				{
					'created': 1443651125,
					'email': '*****@*****.**',
					'reason': '550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient\'s email address for typos or unnecessary spaces. Learn more at  https://support.google.com/mail/answer/6596 o186si2389584ioe.63 - gsmtp ',
					'status': '5.1.1'
				},
				{
					'created': 1433800303,
					'email': '*****@*****.**',
					'reason': '550 5.1.1 <*****@*****.**>: Recipient address rejected: User unknown in virtual alias table ',
					'status': '5.1.1'
				}
			]"            ;
            var mockClient  = new Mock <IClient>(MockBehavior.Strict);

            mockClient.Setup(c => c.GetAsync($"{ENDPOINT}?start_time={start.ToUnixTime()}&end_time={end.ToUnixTime()}", It.IsAny <CancellationToken>()))
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(apiResponse)
            });

            var bounces = new Bounces(mockClient.Object);

            // Act
            var result = bounces.GetAsync(start, end, CancellationToken.None).Result;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Length);
            Assert.AreEqual("*****@*****.**", result[0].EmailAddress);
            Assert.AreEqual("5.1.1", result[0].Status);
        }
示例#6
0
        public void Get_between_startdate_and_enddate()
        {
            // Arrange
            var start = new DateTime(2015, 6, 8, 0, 0, 0, DateTimeKind.Utc);
            var end   = new DateTime(2015, 9, 30, 23, 59, 59, DateTimeKind.Utc);

            var mockHttp = new MockHttpMessageHandler();

            mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri(ENDPOINT) + $"?start_time={start.ToUnixTime()}&end_time={end.ToUnixTime()}").Respond("application/json", MULTIPLE_BOUNCES_JSON);

            var client  = Utils.GetFluentClient(mockHttp);
            var bounces = new Bounces(client);

            // Act
            var result = bounces.GetAsync(start, end, CancellationToken.None).Result;

            // Assert
            mockHttp.VerifyNoOutstandingExpectation();
            mockHttp.VerifyNoOutstandingRequest();
            result.ShouldNotBeNull();
            result.Length.ShouldBe(2);
        }