Skip to content
Open
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
Run setup method on resolved data mapper
  • Loading branch information
Søren Kruse committed May 29, 2019
commit 9df6316564e897f9ea1508e269a5ec7da8454d99
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -65,8 +65,8 @@ public override void Execute(DataMapperResolverArgs args)
"Specified data mapper {0} cannot handle this property. {1}".Formatted(mapperType.FullName, args.PropertyConfiguration));
}

args.Result= mapper;
return;
mapper.Setup(args);
args.Result = mapper;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -78,6 +78,26 @@ public void Execute_DataMapperAttributeLoadedFromMapperCollection_SetsResultToSp
Assert.AreEqual(mapper, args.Result);
}

[Test]
public void Execute_DataMapperAttribute_InvokesSetupMethod()
{
//Assign
var task = new DataMapperAttributeResolverTask();
var configuration = Substitute.For<AbstractPropertyConfiguration>();
configuration.PropertyInfo = typeof(StubClass).GetProperty("StubMapperProperty");

var args = new DataMapperResolverArgs(null, configuration);
args.DataMappers = Enumerable.Empty<AbstractDataMapper>();

//Act
task.Execute(args);

//Assert
var mapper = args.Result as StubMapper;
Assert.IsNotNull(mapper);
Assert.IsTrue(mapper.SetupInvoked);
}

public class StubClass
{
[DataMapper(typeof(StubMapper))]
Expand All @@ -100,6 +120,8 @@ public class StubMapper : AbstractDataMapper
{
public AbstractDataMappingContext MappingContext { get; set; }

public bool SetupInvoked { get; private set; }

public override void MapToCms(AbstractDataMappingContext mappingContext)
{
throw new NotImplementedException();
Expand All @@ -114,6 +136,12 @@ public override bool CanHandle(AbstractPropertyConfiguration configuration, Cont
{
return true;
}

public override void Setup(DataMapperResolverArgs args)
{
base.Setup(args);
SetupInvoked = true;
}
}

public class StubMapperCannotHandle : StubMapper
Expand Down