Skip to content
This repository has been archived by the owner on Dec 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #115 from leekelleher/hotfix-0.8.2
Browse files Browse the repository at this point in the history
Fixes DittoConversionHandlerRegistry cache type-cast
  • Loading branch information
mattbrailsford committed Sep 17, 2015
2 parents 4749fb1 + 46f6e87 commit 6801037
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void RegisterHandler<TObjectType, THandlerType>()
}
else
{
Cache.Add(objType, new[] { handlerType });
Cache.Add(objType, new List<Type> { handlerType });
}
}
}
Expand Down
44 changes: 44 additions & 0 deletions tests/Our.Umbraco.Ditto.Tests/MultipleConversionHandlerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace Our.Umbraco.Ditto.Tests
{
using NUnit.Framework;
using Our.Umbraco.Ditto.Tests.Mocks;

[TestFixture]
public class MultipleConversionHandlerTests
{
public class MyModel
{
public string Name { get; set; }
}

public class MyModelConversionHandler : DittoConversionHandler<MyModel>
{
public override void OnConverted()
{
Model.Name = "foo";
}
}

public class MyModelConversionHandler2 : DittoConversionHandler<MyModel>
{
public override void OnConverted()
{
Model.Name += " bar";
}
}

[Test]
public void Multiple_Conversion_Handlers_Registered_Same_Type()
{
Ditto.RegisterConversionHandler<MyModel, MyModelConversionHandler>();
Ditto.RegisterConversionHandler<MyModel, MyModelConversionHandler2>();

var content = new PublishedContentMock();

var model = content.As<MyModel>();

Assert.That(model, Is.Not.Null);
Assert.That(model.Name, Is.EqualTo("foo bar"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@
<Compile Include="ConversionHandlerTests.cs" />
<Compile Include="CustomValueResolverTests.cs" />
<Compile Include="GlobalValueResolverTests.cs" />
<Compile Include="MultipleConversionHandlerTests.cs" />
<Compile Include="PrefixedPropertyTests.cs" />
<Compile Include="ValueResolverContextTests.cs" />
<Compile Include="CurrentContentTests.cs" />
Expand Down

0 comments on commit 6801037

Please sign in to comment.