Skip to content

Commit

Permalink
KCL-1222: Improve naming and documentation of options and builder cla…
Browse files Browse the repository at this point in the history
…sses
  • Loading branch information
alesk-kentico authored and Tobias Kamenicky committed Oct 3, 2019
1 parent 240f138 commit 3f1fa02
Show file tree
Hide file tree
Showing 21 changed files with 227 additions and 245 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public void BuildWithProjectIdAndUseProductionApi()
var deliveryOptions = DeliveryOptionsBuilder
.CreateInstance()
.WithProjectId(ProjectId)
.UseProductionApi
.UseProductionApi()
.Build();

Assert.Equal(deliveryOptions.ProjectId, ProjectId);
Assert.False(deliveryOptions.UsePreviewApi);
Assert.False(deliveryOptions.UseSecuredProductionApi);
Assert.False(deliveryOptions.UseSecureAccess);
}

[Fact]
Expand All @@ -49,40 +49,38 @@ public void BuildWithProjectIdAndSecuredProductionApi()
var deliveryOptions = DeliveryOptionsBuilder
.CreateInstance()
.WithProjectId(ProjectId)
.UseSecuredProductionApi(SecuredApiKey)
.UseProductionApi(SecuredApiKey)
.Build();

Assert.Equal(ProjectId, deliveryOptions.ProjectId);
Assert.True(deliveryOptions.UseSecuredProductionApi);
Assert.Equal(SecuredApiKey, deliveryOptions.SecuredProductionApiKey);
Assert.True(deliveryOptions.UseSecureAccess);
Assert.Equal(SecuredApiKey, deliveryOptions.SecureAccessApiKey);
}

[Fact]
public void BuildWithRetryPolicyOptions()
{
var retryOptions = new RetryPolicyOptions();
var retryOptions = new DefaultRetryPolicyOptions();

var deliveryOptions = DeliveryOptionsBuilder
.CreateInstance()
.WithProjectId(ProjectId)
.UseProductionApi
.WithRetryPolicyOptions(retryOptions)
.UseProductionApi()
.WithDefaultRetryPolicyOptions(retryOptions)
.Build();

Assert.Equal(deliveryOptions.RetryPolicyOptions, retryOptions);
Assert.Equal(deliveryOptions.DefaultRetryPolicyOptions, retryOptions);
}

[Fact]
public void BuildWithNullRetryPolicyOptions_ResilienceLogicIsDisabled()
public void BuildWithNullRetryPolicyOptions_ThrowsException()
{
var deliveryOptions = DeliveryOptionsBuilder
Assert.Throws<ArgumentNullException>(() => DeliveryOptionsBuilder
.CreateInstance()
.WithProjectId(ProjectId)
.UseProductionApi
.WithRetryPolicyOptions(null)
.Build();

Assert.False(deliveryOptions.EnableRetryPolicy);
.UseProductionApi()
.WithDefaultRetryPolicyOptions(null)
.Build());
}

[Fact]
Expand All @@ -91,8 +89,8 @@ public void BuildWithDisabledRetryLogic()
var deliveryOptions = DeliveryOptionsBuilder
.CreateInstance()
.WithProjectId(Guid.NewGuid())
.UseProductionApi
.DisableRetryLogic
.UseProductionApi()
.DisableRetryPolicy()
.Build();

Assert.False(deliveryOptions.EnableRetryPolicy);
Expand All @@ -104,8 +102,8 @@ public void BuildWithWaitForLoadingNewContent()
var deliveryOptions = DeliveryOptionsBuilder
.CreateInstance()
.WithProjectId(Guid.NewGuid())
.UseProductionApi
.WaitForLoadingNewContent
.UseProductionApi()
.WaitForLoadingNewContent()
.Build();

Assert.True(deliveryOptions.WaitForLoadingNewContent);
Expand Down Expand Up @@ -134,7 +132,7 @@ public void BuildWithCustomEndpointForProductionApi()
var deliveryOptions = DeliveryOptionsBuilder
.CreateInstance()
.WithProjectId(ProjectId)
.UseProductionApi
.UseProductionApi()
.WithCustomEndpoint(customEndpoint)
.Build();

Expand Down Expand Up @@ -166,7 +164,7 @@ public void BuildWithCustomEndpointAsUriForProductionApi()
var deliveryOptions = DeliveryOptionsBuilder
.CreateInstance()
.WithProjectId(ProjectId)
.UseProductionApi
.UseProductionApi()
.WithCustomEndpoint(uri)
.Build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void ValidateRetryOptions_NegativeDeltaBackoff_Throws()
var deliveryOptions = new Delivery.DeliveryOptions
{
ProjectId = _guid.ToString(),
RetryPolicyOptions = new RetryPolicyOptions
DefaultRetryPolicyOptions = new DefaultRetryPolicyOptions
{
DeltaBackoff = TimeSpan.FromSeconds(-1)
}
Expand All @@ -28,7 +28,7 @@ public void ValidateRetryOptions_ZeroDeltaBackoff_Throws()
var deliveryOptions = new Delivery.DeliveryOptions
{
ProjectId = _guid.ToString(),
RetryPolicyOptions = new RetryPolicyOptions
DefaultRetryPolicyOptions = new DefaultRetryPolicyOptions
{
DeltaBackoff = TimeSpan.Zero
}
Expand All @@ -43,7 +43,7 @@ public void ValidateRetryOptions_NegativeMaxCumulativeWaitTime_Throws()
var deliveryOptions = new Delivery.DeliveryOptions
{
ProjectId = _guid.ToString(),
RetryPolicyOptions = new RetryPolicyOptions
DefaultRetryPolicyOptions = new DefaultRetryPolicyOptions
{
MaxCumulativeWaitTime = TimeSpan.FromSeconds(-1)
}
Expand All @@ -58,7 +58,7 @@ public void ValidateRetryOptions_ZeroMaxCumulativeWaitTime_Throws()
var deliveryOptions = new Delivery.DeliveryOptions
{
ProjectId = _guid.ToString(),
RetryPolicyOptions = new RetryPolicyOptions
DefaultRetryPolicyOptions = new DefaultRetryPolicyOptions
{
MaxCumulativeWaitTime = TimeSpan.Zero
}
Expand All @@ -68,15 +68,15 @@ public void ValidateRetryOptions_ZeroMaxCumulativeWaitTime_Throws()
}

[Fact]
public void ValidateNullRetryOptions_DoesNotThrow()
public void ValidateNullRetryOptions_Throws()
{
var deliveryOptions = new Delivery.DeliveryOptions
{
ProjectId = _guid.ToString(),
RetryPolicyOptions = null
DefaultRetryPolicyOptions = null
};

deliveryOptions.Validate();
Assert.Throws<ArgumentNullException>(() => deliveryOptions.Validate());
}

[Fact]
Expand Down Expand Up @@ -122,7 +122,7 @@ public void ValidateOptionsWithNullSecuredApiKey()
.CreateInstance()
.WithProjectId(_guid);

Assert.Throws<ArgumentNullException>(() => deliveryOptionsStep.UseSecuredProductionApi(null));
Assert.Throws<ArgumentNullException>(() => deliveryOptionsStep.UseProductionApi(null));
}

[Fact]
Expand All @@ -146,8 +146,8 @@ public void ValidateOptionsUseOfPreviewAndProductionApiSimultaneously()
ProjectId = _guid.ToString(),
UsePreviewApi = true,
PreviewApiKey = previewApiKey,
UseSecuredProductionApi = true,
SecuredProductionApiKey = productionApiKey
UseSecureAccess = true,
SecureAccessApiKey = productionApiKey
};

Assert.Throws<InvalidOperationException>(() => deliveryOptions.Validate());
Expand All @@ -171,7 +171,7 @@ public void ValidateOptionsWithEnabledSecuredApiWithSetKey()
var deliveryOptions = new Delivery.DeliveryOptions
{
ProjectId = _guid.ToString(),
UseSecuredProductionApi = true
UseSecureAccess = true
};

Assert.Throws<InvalidOperationException>(() => deliveryOptions.Validate());
Expand All @@ -186,7 +186,7 @@ public void ValidateOptionsWithInvalidEndpointFormat(string endpoint)
var deliveryOptionsSteps = DeliveryOptionsBuilder
.CreateInstance()
.WithProjectId(_guid)
.UseProductionApi;
.UseProductionApi();

Assert.Throws<ArgumentException>(() => deliveryOptionsSteps.WithCustomEndpoint(endpoint));
}
Expand All @@ -197,7 +197,7 @@ public void ValidateOptionsWithNullUriEndpoint()
var deliveryOptionsSteps = DeliveryOptionsBuilder
.CreateInstance()
.WithProjectId(_guid)
.UseProductionApi;
.UseProductionApi();

Assert.Throws<ArgumentNullException>(() => deliveryOptionsSteps.WithCustomEndpoint((Uri)null));
}
Expand All @@ -209,7 +209,7 @@ public void ValidateOptionsWithUriEndpointWrongScheme()
var deliveryOptionsSteps = DeliveryOptionsBuilder
.CreateInstance()
.WithProjectId(_guid)
.UseProductionApi;
.UseProductionApi();

Assert.Throws<ArgumentException>(() => deliveryOptionsSteps.WithCustomEndpoint(incorrectSchemeUri));
}
Expand All @@ -221,7 +221,7 @@ public void ValidateOptionsWithRelativeUriEndpoint()
var deliveryOptionsSteps = DeliveryOptionsBuilder
.CreateInstance()
.WithProjectId(_guid)
.UseProductionApi;
.UseProductionApi();

Assert.Throws<ArgumentException>(() => deliveryOptionsSteps.WithCustomEndpoint(relativeUri));
}
Expand Down
8 changes: 4 additions & 4 deletions Kentico.Kontent.Delivery.Tests/DeliveryClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -851,9 +851,9 @@ public async void PreviewAndSecuredProductionThrowsWhenBothEnabled(bool usePrevi
{
ProjectId = _guid.ToString(),
UsePreviewApi = usePreviewApi,
UseSecuredProductionApi = useSecuredProduction,
UseSecureAccess = useSecuredProduction,
PreviewApiKey = "someKey",
SecuredProductionApiKey = "someKey"
SecureAccessApiKey = "someKey"
};

var client = DeliveryClientFactory.GetMockedDeliveryClientWithOptions(options, _mockHttp);
Expand Down Expand Up @@ -885,8 +885,8 @@ public async void SecuredProductionAddCorrectHeader()
var options = new DeliveryOptions
{
ProjectId = _guid.ToString(),
SecuredProductionApiKey = securityKey,
UseSecuredProductionApi = true
SecureAccessApiKey = securityKey,
UseSecureAccess = true
};
_mockHttp
.Expect($"{_baseUrl}/items")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void AddDeliveryClientWithDeliveryOptions_AllServicesAreRegistered()
public void AddDeliveryClientWithProjectId_AllServicesAreRegistered()
{
_fakeServiceCollection.AddDeliveryClient(builder =>
builder.WithProjectId(ProjectId).UseProductionApi.Build());
builder.WithProjectId(ProjectId).UseProductionApi().Build());

AssertDefaultServiceCollection(_expectedInterfacesWithImplementationTypes, _expectedResolvableContentTypes);
}
Expand Down
2 changes: 1 addition & 1 deletion Kentico.Kontent.Delivery.Tests/FakeHttpClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private static DeliveryOptions MockDeliveryOptions(string baseUrl)
=> DeliveryOptionsBuilder
.CreateInstance()
.WithProjectId(Guid.NewGuid())
.UseProductionApi
.UseProductionApi()
.WithCustomEndpoint($"{baseUrl}/{{0}}")
.Build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void Constructor_NullRetryPolicyOptions_ThrowsArgumentNullException()
{
var deliveryOptions = Options.Create(new DeliveryOptions
{
RetryPolicyOptions = null
DefaultRetryPolicyOptions = null
});

Assert.Throws<ArgumentNullException>(() => new DefaultRetryPolicyProvider(deliveryOptions));
Expand All @@ -23,7 +23,7 @@ public void GetRetryPolicy_ReturnsDefaultPolicy()
{
var deliveryOptions = Options.Create(new DeliveryOptions
{
RetryPolicyOptions = new RetryPolicyOptions()
DefaultRetryPolicyOptions = new DefaultRetryPolicyOptions()
});
var provider = new DefaultRetryPolicyProvider(deliveryOptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class DefaultRetryPolicyTests
[Fact]
public async Task ExecuteAsync_ResponseOk_DoesNotRetry()
{
var options = new RetryPolicyOptions
var options = new DefaultRetryPolicyOptions
{
DeltaBackoff = TimeSpan.FromSeconds(5)
};
Expand All @@ -32,7 +32,7 @@ public async Task ExecuteAsync_ResponseOk_DoesNotRetry()
[Fact]
public async Task ExecuteAsync_RecoversAfterNotSuccessStatusCode()
{
var options = new RetryPolicyOptions
var options = new DefaultRetryPolicyOptions
{
DeltaBackoff = TimeSpan.FromMilliseconds(100)
};
Expand All @@ -51,7 +51,7 @@ public async Task ExecuteAsync_RecoversAfterNotSuccessStatusCode()
[Fact]
public async Task ExecuteAsync_RecoversAfterException()
{
var options = new RetryPolicyOptions
var options = new DefaultRetryPolicyOptions
{
DeltaBackoff = TimeSpan.FromMilliseconds(100)
};
Expand All @@ -72,7 +72,7 @@ public async Task ExecuteAsync_RecoversAfterException()
[Fact]
public async Task ExecuteAsync_UnsuccessfulStatusCode_RetriesUntilCumulativeWaitTimeReached()
{
var options = new RetryPolicyOptions
var options = new DefaultRetryPolicyOptions
{
DeltaBackoff = TimeSpan.FromMilliseconds(100),
MaxCumulativeWaitTime = TimeSpan.FromSeconds(2)
Expand All @@ -93,7 +93,7 @@ public async Task ExecuteAsync_UnsuccessfulStatusCode_RetriesUntilCumulativeWait
[Fact]
public async Task ExecuteAsync_Exception_RetriesUntilCumulativeWaitTimeReached()
{
var options = new RetryPolicyOptions
var options = new DefaultRetryPolicyOptions
{
DeltaBackoff = TimeSpan.FromMilliseconds(100),
MaxCumulativeWaitTime = TimeSpan.FromSeconds(2)
Expand All @@ -115,7 +115,7 @@ public async Task ExecuteAsync_Exception_RetriesUntilCumulativeWaitTimeReached()
[InlineData(HttpStatusCode.ServiceUnavailable)]
public async Task ExecuteAsync_ThrottledRequest_NoHeader_GetsNextWaitTime(HttpStatusCode statusCode)
{
var options = new RetryPolicyOptions
var options = new DefaultRetryPolicyOptions
{
DeltaBackoff = TimeSpan.FromSeconds(10),
MaxCumulativeWaitTime = TimeSpan.FromSeconds(5)
Expand All @@ -136,7 +136,7 @@ public async Task ExecuteAsync_ThrottledRequest_NoHeader_GetsNextWaitTime(HttpSt
[InlineData(HttpStatusCode.ServiceUnavailable, 0)]
public async Task ExecuteAsync_ThrottledRequest_RetryAfterHeaderWithNotPositiveDelta_GetsNextWaitTime(HttpStatusCode statusCode, int waitTimeInSeconds)
{
var options = new RetryPolicyOptions
var options = new DefaultRetryPolicyOptions
{
DeltaBackoff = TimeSpan.FromSeconds(10),
MaxCumulativeWaitTime = TimeSpan.FromSeconds(5)
Expand All @@ -157,7 +157,7 @@ public async Task ExecuteAsync_ThrottledRequest_RetryAfterHeaderWithNotPositiveD
[InlineData(HttpStatusCode.ServiceUnavailable)]
public async Task ExecuteAsync_ThrottledRequest_RetryAfterHeaderWithPastDate_GetsNextWaitTime(HttpStatusCode statusCode)
{
var options = new RetryPolicyOptions
var options = new DefaultRetryPolicyOptions
{
DeltaBackoff = TimeSpan.FromSeconds(10),
MaxCumulativeWaitTime = TimeSpan.FromSeconds(5)
Expand All @@ -178,7 +178,7 @@ public async Task ExecuteAsync_ThrottledRequest_RetryAfterHeaderWithPastDate_Get
[InlineData(HttpStatusCode.ServiceUnavailable)]
public async Task ExecuteAsync_ThrottledRequest_RetryAfterHeaderWithDelta_ReadsWaitTimeFromHeader(HttpStatusCode statusCode)
{
var options = new RetryPolicyOptions
var options = new DefaultRetryPolicyOptions
{
DeltaBackoff = TimeSpan.FromMilliseconds(100),
MaxCumulativeWaitTime = TimeSpan.FromSeconds(5)
Expand All @@ -199,7 +199,7 @@ public async Task ExecuteAsync_ThrottledRequest_RetryAfterHeaderWithDelta_ReadsW
[InlineData(HttpStatusCode.ServiceUnavailable)]
public async Task ExecuteAsync_ThrottledRequest_RetryAfterHeaderWithDate_ReadsWaitTimeFromHeader(HttpStatusCode statusCode)
{
var options = new RetryPolicyOptions
var options = new DefaultRetryPolicyOptions
{
DeltaBackoff = TimeSpan.FromMilliseconds(100),
MaxCumulativeWaitTime = TimeSpan.FromSeconds(5)
Expand All @@ -224,7 +224,7 @@ public async Task ExecuteAsync_ThrottledRequest_RetryAfterHeaderWithDate_ReadsWa
[InlineData(HttpStatusCode.GatewayTimeout)]
public async Task ExecuteAsync_RetriesForCertainStatusCodes(HttpStatusCode statusCode)
{
var options = new RetryPolicyOptions
var options = new DefaultRetryPolicyOptions
{
DeltaBackoff = TimeSpan.FromMilliseconds(100)
};
Expand All @@ -244,7 +244,7 @@ public async Task ExecuteAsync_RetriesForCertainStatusCodes(HttpStatusCode statu
[MemberData(nameof(RetriedExceptions))]
public async Task ExecuteAsync_RetriesForCertainExceptions(Exception exception)
{
var options = new RetryPolicyOptions
var options = new DefaultRetryPolicyOptions
{
DeltaBackoff = TimeSpan.FromMilliseconds(100)
};
Expand Down
Loading

0 comments on commit 3f1fa02

Please sign in to comment.