public void Create()
        {
            // Arrange
            var name = "customfield1";
            var type = FieldType.Text;

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

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

            var customFields = new CustomFields(mockClient.Object, ENDPOINT);

            // Act
            var result = customFields.CreateAsync(name, type, CancellationToken.None).Result;

            // Assert
            result.ShouldNotBeNull();
        }
예제 #2
0
        public void Create()
        {
            // Arrange
            var name = "customfield1";
            var type = FieldType.Text;

            var apiResponse = @"{
				'id': 1,
				'name': 'customfield1',
				'type': 'text'
			}"            ;
            var mockClient  = new Mock <IClient>(MockBehavior.Strict);

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

            var customFields = new CustomFields(mockClient.Object);

            // Act
            var result = customFields.CreateAsync(name, type, CancellationToken.None).Result;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Id);
            Assert.AreEqual(name, result.Name);
            Assert.AreEqual(type, result.Type);
        }
예제 #3
0
        public async Task CreateAsync()
        {
            // Arrange
            var name = "customfield1";
            var type = FieldType.Text;

            var mockHttp = new MockHttpMessageHandler();

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

            var client       = Utils.GetFluentClient(mockHttp);
            var customFields = new CustomFields(client);

            // Act
            var result = await customFields.CreateAsync(name, type, CancellationToken.None).ConfigureAwait(false);

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