public void ValidateLink() { // Arrange var linkId = 1L; var apiResponse = @"{ 'id': 1, 'valid': true, 'validation_results': { 'domain_cname': { 'valid': false, 'reason': 'Expected CNAME to match \'sendgrid.net.\' but found \'example.com.\'.' }, 'owner_cname': { 'valid': true, 'reason': null } } }" ; var mockRepository = new MockRepository(MockBehavior.Strict); var mockClient = mockRepository.Create <IClient>(); mockClient .Setup(c => c.PostAsync($"{ENDPOINT}/links/{linkId}/validate", It.IsAny <JObject>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(apiResponse) }) .Verifiable(); var whitelabel = new Whitelabel(mockClient.Object, ENDPOINT); // Act var result = whitelabel.ValidateLinkAsync(linkId).Result; // Assert result.ShouldNotBeNull(); result.LinkId.ShouldBe(1); result.IsValid.ShouldBe(true); result.ValidationResults.Domain.IsValid.ShouldBe(false); result.ValidationResults.Domain.Reason.ShouldBe("Expected CNAME to match \'sendgrid.net.\' but found \'example.com.\'."); result.ValidationResults.Owner.IsValid.ShouldBe(true); result.ValidationResults.Owner.Reason.ShouldBeNull(); }
public async Task ValidateLinkAsync() { // Arrange var linkId = 1L; var apiResponse = @"{ 'id': 1, 'valid': true, 'validation_results': { 'domain_cname': { 'valid': false, 'reason': 'Expected CNAME to match \'sendgrid.net.\' but found \'example.com.\'.' }, 'owner_cname': { 'valid': true, 'reason': null } } }" ; var mockHttp = new MockHttpMessageHandler(); mockHttp.Expect(HttpMethod.Post, Utils.GetSendGridApiUri(ENDPOINT, "links", linkId, "validate")).Respond("application/json", apiResponse); var client = Utils.GetFluentClient(mockHttp); var whitelabel = new Whitelabel(client); // Act var result = await whitelabel.ValidateLinkAsync(linkId).ConfigureAwait(false); // Assert mockHttp.VerifyNoOutstandingExpectation(); mockHttp.VerifyNoOutstandingRequest(); result.ShouldNotBeNull(); result.LinkId.ShouldBe(1); result.IsValid.ShouldBe(true); result.ValidationResults.Domain.IsValid.ShouldBe(false); result.ValidationResults.Domain.Reason.ShouldBe("Expected CNAME to match \'sendgrid.net.\' but found \'example.com.\'."); result.ValidationResults.Owner.IsValid.ShouldBe(true); result.ValidationResults.Owner.Reason.ShouldBeNull(); }