Beispiel #1
0
        public void GetRecipients()
        {
            // Arrange
            var segmentId      = 1;
            var recordsPerPage = 25;
            var page           = 1;

            var apiResponse = @"{
				'recipients': [
					{
						'created_at': 1422313607,
						'email': '*****@*****.**',
						'first_name': null,
						'id': 'YUBh',
						'last_clicked': null,
						'last_emailed': null,
						'last_name': 'Jones',
						'last_opened': null,
						'updated_at': 1422313790,
						'custom_fields': [
							{
								'id': 23,
								'name': 'pet',
								'value': 'Indiana',
								'type': 'text'
							}
						]
					}
				]
			}"            ;

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

            mockClient
            .Setup(c => c.GetAsync($"{ENDPOINT}/{segmentId}/recipients?page_size={recordsPerPage}&page={page}", It.IsAny <CancellationToken>()))
            .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(apiResponse)
            })
            .Verifiable();

            var segments = new Segments(mockClient.Object, ENDPOINT);

            // Act
            var result = segments.GetRecipientsAsync(segmentId, recordsPerPage, page, CancellationToken.None).Result;

            // Assert
            result.ShouldNotBeNull();
            result.Length.ShouldBe(1);
            result[0].Email.ShouldBe("*****@*****.**");
        }
Beispiel #2
0
        public async Task GetRecipientsAsync()
        {
            // Arrange
            var segmentId      = 1;
            var recordsPerPage = 25;
            var page           = 1;

            var apiResponse = @"{
				""recipients"": [
					{
						""created_at"": 1422313607,
						""email"": ""*****@*****.**"",
						""first_name"": null,
						""id"": ""YUBh"",
						""last_clicked"": null,
						""last_emailed"": null,
						""last_name"": ""Jones"",
						""last_opened"": null,
						""updated_at"": 1422313790,
						""custom_fields"": [
							{
								""id"": 23,
								""name"": ""pet"",
								""value"": ""Indiana"",
								""type"": ""text""
							}
						]
					}
				]
			}"            ;

            var mockHttp = new MockHttpMessageHandler();

            mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri(ENDPOINT, $"{segmentId}/recipients?page_size={recordsPerPage}&page={page}")).Respond("application/json", apiResponse);

            var client   = Utils.GetFluentClient(mockHttp);
            var segments = new Segments(client);

            // Act
            var result = await segments.GetRecipientsAsync(segmentId, recordsPerPage, page, null, CancellationToken.None).ConfigureAwait(false);

            // Assert
            mockHttp.VerifyNoOutstandingExpectation();
            mockHttp.VerifyNoOutstandingRequest();
            result.ShouldNotBeNull();
            result.Length.ShouldBe(1);
            result[0].Email.ShouldBe("*****@*****.**");
        }
Beispiel #3
0
        public async Task GetRecipientsAsync()
        {
            // Arrange
            var segmentId      = 1;
            var recordsPerPage = 25;
            var page           = 1;

            var apiResponse = @"{
				'recipients': [
					{
						'created_at': 1422313607,
						'email': '*****@*****.**',
						'first_name': null,
						'id': 'YUBh',
						'last_clicked': null,
						'last_emailed': null,
						'last_name': 'Jones',
						'last_opened': null,
						'updated_at': 1422313790,
						'custom_fields': [
							{
								'id': 23,
								'name': 'pet',
								'value': 'Indiana',
								'type': 'text'
							}
						]
					}
				]
			}"            ;

            var mockHttp = new MockHttpMessageHandler();

            mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri(ENDPOINT, $"{segmentId}/recipients?page_size={recordsPerPage}&page={page}")).Respond("application/json", apiResponse);

            var client   = Utils.GetFluentClient(mockHttp);
            var segments = new Segments(client);

            // Act
            var result = await segments.GetRecipientsAsync(segmentId, recordsPerPage, page, null, CancellationToken.None).ConfigureAwait(false);

            // Assert
            mockHttp.VerifyNoOutstandingExpectation();
            mockHttp.VerifyNoOutstandingRequest();
            result.ShouldNotBeNull();
            result.Length.ShouldBe(1);
            result[0].Email.ShouldBe("*****@*****.**");
        }