Skip to content

Commit

Permalink
Add more IdentityEquals extension methods to compare between `Valid…
Browse files Browse the repository at this point in the history
…ationPackage` and `ValidationPackageIndex`
  • Loading branch information
kMutagene committed Jun 21, 2024
1 parent c8cbd28 commit 082a6f7
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/AVPRClient/AVPRClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<RepositoryType>git</RepositoryType>
<PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/RELEASE_NOTES.md"))</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageVersion>0.1.1</PackageVersion>
<PackageVersion>0.1.2</PackageVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
27 changes: 27 additions & 0 deletions src/AVPRClient/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,33 @@ AVPRClient.ValidationPackage other
&& package.PreReleaseVersionSuffix == other.PreReleaseVersionSuffix
&& package.BuildMetadataVersionSuffix == other.BuildMetadataVersionSuffix;
}

public static bool IdentityEquals(
this AVPRClient.ValidationPackage package,
AVPRIndex.Domain.ValidationPackageIndex indexedPackage
)
{
return package.Name == indexedPackage.Metadata.Name
&& package.MajorVersion == indexedPackage.Metadata.MajorVersion
&& package.MinorVersion == indexedPackage.Metadata.MinorVersion
&& package.PatchVersion == indexedPackage.Metadata.PatchVersion
&& package.PreReleaseVersionSuffix == indexedPackage.Metadata.PreReleaseVersionSuffix
&& package.BuildMetadataVersionSuffix == indexedPackage.Metadata.BuildMetadataVersionSuffix;
}

public static bool IdentityEquals(
this AVPRIndex.Domain.ValidationPackageIndex indexedPackage,
AVPRClient.ValidationPackage package
)
{
return package.Name == indexedPackage.Metadata.Name
&& package.MajorVersion == indexedPackage.Metadata.MajorVersion
&& package.MinorVersion == indexedPackage.Metadata.MinorVersion
&& package.PatchVersion == indexedPackage.Metadata.PatchVersion
&& package.PreReleaseVersionSuffix == indexedPackage.Metadata.PreReleaseVersionSuffix
&& package.BuildMetadataVersionSuffix == indexedPackage.Metadata.BuildMetadataVersionSuffix;
}

public static AVPRClient.ValidationPackage toValidationPackage(
this AVPRIndex.Domain.ValidationPackageIndex indexedPackage,
DateTimeOffset releaseDate
Expand Down
3 changes: 3 additions & 0 deletions src/AVPRClient/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v0.1.2
- Add more `IdentityEquals` extension methods to compare between `ValidationPackage` and `ValidationPackageIndex`

## v0.1.1
- Add `IdentityEquals` extension method for `ValidationPackage`

Expand Down
36 changes: 36 additions & 0 deletions tests/ClientTests/ReferenceObjects.fs
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,40 @@ module ValidationPackage =
Tags = [|OntologyAnnotation.allFieldsClient|],
ReleaseNotes = "releasenotes",
CQCHookEndpoint = "hookendpoint"
)

module ValidationPackageIndex =

open System.IO

let allFields_cqcHookAddition = AVPRIndex.Domain.ValidationPackageIndex.create(
repoPath = "",
fileName = "",
lastUpdated = System.DateTime.Now,
contentHash = "",
metadata = AVPRIndex.Domain.ValidationPackageMetadata.create(
name = "name",
majorVersion = 1,
minorVersion = 0,
patchVersion = 0,
summary = "summary",
description = "description"
)
)

let allFields_semVerAddition = AVPRIndex.Domain.ValidationPackageIndex.create(
repoPath = "",
fileName = "",
lastUpdated = System.DateTime.Now,
contentHash = "",
metadata = AVPRIndex.Domain.ValidationPackageMetadata.create(
name = "name",
majorVersion = 1,
minorVersion = 0,
patchVersion = 0,
summary = "summary",
description = "description",
PreReleaseVersionSuffix = "use",
BuildMetadataVersionSuffix = "suffixes"
)
)
49 changes: 48 additions & 1 deletion tests/ClientTests/TypeExtensionsTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ open System.Security.Cryptography
module ValidationPackage =

[<Fact>]
let ``IdentityEquals returns true for the same package without suffixes`` () =
let ``IdentityEquals returns true for the same package (no suffixes)`` () =
Assert.True(
ReferenceObjects.ValidationPackage.allFields_cqcHookAddition.IdentityEquals(
ReferenceObjects.ValidationPackage.allFields_cqcHookAddition
Expand All @@ -34,6 +34,30 @@ module ValidationPackage =
)
)

[<Fact>]
let ``IdentityEquals returns true for indexed package with same version (no suffixes)`` () =
Assert.True(
ReferenceObjects.ValidationPackage.allFields_cqcHookAddition.IdentityEquals(
ReferenceObjects.ValidationPackageIndex.allFields_cqcHookAddition
)
)

[<Fact>]
let ``IdentityEquals returns true for indexed package with same version with suffixes`` () =
Assert.True(
ReferenceObjects.ValidationPackage.allFields_semVerAddition.IdentityEquals(
ReferenceObjects.ValidationPackageIndex.allFields_semVerAddition
)
)

[<Fact>]
let ``IdentityEquals returns false for a different indexed package`` () =
Assert.False(
ReferenceObjects.ValidationPackage.allFields_cqcHookAddition.IdentityEquals(
ReferenceObjects.ValidationPackageIndex.allFields_semVerAddition
)
)

module ValidationPackageIndex =

let allFields_cqcHookAddition = AVPRIndex.Domain.ValidationPackageIndex.create(
Expand Down Expand Up @@ -82,6 +106,29 @@ module ValidationPackageIndex =
let actual = allFields_semVerAddition.toPackageContentHash(HashFileDirectly = true)
Assert.Equivalent(ReferenceObjects.Hash.allFields_semVerAddition, actual)

[<Fact>]
let ``IdentityEquals returns true for package with same version (no suffixes)`` () =
Assert.True(
ReferenceObjects.ValidationPackageIndex.allFields_cqcHookAddition.IdentityEquals(
ReferenceObjects.ValidationPackage.allFields_cqcHookAddition
)
)

[<Fact>]
let ``IdentityEquals returns true for package with same version with suffixes`` () =
Assert.True(
ReferenceObjects.ValidationPackageIndex.allFields_semVerAddition.IdentityEquals(
ReferenceObjects.ValidationPackage.allFields_semVerAddition
)
)

[<Fact>]
let ``IdentityEquals returns false for a different package`` () =
Assert.False(
ReferenceObjects.ValidationPackageIndex.allFields_cqcHookAddition.IdentityEquals(
ReferenceObjects.ValidationPackage.allFields_semVerAddition
)
)
module Author =

open System.Collections
Expand Down

0 comments on commit 082a6f7

Please sign in to comment.