Beispiel #1
0
        public void Get()
        {
            // Arrange
            var groupId     = 100;
            var apiResponse = @"{
				'id': 100,
				'name': 'Newsletters',
				'description': 'Our monthly newsletter.',
				'last_email_sent_at': null,
				'is_default': true,
				'unsubscribes': 400
			}"            ;

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

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

            var groups = new UnsubscribeGroups(mockClient.Object);

            // Act
            var result = groups.GetAsync(groupId, CancellationToken.None).Result;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(groupId, result.Id);
            Assert.AreEqual("Newsletters", result.Name);
        }
        public async Task GetAsync()
        {
            // Arrange
            var groupId = 100;

            var mockHttp = new MockHttpMessageHandler();

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

            var client = Utils.GetFluentClient(mockHttp);
            var groups = new UnsubscribeGroups(client);

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

            // Assert
            mockHttp.VerifyNoOutstandingExpectation();
            mockHttp.VerifyNoOutstandingRequest();
            result.ShouldNotBeNull();
        }
Beispiel #3
0
        public void Get()
        {
            // Arrange
            var groupId = 100;

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

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

            var groups = new UnsubscribeGroups(mockClient.Object, ENDPOINT);

            // Act
            var result = groups.GetAsync(groupId, CancellationToken.None).Result;

            // Assert
            result.ShouldNotBeNull();
        }