Skip to content

Commit

Permalink
nibhati-5142-add Params and testing for ApiVersionBase.cs (#19193)
Browse files Browse the repository at this point in the history
* add tests for ApiVersionBase

* update methods
  • Loading branch information
nisha-bhatia authored Mar 4, 2021
1 parent b066d3f commit e7200c8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ protected ApiVersionsBase(string value)
/// <returns></returns>
public static bool operator <(ApiVersionsBase left, ApiVersionsBase right)
{
if (left is null)
return true;
if (ReferenceEquals(null, left))
return !ReferenceEquals(null, right);

return left.CompareTo(right) == -1;
}
Expand All @@ -44,7 +44,7 @@ protected ApiVersionsBase(string value)
/// <returns></returns>
public static bool operator >(ApiVersionsBase left, ApiVersionsBase right)
{
if (left is null)
if (ReferenceEquals(null, left))
return false;

return left.CompareTo(right) == 1;
Expand All @@ -57,6 +57,10 @@ protected ApiVersionsBase(string value)
/// <returns> API version value. </returns>
public static implicit operator string(ApiVersionsBase version)
{
if (ReferenceEquals(null, version))
{
return null;
}
return version._value;
}

Expand Down Expand Up @@ -109,7 +113,7 @@ public static implicit operator string(ApiVersionsBase version)
/// <returns> Comparison result in integer. 1 for greater than, 0 for equals to, and -1 for less than. </returns>
public int CompareTo(string other)
{
if (other == null)
if (other is null)
{
return 1;
}
Expand Down Expand Up @@ -180,14 +184,9 @@ public override string ToString()
public override bool Equals(object obj)
{
if (obj is ApiVersionsBase)
{
return Equals(obj as ApiVersionsBase);
}

if (obj is string)
{
return Equals(obj as string);
}

return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ private FakeResourceApiVersions ConvertFromString(string version)
return FakeResourceApiVersions.V2019_12_01_preview_1;
case "2019-12-01-foobar":
return FakeResourceApiVersions.V2019_12_01_foobar;
case null:
return null;
default:
throw new ArgumentException($"Version ({version}) was not valid");
}
Expand Down Expand Up @@ -212,5 +214,43 @@ public void GetHashCodeTest()
FakeResourceApiVersions version = FakeResourceApiVersions.Default;
Assert.AreEqual(version.ToString().GetHashCode(), version.GetHashCode());
}

[TestCase("2019-12-01", null)]
[TestCase("2020-06-01", "2019-12-01")]
public void TestGreaterThanTrue(string leftString, string rightString)
{
FakeResourceApiVersions left = ConvertFromString(leftString);
FakeResourceApiVersions right = ConvertFromString(rightString);
Assert.IsTrue(left > right);
}

[TestCase(null, "2019-12-01")]
[TestCase("2019-12-01", "2020-06-01")]
[TestCase(null, null)]
public void TestGreaterThanFalse(string leftString, string rightString)
{
FakeResourceApiVersions left = ConvertFromString(leftString);
FakeResourceApiVersions right = ConvertFromString(rightString);
Assert.IsFalse(left > right);
}

[TestCase(null, "2019-12-01")]
[TestCase("2019-12-01-foobar", "2019-12-01-preview-1")]
public void TestLessThanTrue(string leftString, string rightString)
{
FakeResourceApiVersions left = ConvertFromString(leftString);
FakeResourceApiVersions right = ConvertFromString(rightString);
Assert.IsTrue(left < right);
}

[TestCase("2019-12-01", null)]
[TestCase("2020-06-01", "2019-12-01-foobar")]
[TestCase(null, null)]
public void TestLessThanFalse(string leftString, string rightString)
{
FakeResourceApiVersions left = ConvertFromString(leftString);
FakeResourceApiVersions right = ConvertFromString(rightString);
Assert.IsFalse(left < right);
}
}
}

0 comments on commit e7200c8

Please sign in to comment.