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(); }
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); }
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(); }