Ejemplo n.º 1
0
        public void ValidateBatchId_false()
        {
            // Arrange
            var batchId = "ABC123";

            var apiResponse = @"{
				'errors': [
					{
						'field': null,
						'message': 'invalid batch id'
					}
				]
			}"            ;

            var mockHttp = new MockHttpMessageHandler();

            mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri(ENDPOINT, batchId)).Respond(HttpStatusCode.BadRequest, "application/json", apiResponse);

            var client  = Utils.GetFluentClient(mockHttp);
            var batches = new Batches(client);

            // Act
            var result = batches.ValidateBatchIdAsync(batchId).Result;

            // Assert
            mockHttp.VerifyNoOutstandingExpectation();
            mockHttp.VerifyNoOutstandingRequest();
            result.ShouldBeFalse();
        }
Ejemplo n.º 2
0
        public void ValidateBatchId_false()
        {
            // Arrange
            var batchId = "ABC123";

            var apiResponse = @"{
				'errors': [
					{
						'field': null,
						'message': 'invalid batch id'
					}
				]
			}"            ;

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

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

            var batches = new Batches(mockClient.Object, ENDPOINT);

            // Act
            var result = batches.ValidateBatchIdAsync(batchId).Result;

            // Assert
            result.ShouldBeFalse();
        }
Ejemplo n.º 3
0
        public async Task ValidateBatchIdAsync_problem()
        {
            // Arrange
            var batchId = "ABC123";

            var apiResponse = @"{
				'errors': [
					{
						'field': null,
						'message': 'an error has occured'
					}
				]
			}"            ;

            var mockHttp = new MockHttpMessageHandler();

            mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri(ENDPOINT, batchId)).Respond(HttpStatusCode.BadRequest, "application/json", apiResponse);

            var client  = Utils.GetFluentClient(mockHttp);
            var batches = new Batches(client);

            // Act
            var result = await Should.ThrowAsync <Exception>(async() => await batches.ValidateBatchIdAsync(batchId).ConfigureAwait(false)).ConfigureAwait(false);

            // Assert
            mockHttp.VerifyNoOutstandingExpectation();
            mockHttp.VerifyNoOutstandingRequest();

            result.Message.ShouldBe("an error has occured");
        }
Ejemplo n.º 4
0
        public async Task ValidateBatchIdAsync_false()
        {
            // Arrange
            var batchId = "ABC123";

            var apiResponse = @"{
				""errors"": [
					{
						""field"": null,
						""message"": ""invalid batch id""
					}
				]
			}"            ;

            var mockHttp = new MockHttpMessageHandler();

            mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri(ENDPOINT, batchId)).Respond(HttpStatusCode.BadRequest, "application/json", apiResponse);

            var client  = Utils.GetFluentClient(mockHttp);
            var batches = new Batches(client);

            // Act
            var result = await batches.ValidateBatchIdAsync(batchId).ConfigureAwait(false);

            // Assert
            mockHttp.VerifyNoOutstandingExpectation();
            mockHttp.VerifyNoOutstandingRequest();
            result.ShouldBeFalse();
        }
Ejemplo n.º 5
0
        public void ValidateBatchId_true()
        {
            // Arrange
            var batchId = "ABC123";

            var apiResponse = @"{
				'batch_id': 'ABC123'
			}"            ;

            var mockHttp = new MockHttpMessageHandler();

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

            var client  = Utils.GetFluentClient(mockHttp);
            var batches = new Batches(client);

            // Act
            var result = batches.ValidateBatchIdAsync(batchId).Result;

            // Assert
            mockHttp.VerifyNoOutstandingExpectation();
            mockHttp.VerifyNoOutstandingRequest();
            result.ShouldBeTrue();
        }