public void Creating_WithResource_SetsRequestValuesCorrectly() { var resource = new ResourceBaseBuilder().WithMethod(HttpMethod.Delete).WithRequestBody(new { Value = true }); var sut = new PartnerApiRequestBuilder().Build(); var actual = sut.Create(resource).Result; Assert.AreEqual(HttpMethod.Delete, actual.Method); Assert.AreEqual("{\"Value\":true}", actual.Content.ReadAsStringAsync().Result); }
public void Creating_WithPartnerToken_SetsAuthorizationHeaderCorrectly() { var sut = new PartnerApiRequestBuilder() .WithPartner(new PartnerAccessTokenStubBuilder().WithGet(new PartnerAccessTokenDtoBuilder().WithTokenType("Bearer").WithAccessToken("xXx")).Build()) .Build(); var actual = sut.Create(new ResourceBaseBuilder()).Result.Headers.Authorization.ToString(); Assert.AreEqual("Bearer xXx", actual); }
public void Creating_WithResourceContainingParameters_SetsUriCorrectly() { var sut = new PartnerApiRequestBuilder() .WithEndpoint(new EndpointStubBuilder().WithUri("https://sign.visma.net/").Build()) .WithOrganizationToken(new OrganizationTokenStubBuilder().WithGet("5678").Build()) .Build(); var actual = sut.Create(new ResourceBaseBuilder().WithResourceUri("api/v1/organization?business_id=1234567-1")).Result.RequestUri.ToString(); Assert.AreEqual("https://sign.visma.net/api/v1/organization?business_id=1234567-1&as_organization=5678", actual); }
public void Creating_WithGivenBusinessId_GetsCorrectToken() { var token = new OrganizationTokenStubBuilder().Build(); var sut = new PartnerApiRequestBuilder() .WithCurrentOrganization(new CurrentOrganizationStubBuilder().WithBusinessId("1234567-1").Build()) .WithOrganizationToken(token) .Build(); sut.Create(new ResourceBaseBuilder()).Wait(); token.Received(1).Get("1234567-1"); }
public void Creating_WithoutOrganizationBeingDefined_SetsUriCorrectly(string businessId) { var token = new OrganizationTokenStubBuilder().Build(); var sut = new PartnerApiRequestBuilder() .WithEndpoint(new EndpointStubBuilder().WithUri("https://sign.visma.net/").Build()) .WithCurrentOrganization(new CurrentOrganizationStubBuilder().WithBusinessId(businessId).Build()) .Build(); var actual = sut.Create(new ResourceBaseBuilder().WithResourceUri("api/v1/organization?business_id=1234567-1")).Result.RequestUri.ToString(); Assert.AreEqual("https://sign.visma.net/api/v1/organization?business_id=1234567-1", actual); token.Received(0).Get(Arg.Any <string>()); }