public async void PutAsync_CalledWithItem_ReturnsReponse() { // Given var client = new Mock <IRestClient>(); var response = new OrganizationResponse { Item = new Organization { Name = "blah blah" } }; var request = new OrganizationRequest { Item = new Organization { Name = "blah blah", Id = 123 } }; client.Setup(b => b.PutAsync <OrganizationResponse>( It.IsAny <Uri>(), request, "application/json", It.IsAny <string>(), It.IsAny <string>())) .Returns(TaskHelper.CreateTaskFromResult(response)); var resource = new OrganizationResource(client.Object); // When var result = await resource.PutAsync(request); // Then Assert.Equal(result, response); }
public void PutAsync_HasNoId_ThrowsException() { // Given var client = new Mock <IRestClient>(); var response = new OrganizationResponse { Item = new Organization { Name = "blah blah" } }; var request = new OrganizationRequest { Item = new Organization { Name = "blah blah" } }; client.Setup(b => b.PutAsync <OrganizationResponse>( It.IsAny <Uri>(), request, "application/json", It.IsAny <string>(), It.IsAny <string>())) .Returns(TaskHelper.CreateTaskFromResult(response)); var resource = new OrganizationResource(client.Object); // When, Then Assert.Throws <ArgumentException>(async() => await resource.PutAsync(request)); }
public async void PutAsync_Called_BuildsUri() { // Given var request = new OrganizationRequest { Item = new Organization { Name = "Organizations", Id = 123 } }; var resource = new OrganizationResource(_client.Object); // When await resource.PutAsync(request); // Then _client.Setup(b => b.BuildUri(It.IsAny <string>(), "")); }
public void PutAsync_HasNoId_ThrowsException() { // Given var response = new OrganizationResponse { Item = new Organization { Name = "blah blah" } }; var request = new OrganizationRequest { Item = new Organization { Name = "blah blah" } }; _client.Setup(b => b.PutAsync<OrganizationResponse>( It.IsAny<Uri>(), request, "application/json", It.IsAny<string>(), It.IsAny<string>())) .Returns(TaskHelper.CreateTaskFromResult(response)); var resource = new OrganizationResource(_client.Object); // When, Then Assert.Throws<ArgumentException>(async () => await resource.PutAsync(request)); }
public async void PutAsync_CalledWithItem_ReturnsReponse() { // Given var response = new OrganizationResponse { Item = new Organization { Name = "blah blah" } }; var request = new OrganizationRequest { Item = new Organization { Name = "blah blah", Id = 123 } }; _client.Setup(b => b.PutAsync<OrganizationResponse>( It.IsAny<Uri>(), request, "application/json", It.IsAny<string>(), It.IsAny<string>())) .Returns(TaskHelper.CreateTaskFromResult(response)); var resource = new OrganizationResource(_client.Object); // When var result = await resource.PutAsync(request); // Then Assert.That(result, Is.EqualTo(response)); }
public async void PutAsync_Called_BuildsUri() { // Given var request = new OrganizationRequest { Item = new Organization { Name = "Organizations", Id = 123 } }; var resource = new OrganizationResource(_client.Object); // When await resource.PutAsync(request); // Then _client.Setup(b => b.BuildUri(It.IsAny<string>(), "")); }