Exemple #1
0
        public async Task GetAllAsync()
        {
            // Arrange
            var mockHttp = new MockHttpMessageHandler();

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

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

            // Act
            var result = await segments.GetAllAsync(null, CancellationToken.None).ConfigureAwait(false);

            // Assert
            mockHttp.VerifyNoOutstandingExpectation();
            mockHttp.VerifyNoOutstandingRequest();
            result.ShouldNotBeNull();
            result.Length.ShouldBe(1);
        }
        public void GetAll()
        {
            // Arrange
            var apiResponse = @"{
				'segments': [
					{
						'id': 1,
						'name': 'Last Name Miller',
						'list_id': 4,
						'conditions': [
							{
								'field': 'last_name',
								'value': 'Miller',
								'operator': 'eq',
								'and_or': ''
							}
						],
						'recipient_count': 1
					}
				]
			}"            ;

            var mockClient = new Mock <IClient>(MockBehavior.Strict);

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

            var segments = new Segments(mockClient.Object);

            // Act
            var result = segments.GetAllAsync(CancellationToken.None).Result;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Length);
            Assert.AreEqual("Last Name Miller", result[0].Name);
        }
Exemple #3
0
        public void GetAll()
        {
            // Arrange
            var mockRepository = new MockRepository(MockBehavior.Strict);
            var mockClient     = mockRepository.Create <IClient>();

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

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

            // Act
            var result = segments.GetAllAsync(CancellationToken.None).Result;

            // Assert
            result.ShouldNotBeNull();
            result.Length.ShouldBe(1);
        }