public void IsUnsubscribed_true() { // Arrange var email = "*****@*****.**"; var apiResponse = @"{ 'recipient_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(apiResponse) }) .Verifiable(); var globalSuppressions = new GlobalSuppressions(mockClient.Object, ENDPOINT); // Act var result = globalSuppressions.IsUnsubscribedAsync(email, CancellationToken.None).Result; // Assert result.ShouldBeTrue(); }
public async Task IsUnsubscribedAsync_false() { // Arrange var email = "*****@*****.**"; var apiResponse = @"{ }" ; var mockHttp = new MockHttpMessageHandler(); mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri(ENDPOINT, email)).Respond("application/json", apiResponse); var client = Utils.GetFluentClient(mockHttp); var globalSuppressions = new GlobalSuppressions(client); // Act var result = await globalSuppressions.IsUnsubscribedAsync(email, null, CancellationToken.None).ConfigureAwait(false); // Assert mockHttp.VerifyNoOutstandingExpectation(); mockHttp.VerifyNoOutstandingRequest(); result.ShouldBeFalse(); }
public void IsUnsubscribed_false() { // Arrange var email = "*****@*****.**"; var apiResponse = @"{ }" ; 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 globalSuppressions = new GlobalSuppressions(mockClient.Object); // Act var result = globalSuppressions.IsUnsubscribedAsync(email, CancellationToken.None).Result; // Assert Assert.IsFalse(result); }
public void IsUnsubscribed_true() { // Arrange var email = "*****@*****.**"; var apiResponse = @"{ 'recipient_email': '*****@*****.**' }" ; var mockHttp = new MockHttpMessageHandler(); mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri(ENDPOINT, email)).Respond("application/json", apiResponse); var client = Utils.GetFluentClient(mockHttp); var globalSuppressions = new GlobalSuppressions(client); // Act var result = globalSuppressions.IsUnsubscribedAsync(email, CancellationToken.None).Result; // Assert mockHttp.VerifyNoOutstandingExpectation(); mockHttp.VerifyNoOutstandingRequest(); result.ShouldBeTrue(); }