Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/DocumentDbTests/Configuration/DocumentMappingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
using System.Reflection;
using JasperFx.CodeGeneration;
using JasperFx.Core.Reflection;
using JasperFx.Events;
using JasperFx.Events.Projections;
using Marten;
using Marten.Events.Projections;
using Marten.Exceptions;
using Marten.Linq.Members;
using Marten.Linq.Parsing;
Expand Down Expand Up @@ -917,6 +920,20 @@ public static void ConfigureMarten(DocumentMapping<ConfiguresItselfSpecifically>

#endregion

[Fact]
public void uses_ConfigureMarten_for_projection_view_type_registered_only_via_projection()
{
using var store = DocumentStore.For(opts =>
{
opts.Connection(ConnectionSource.ConnectionString);
opts.Projections.Add<ProjectionWithConfiguredView>(ProjectionLifecycle.Inline);
});

var mapping = store.Options.Storage.MappingFor(typeof(ProjectionConfiguredView));
mapping.ShouldBeOfType<DocumentMapping<ProjectionConfiguredView>>();
mapping.Indexes.OfType<ComputedIndex>().Any().ShouldBeTrue();
}

#region sample_using_DatabaseSchemaName_attribute

[DatabaseSchemaName("organization")]
Expand All @@ -932,3 +949,30 @@ public class BadDoc
{
public string Name { get; set; }
}

public record SomeProjectionEvent(Guid Id, string ImportantField);

public class ProjectionConfiguredView
{
public string Id { get; set; } = "";
public string ImportantField { get; set; } = "";

public static void ConfigureMarten(DocumentMapping<ProjectionConfiguredView> mapping)
{
mapping.Index(x => x.ImportantField);
}
}

public class ProjectionWithConfiguredView: MultiStreamProjection<ProjectionConfiguredView, string>
{
public ProjectionWithConfiguredView()
{
Identity<IEvent<SomeProjectionEvent>>(e => e.Data.Id.ToString());
}

public ProjectionConfiguredView Apply(SomeProjectionEvent @event, ProjectionConfiguredView current)
{
current.ImportantField = @event.ImportantField;
return current;
}
}
4 changes: 3 additions & 1 deletion src/Marten/Storage/StorageFeatures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ internal DocumentMapping Build(Type type, StoreOptions options)
}

_buildingList.Value.Remove(type);
var m = new DocumentMapping(type, options);
var fallbackBuilder = typeof(DocumentMappingBuilder<>)
.CloseAndBuildAs<IDocumentMappingBuilder>(type);
var m = fallbackBuilder.Build(options);
_options.applyPostPolicies(m);
return m;
}
Expand Down
Loading