Class ApiOptionsSingleton was implemented in order to support proper unit tests.

Now ApiOptionsSingleton.Instance is used as ApiOptions.None static member instead of creation of new ApiOptions class each time when ApiOptions.None is invoked.

Singleton pattern will allow write proper tests for methods that use ApiOptions.None as their parameter

For instance, now "Arg.Is<ApiOptions>(options => options == ApiOptions.None)" construction can be used.

Also, usage of sigleton has some posititve performance impact.
This commit is contained in:
aedampir@gmail.com
2016-03-15 17:10:08 +07:00
parent 816aad0c6a
commit b157c452a2
+24 -1
View File
@@ -7,9 +7,32 @@ namespace Octokit
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class ApiOptions
{
private class ApiOptionsSingleton
{
private static readonly ApiOptions _instance = new ApiOptions();
// Explicit static constructor to tell C# compiler
// not to mark type as beforefieldinit
static ApiOptionsSingleton()
{
}
private ApiOptionsSingleton()
{
}
public static ApiOptions Instance
{
get
{
return _instance;
}
}
}
public static ApiOptions None
{
get { return new ApiOptions(); }
get { return ApiOptionsSingleton.Instance; }
}
/// <summary>