Skip to content

Commit

Permalink
[Internal] Tests: Adds Coverage to validate Cosmos .NET SDK versionin…
Browse files Browse the repository at this point in the history
…g strategy (#4567)

* Unit test coverage to validate Cosmos .NET SDK versioning strategy

* Updating logic to fix the build version comparision

* Renamed a method

* Great catch on exception catching, fixing it

* Using Tests Logger
  • Loading branch information
kirankumarkolli authored Jul 11, 2024
1 parent 5bba9a0 commit b478595
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
namespace Microsoft.Azure.Cosmos.Tests.Contracts
{
using System;
using System;
using System.Diagnostics;
using System.IO;
using System.Xml;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestCategory("Windows")]
Expand Down Expand Up @@ -46,6 +49,70 @@ public void TelemetryContractChanges()
public void UniqueKeyUnsealed()
{
Assert.IsFalse(typeof(UniqueKey).IsSealed);
}
}

[TestMethod]
public void ValdatePacakgeVersions()
{
const String VersionFile = "Directory.Build.props";

XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(File.ReadAllText(VersionFile));

XmlNode propertyGroupNode = xmldoc.DocumentElement["PropertyGroup"];

string officialVersionText = propertyGroupNode?["ClientOfficialVersion"]?.InnerText;
string previewVersionText = propertyGroupNode?["ClientPreviewVersion"]?.InnerText;
string previewSuffixText = propertyGroupNode?["ClientPreviewSuffixVersion"]?.InnerText;

Logger.LogLine($"Official Version: {officialVersionText}");
Logger.LogLine($"Preview Version: {previewVersionText}");
Logger.LogLine($"PreviewSuffix Suffix: {previewSuffixText}");

this.ValdateSDKVersionsUtil(officialVersionText, previewVersionText, previewSuffixText);
}

[TestMethod]
[DataRow("4.0.0", "4.1.0", "preview.0", false)]
[DataRow("4.0.1", "4.1.0", "preview.1", false)]
// Invalida pattern's
[DataRow("4.0.0", "4.0.0", "preview.0", true)]
[DataRow("4.0.0", "4.1.0", "preview.1", true)]
[DataRow("4.2.0", "4.1.0", "preview.0", true)]
public void ValdateSDKVersions(string officialVersionText,
string previewVersionText,
string previewSuffixText,
bool failureExpected)
{
if (failureExpected)
{
Assert.ThrowsException<AssertFailedException>(() => this.ValdateSDKVersionsUtil(officialVersionText, previewVersionText, previewSuffixText));
}
else
{
this.ValdateSDKVersionsUtil(officialVersionText, previewVersionText, previewSuffixText);
}
}

private void ValdateSDKVersionsUtil(string officialVersionText,
string previewVersionText,
string previewSuffixText)
{
Version officialVersion = new Version(officialVersionText);
Version previewVersion = new Version(previewVersionText);

string debugText = $"{officialVersionText} {previewVersionText} {previewSuffixText}";

string[] peviewSuffixSplits = previewSuffixText.Split('.');
Assert.AreEqual(2, peviewSuffixSplits.Length, $"{debugText}");

// Preview minor version should always be one ahead of the official version
Assert.AreEqual(officialVersion.Major, previewVersion.Major, $"{debugText}");
Assert.AreEqual(officialVersion.Minor + 1, previewVersion.Minor, $"{debugText}");
Assert.AreEqual(0, previewVersion.Build, $"{debugText}");

Assert.AreEqual(officialVersion.Build, int.Parse(peviewSuffixSplits[1]), $"{debugText}");
Assert.AreEqual("preview", peviewSuffixSplits[0], false, $"{debugText}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@
<Folder Include="Diagnostics\" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\..\Directory.Build.props" Link="Directory.Build.props">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<Compile Update="Tracing\TraceWriterBaselineTests.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down

0 comments on commit b478595

Please sign in to comment.