-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from jinaga:compare-proxy
Improved comparison semantics with proxies
- Loading branch information
Showing
7 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"cSpell.words": [ | ||
"michaelperry" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
global using FluentAssertions; | ||
global using Xunit; |
27 changes: 27 additions & 0 deletions
27
Jinaga.SourceGenerator.Test/Jinaga.SourceGenerator.Test.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="6.12.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Jinaga\Jinaga.csproj" /> | ||
<ProjectReference Include="..\Jinaga.UnitTest\Jinaga.UnitTest.csproj" /> | ||
<ProjectReference Include="..\Jinaga.SourceGenerator\Jinaga.SourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
|
||
namespace Jinaga.SourceGenerator.Test.Model; | ||
|
||
[FactType("Blog.Site")] | ||
public partial record Site(User creator, string identifier) { } | ||
|
||
[FactType("Blog.GuestBlogger")] | ||
public partial record GuestBlogger(Site site, User guest) { } | ||
|
||
[FactType("Blog.Content")] | ||
public partial record Content(Site site, string path) { } | ||
|
||
[FactType("Blog.Content")] | ||
public partial record ContentV2(Site site, DateTime? createdAt) { } | ||
|
||
[FactType("Blog.Comment")] | ||
public partial record Comment(Content content, Guid uniqueId, User author) { } | ||
|
||
[FactType("Blog.Content.Publish")] | ||
public partial record Publish(Content content, DateTime date) { } |
109 changes: 109 additions & 0 deletions
109
Jinaga.SourceGenerator.Test/Specifications/ProjectionVersioningTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
using Jinaga.UnitTest; | ||
|
||
namespace Jinaga.SourceGenerator.Test.Specifications; | ||
|
||
public class ProjectionVersioningTest | ||
{ | ||
[Fact] | ||
public async Task CanReadVersionOneFieldFromVersionOneFact() | ||
{ | ||
var jinagaClient = JinagaTest.Create(); | ||
var site = await jinagaClient.Fact(new Model.Site(new User("Michael"), "michaelperry.net")); | ||
var content = await jinagaClient.Fact(new Model.Content(site, "index.html")); | ||
var originalHash = jinagaClient.Hash(content); | ||
|
||
var contentPathForSite = Given<Model.Site>.Match((site, facts) => | ||
from content in facts.OfType<Model.Content>() | ||
where content.site == site | ||
select new | ||
{ | ||
content, | ||
content.path, | ||
hash = jinagaClient.Hash(content) | ||
} | ||
); | ||
var contentPath = await jinagaClient.Query(contentPathForSite, site); | ||
|
||
var projection = contentPath.Should().ContainSingle().Subject; | ||
projection.path.Should().Be("index.html"); | ||
projection.hash.Should().Be(originalHash); | ||
bool creatorEqual = projection.content.site.creator == content.site.creator; | ||
creatorEqual.Should().BeTrue(); | ||
bool siteEqual = projection.content.site == content.site; | ||
siteEqual.Should().BeTrue(); | ||
projection.content.Should().Be(content); | ||
} | ||
|
||
[Fact] | ||
public async Task CanReadVersionTwoFieldFromVersionOneFact() | ||
{ | ||
var jinagaClient = JinagaTest.Create(); | ||
var site = await jinagaClient.Fact(new Model.Site(new User("Michael"), "michaelperry.net")); | ||
var contentV1 = await jinagaClient.Fact(new Model.Content(site, "index.html")); | ||
var originalHash = jinagaClient.Hash(contentV1); | ||
|
||
var contentCreatedAtForSite = Given<Model.Site>.Match((site, facts) => | ||
from content in facts.OfType<Model.ContentV2>() | ||
where content.site == site | ||
select new | ||
{ | ||
content.createdAt, | ||
hash = jinagaClient.Hash(content), | ||
content | ||
} | ||
); | ||
var contentCreatedAt = await jinagaClient.Query(contentCreatedAtForSite, site); | ||
|
||
var projection = contentCreatedAt.Should().ContainSingle().Subject; | ||
projection.createdAt.Should().BeNull(); | ||
projection.hash.Should().Be(originalHash); | ||
jinagaClient.Hash(projection.content).Should().Be(originalHash); | ||
} | ||
|
||
[Fact] | ||
public async Task CanReadVersionTwoFieldFromVersionTwoFact() | ||
{ | ||
var jinagaClient = JinagaTest.Create(); | ||
var site = await jinagaClient.Fact(new Model.Site(new User("Michael"), "michaelperry.net")); | ||
var contentV2 = await jinagaClient.Fact(new Model.ContentV2(site, new DateTime(2021, 1, 1).ToUniversalTime())); | ||
var originalHash = jinagaClient.Hash(contentV2); | ||
|
||
var contentCreatedAtForSite = Given<Model.Site>.Match((site, facts) => | ||
from content in facts.OfType<Model.ContentV2>() | ||
where content.site == site | ||
select new | ||
{ | ||
content.createdAt, | ||
hash = jinagaClient.Hash(content) | ||
} | ||
); | ||
var contentCreatedAt = await jinagaClient.Query(contentCreatedAtForSite, site); | ||
|
||
contentCreatedAt.Should().ContainSingle().Which.createdAt.Should().Be(new DateTime(2021, 1, 1).ToUniversalTime()); | ||
contentCreatedAt.Should().ContainSingle().Which.hash.Should().Be(originalHash); | ||
} | ||
|
||
[Fact] | ||
public async Task CanReadVersionOneFieldFromVersionTwoFact() | ||
{ | ||
var jinagaClient = JinagaTest.Create(); | ||
var site = await jinagaClient.Fact(new Model.Site(new User("Michael"), "michaelperry.net")); | ||
var contentV2 = await jinagaClient.Fact(new Model.ContentV2(site, new DateTime(2021, 1, 1))); | ||
var originalHash = jinagaClient.Hash(contentV2); | ||
|
||
var contentPathForSite = Given<Model.Site>.Match((site, facts) => | ||
from content in facts.OfType<Model.Content>() | ||
where content.site == site | ||
select new | ||
{ | ||
content.path, | ||
hash = jinagaClient.Hash(content) | ||
} | ||
); | ||
var contentPath = await jinagaClient.Query(contentPathForSite, site); | ||
|
||
var projection = contentPath.Should().ContainSingle().Subject; | ||
projection.path.Should().Be(""); | ||
projection.hash.Should().Be(originalHash); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters