-
Notifications
You must be signed in to change notification settings - Fork 9
/
FakeTypedModelFactory.cs
35 lines (30 loc) · 1.14 KB
/
FakeTypedModelFactory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.Collections.Generic;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
namespace Umbraco.UnitTesting.Adapter.Support
{
public class FakeModelFactoryResolver : PublishedContentModelFactoryResolver
{
public FakeModelFactoryResolver(IPublishedContentModelFactory factory) : base(factory)
{
}
}
public class FakeContentModelFactory : IPublishedContentModelFactory
{
protected Dictionary<string, Func<IPublishedContent, IPublishedContent>> Factories { get; } = new Dictionary<string, Func<IPublishedContent, IPublishedContent>>();
public void Register(string alias, Func<IPublishedContent, IPublishedContent> factory)
{
if (Factories.ContainsKey(alias))
Factories[alias] = factory;
else
Factories.Add(alias, factory);
}
public IPublishedContent CreateModel(IPublishedContent content)
{
if (Factories.ContainsKey(content.DocumentTypeAlias))
content = Factories[content.DocumentTypeAlias](content);
return content;
}
}
}