Skip to content

Commit

Permalink
Merge branch 'main' into feat/rework-projections
Browse files Browse the repository at this point in the history
  • Loading branch information
the-avid-engineer committed Sep 17, 2023
2 parents 114d481 + 1f686b7 commit ed838e0
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Pack Projects into Nuget Packages
run: dotnet pack EntityDb.sln --no-restore -c Release /p:Version='${{ needs.milestone.outputs.version }}-beta.${{ github.event.number }}.${{ github.run_number }}.${{ github.run_attempt }}'
- name: Publish to Beta
run: dotnet nuget push ./**/*.nupkg -s ${{ secrets.NUGET_SOURCE }} -k ${{ secrets.NUGET_API_KEY }}
run: dotnet nuget push ./**/*.nupkg -s ${{ vars.NUGET_SOURCE }} -k ${{ secrets.NUGET_API_KEY }}
- name: Packages & Symbols Artifact
uses: actions/upload-artifact@v3.1.1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
- name: Pack Projects into Nuget Packages
run: dotnet pack EntityDb.sln --no-restore -c Release /p:Version=${{ needs.tag.outputs.version }}
- name: Publish to Stable
run: dotnet nuget push ./**/*.nupkg -s ${{ secrets.NUGET_SOURCE }} -k ${{ secrets.NUGET_API_KEY }}
run: dotnet nuget push ./**/*.nupkg -s ${{ vars.NUGET_SOURCE }} -k ${{ secrets.NUGET_API_KEY }}
- name: Packages & Symbols Artifact
uses: actions/upload-artifact@v3.1.1
with:
Expand Down
20 changes: 19 additions & 1 deletion src/EntityDb.Common/TypeResolvers/DefaultPartialTypeResolver.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
using EntityDb.Common.Envelopes;
using Microsoft.Extensions.Options;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;

namespace EntityDb.Common.TypeResolvers;

internal class DefaultPartialTypeResolver : IPartialTypeResolver
{
private readonly IOptions<DefaultPartialTypeResolverOptions> _options;

public DefaultPartialTypeResolver(IOptions<DefaultPartialTypeResolverOptions> options)
{
_options = options;
}

private Assembly AssemblyResolver(AssemblyName assemblyName)
{
if (_options.Value.IgnoreVersion)
{
assemblyName.Version = null;
}

return Assembly.Load(assemblyName);
}

public bool TryResolveType(EnvelopeHeaders envelopeHeaders, [NotNullWhen(true)] out Type? resolvedType)
{
if (EnvelopeHelper.NotThisPlatform(envelopeHeaders) ||
Expand All @@ -19,7 +37,7 @@ public bool TryResolveType(EnvelopeHeaders envelopeHeaders, [NotNullWhen(true)]
resolvedType = Type.GetType
(
Assembly.CreateQualifiedName(assemblyFullName, typeFullName),
Assembly.Load,
AssemblyResolver,
(assembly, typeName, ignoreCase) => assembly!.GetType(typeName, true, ignoreCase),
true,
false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace EntityDb.Common.TypeResolvers;

/// <summary>
/// Options for the default partial type resolver
/// </summary>
public class DefaultPartialTypeResolverOptions
{
/// <summary>
/// If you version your assemblies, you may want to ignore the
/// version of the assembly for type resolving purposes.
/// </summary>
public bool IgnoreVersion { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.10" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,30 @@ public VersionNumber GetVersionNumber()

public OneToOneProjection Reduce(ISource source)
{
if (source is ITransaction transaction)
if (source is not ITransaction transaction)
{
var projection = this with
{
LastTransactionAt = transaction.TimeStamp,
};
throw new NotSupportedException();
}

foreach (var command in transaction.Commands)
{
if (command.Data is not IReducer<OneToOneProjection> reducer)
{
continue;
}
var projection = this with
{
LastTransactionAt = transaction.TimeStamp,
};

projection = reducer.Reduce(projection) with
{
VersionNumber = command.EntityVersionNumber,
};
foreach (var command in transaction.Commands)
{
if (command.Data is not IReducer<OneToOneProjection> reducer)
{
continue;
}

return projection;
projection = reducer.Reduce(projection) with
{
VersionNumber = command.EntityVersionNumber,
};
}

throw new NotSupportedException();
return projection;
}

public bool ShouldRecord()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using EntityDb.Common.Envelopes;
using EntityDb.Common.TypeResolvers;
using Microsoft.Extensions.Options;
using Moq;
using Shouldly;
using Xunit;

Expand All @@ -14,7 +16,13 @@ public void GivenEmptyHeaders_WhenLoadingType_ThenReturnNull()

var headers = new EnvelopeHeaders(new Dictionary<string, string>());

var typeResolver = new DefaultPartialTypeResolver();
var optionsMock = new Mock<IOptions<DefaultPartialTypeResolverOptions>>();

optionsMock
.SetupGet(x => x.Value)
.Returns(new DefaultPartialTypeResolverOptions());

var typeResolver = new DefaultPartialTypeResolver(optionsMock.Object);

// ACT

Expand All @@ -37,7 +45,13 @@ public void GivenFullNames_WhenLoadingType_ThenReturnType()

var headers = EnvelopeHelper.GetEnvelopeHeaders(expectedType, true, false);

var typeResolver = new DefaultPartialTypeResolver();
var optionsMock = new Mock<IOptions<DefaultPartialTypeResolverOptions>>();

optionsMock
.SetupGet(x => x.Value)
.Returns(new DefaultPartialTypeResolverOptions());

var typeResolver = new DefaultPartialTypeResolver(optionsMock.Object);

// ACT

Expand All @@ -56,7 +70,13 @@ public void GivenMemberInfoName_WhenLoadingType_ThenReturnNull()

var headers = EnvelopeHelper.GetEnvelopeHeaders(typeof(object), false);

var typeResolver = new DefaultPartialTypeResolver();
var optionsMock = new Mock<IOptions<DefaultPartialTypeResolverOptions>>();

optionsMock
.SetupGet(x => x.Value)
.Returns(new DefaultPartialTypeResolverOptions());

var typeResolver = new DefaultPartialTypeResolver(optionsMock.Object);

// ACT

Expand All @@ -73,7 +93,13 @@ public void GivenNoTypeInformation_WhenLoadingType_ThenReturnNull()
{
// ARRANGE

var typeResolver = new DefaultPartialTypeResolver();
var optionsMock = new Mock<IOptions<DefaultPartialTypeResolverOptions>>();

optionsMock
.SetupGet(x => x.Value)
.Returns(new DefaultPartialTypeResolverOptions());

var typeResolver = new DefaultPartialTypeResolver(optionsMock.Object);

var envelopeHeaders = new EnvelopeHeaders(new Dictionary<string, string>
{
Expand All @@ -95,7 +121,13 @@ public void GivenGarbageTypeInformation_WhenLoadingType_ThenThrow()
{
// ARRANGE

var typeResolver = new DefaultPartialTypeResolver();
var optionsMock = new Mock<IOptions<DefaultPartialTypeResolverOptions>>();

optionsMock
.SetupGet(x => x.Value)
.Returns(new DefaultPartialTypeResolverOptions());

var typeResolver = new DefaultPartialTypeResolver(optionsMock.Object);

var envelopeHeaders = new EnvelopeHeaders(new Dictionary<string, string>
{
Expand Down

0 comments on commit ed838e0

Please sign in to comment.