ResolveAll(Type serviceType) {
49 | return this.container.LocateAll(serviceType);
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/DependencyInjection/Adapters/HaveBoxAdapter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using HaveBox;
6 | using FeatureTests.On.DependencyInjection.Adapters.Interface;
7 |
8 | namespace FeatureTests.On.DependencyInjection.Adapters {
9 | public class HaveBoxAdapter : ContainerAdapterBase {
10 | private readonly Container container = new Container();
11 |
12 | public override Assembly Assembly {
13 | get { return typeof(Container).Assembly; }
14 | }
15 |
16 | public override void RegisterSingleton(Type serviceType, Type implementationType) {
17 | this.container.Configure(r => r.For(serviceType).Use(implementationType).AsSingleton());
18 | }
19 |
20 | public override void RegisterTransient(Type serviceType, Type implementationType) {
21 | this.container.Configure(r => r.For(serviceType).Use(implementationType));
22 | }
23 |
24 | public override void RegisterPerWebRequest(Type serviceType, Type implementationType) {
25 | throw PerWebRequestMayNotBePossible();
26 | }
27 |
28 | public override void RegisterInstance(Type serviceType, object instance) {
29 | this.container.Configure(r => r.For(serviceType).Use(() => instance));
30 | }
31 |
32 | public override object Resolve(Type serviceType) {
33 | return this.container.GetInstance(serviceType);
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/DependencyInjection/Adapters/IfInjectorAdapter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using IfInjector;
6 | using FeatureTests.Shared.GenericApiSupport;
7 | using FeatureTests.Shared.GenericApiSupport.GenericPlaceholders;
8 | using FeatureTests.On.DependencyInjection.Adapters.Interface;
9 |
10 | namespace FeatureTests.On.DependencyInjection.Adapters {
11 | public class IfInjectorAdapter : ContainerAdapterBase {
12 | private readonly Injector injector = new Injector();
13 |
14 | public override Assembly Assembly {
15 | get { return typeof(Injector).Assembly; }
16 | }
17 |
18 | public override void RegisterSingleton(Type serviceType, Type implementationType) {
19 | GenericHelper.RewriteAndInvoke(
20 | () => this.injector.Register(Binding.For>().To>().AsSingleton(true)),
21 | serviceType, implementationType
22 | );
23 | }
24 |
25 | public override void RegisterTransient(Type serviceType, Type implementationType) {
26 | GenericHelper.RewriteAndInvoke(
27 | () => this.injector.Register(Binding.For>().To>()),
28 | serviceType, implementationType
29 | );
30 | }
31 |
32 | public override void RegisterPerWebRequest(Type serviceType, Type implementationType) {
33 | throw PerWebRequestMayNotBeProvided();
34 | }
35 |
36 | public override void RegisterInstance(Type serviceType, object instance) {
37 | GenericHelper.RewriteAndInvoke(
38 | () => this.injector.Register(Binding.For().SetFactory(() => (X1)instance).AsSingleton(true)),
39 | serviceType
40 | );
41 | }
42 |
43 | public override object Resolve(Type serviceType) {
44 | return this.injector.Resolve(serviceType);
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/DependencyInjection/Adapters/Interface/ContainerAdapterBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using FeatureTests.On.DependencyInjection.Adapters.WebRequestSupport;
6 | using FeatureTests.Shared;
7 |
8 | namespace FeatureTests.On.DependencyInjection.Adapters.Interface {
9 | public abstract class ContainerAdapterBase : LibraryAdapterBase, IContainerAdapter {
10 | public abstract void RegisterTransient(Type serviceType, Type implementationType);
11 | public abstract void RegisterSingleton(Type serviceType, Type implementationType);
12 | public abstract void RegisterPerWebRequest(Type serviceType, Type implementationType);
13 | public abstract void RegisterInstance(Type serviceType, object instance);
14 |
15 | public virtual void BeforeAllWebRequests(WebRequestTestHelper helper) { }
16 | public virtual void AfterBeginWebRequest() {}
17 | public virtual void BeforeEndWebRequest() {}
18 |
19 | public abstract object Resolve(Type serviceType);
20 |
21 | public virtual IEnumerable ResolveAll(Type serviceType) {
22 | var enumerableType = typeof(IEnumerable<>).MakeGenericType(serviceType);
23 | return ((IEnumerable)this.Resolve(enumerableType)).Cast();
24 | }
25 |
26 | public virtual bool CrashesOnRecursion {
27 | get { return false; }
28 | }
29 |
30 | public virtual bool CrashesOnListRecursion {
31 | get { return this.CrashesOnRecursion; }
32 | }
33 |
34 | protected Exception PerWebRequestMayNotBeProvided() {
35 | return new NotSupportedException("I am not sure if " + Name + " provides PerRequest lifetime out of the box.");
36 | }
37 |
38 | protected Exception PerWebRequestMayNotBeProvidedButPerThreadIs() {
39 | return new NotSupportedException(
40 | PerWebRequestMayNotBeProvided().Message + Environment.NewLine +
41 | "It does provide PerThread, but a web request is not guaranteed to stay in one thread."
42 | );
43 | }
44 |
45 | protected Exception PerWebRequestMayNotBePossible() {
46 | return new NotSupportedException("I am not sure if " + Name + " can support PerRequest lifetime.");
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/DependencyInjection/Adapters/Interface/ContainerAdapterExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace FeatureTests.On.DependencyInjection.Adapters.Interface {
6 | public static class ContainerAdapterExtensions {
7 | public static void RegisterType(this IContainerAdapter container) {
8 | container.RegisterTransient();
9 | }
10 |
11 | public static void RegisterType(this IContainerAdapter container)
12 | where TImplementation : TService
13 | {
14 | container.RegisterTransient();
15 | }
16 |
17 | public static void RegisterSingleton(this IContainerAdapter container) {
18 | container.RegisterSingleton();
19 | }
20 |
21 | public static void RegisterSingleton(this IContainerAdapter container)
22 | where TImplementation : TService
23 | {
24 | container.RegisterSingleton(typeof(TService), typeof(TImplementation));
25 | }
26 |
27 | public static void RegisterTransient(this IContainerAdapter container) {
28 | container.RegisterSingleton();
29 | }
30 |
31 | public static void RegisterTransient(this IContainerAdapter container)
32 | where TImplementation : TService
33 | {
34 | container.RegisterTransient(typeof(TService), typeof(TImplementation));
35 | }
36 |
37 | public static void RegisterPerWebRequest(this IContainerAdapter container) {
38 | container.RegisterPerWebRequest();
39 | }
40 |
41 | public static void RegisterPerWebRequest(this IContainerAdapter container)
42 | where TImplementation : TService
43 | {
44 | container.RegisterPerWebRequest(typeof(TService), typeof(TImplementation));
45 | }
46 |
47 | public static void RegisterInstance(this IContainerAdapter container, TService instance) {
48 | container.RegisterInstance(typeof(TService), instance);
49 | }
50 |
51 | public static void RegisterInstance(this IContainerAdapter container, object instance) {
52 | container.RegisterInstance(instance.GetType(), instance);
53 | }
54 |
55 | public static TService Resolve(this IContainerAdapter container) {
56 | return (TService)container.Resolve(typeof(TService));
57 | }
58 |
59 | public static IEnumerable ResolveAll(this IContainerAdapter container) {
60 | return container.ResolveAll(typeof(TService)).Cast();
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/DependencyInjection/Adapters/Interface/IContainerAdapter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using FeatureTests.On.DependencyInjection.Adapters.WebRequestSupport;
5 | using FeatureTests.Shared;
6 |
7 | namespace FeatureTests.On.DependencyInjection.Adapters.Interface {
8 | public interface IContainerAdapter : ILibrary {
9 | void RegisterSingleton(Type serviceType, Type implementationType);
10 | void RegisterTransient(Type serviceType, Type implementationType);
11 |
12 | // it is weird to have a special case for this one, as it is normally handled
13 | // by some kind of general subcontainer/scope support -- but for widest reach
14 | // I want to start with the most common use case
15 | void RegisterPerWebRequest(Type serviceType, Type implementationType);
16 |
17 | void RegisterInstance(Type serviceType, object instance);
18 |
19 | void BeforeAllWebRequests(WebRequestTestHelper helper);
20 | void AfterBeginWebRequest();
21 | void BeforeEndWebRequest();
22 |
23 | object Resolve(Type serviceType);
24 | IEnumerable ResolveAll(Type serviceType);
25 |
26 | ///
27 | /// This test was run only once because there is no way to recover from StackOverflowException.
28 | ///
29 | bool CrashesOnRecursion { get; }
30 |
31 | ///
32 | /// This test was run only once because there is no way to recover from StackOverflowException.
33 | ///
34 | bool CrashesOnListRecursion { get; }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/DependencyInjection/Adapters/LightCoreAdapter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using LightCore;
6 | using LightCore.Lifecycle;
7 | using FeatureTests.Shared.GenericApiSupport;
8 | using FeatureTests.Shared.GenericApiSupport.GenericPlaceholders;
9 | using FeatureTests.On.DependencyInjection.Adapters.Interface;
10 |
11 | namespace FeatureTests.On.DependencyInjection.Adapters {
12 | public class LightCoreAdapter : ContainerAdapterBase {
13 | private IContainerBuilder builder = new ContainerBuilder();
14 | private IContainer container;
15 |
16 | public override Assembly Assembly {
17 | get { return typeof(IContainer).Assembly; }
18 | }
19 |
20 | public override void RegisterSingleton(Type serviceType, Type implementationType) {
21 | this.builder.Register(serviceType, implementationType).ControlledBy();
22 | }
23 |
24 | public override void RegisterTransient(Type serviceType, Type implementationType) {
25 | this.builder.Register(serviceType, implementationType).ControlledBy();
26 | }
27 |
28 | public override void RegisterPerWebRequest(Type serviceType, Type implementationType) {
29 | throw PerWebRequestMayNotBeProvidedButPerThreadIs();
30 | }
31 |
32 | public override void RegisterInstance(Type serviceType, object instance) {
33 | GenericHelper.RewriteAndInvoke(() => this.builder.Register((X1)instance), serviceType);
34 | }
35 |
36 | public override object Resolve(Type serviceType) {
37 | this.FreezeContainer();
38 | return this.container.Resolve(serviceType);
39 | }
40 |
41 | private void FreezeContainer() {
42 | if (this.container != null)
43 | return;
44 |
45 | this.container = this.builder.Build();
46 | this.builder = null; // simple way to prevent accidental reuse of adapter
47 | }
48 |
49 | public override bool CrashesOnRecursion {
50 | get { return true; }
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/DependencyInjection/Adapters/LightInjectAdapter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Collections.Generic;
4 | using LightInject;
5 | using FeatureTests.On.DependencyInjection.Adapters.Interface;
6 |
7 | namespace FeatureTests.On.DependencyInjection.Adapters {
8 | public class LightInjectAdapter : ContainerAdapterBase {
9 | private readonly IServiceContainer container = new ServiceContainer();
10 | private Scope webRequestScope;
11 |
12 | public override Assembly Assembly {
13 | get { return typeof(IServiceContainer).Assembly; }
14 | }
15 |
16 | public override void RegisterSingleton(Type serviceType, Type implementationType) {
17 | container.Register(serviceType, implementationType, new PerContainerLifetime());
18 | }
19 |
20 | public override void RegisterTransient(Type serviceType, Type implementationType) {
21 | container.Register(serviceType, implementationType, implementationType.Name);
22 | }
23 |
24 | public override void RegisterPerWebRequest(Type serviceType, Type implementationType) {
25 | container.Register(serviceType, implementationType, new PerScopeLifetime());
26 | }
27 |
28 | public override void RegisterInstance(Type serviceType, object instance) {
29 | container.RegisterInstance(serviceType, instance);
30 | }
31 |
32 | public override void AfterBeginWebRequest() {
33 | this.webRequestScope = container.BeginScope();
34 | }
35 |
36 | public override void BeforeEndWebRequest() {
37 | this.webRequestScope.Dispose();
38 | }
39 |
40 | public override object Resolve(Type serviceType) {
41 | return container.GetInstance(serviceType);
42 | }
43 |
44 | public override IEnumerable ResolveAll(Type serviceType) {
45 | return container.GetAllInstances(serviceType);
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/DependencyInjection/Adapters/LinFuAdapter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using LinFu.IoC;
6 | using LinFu.IoC.Configuration;
7 | using LinFu.IoC.Interfaces;
8 | using FeatureTests.On.DependencyInjection.Adapters.Interface;
9 |
10 | namespace FeatureTests.On.DependencyInjection.Adapters {
11 | // thanks a lot to Philip Laureano for this adapter
12 | public class LinFuAdapter : ContainerAdapterBase {
13 | private readonly IServiceContainer container;
14 |
15 | public LinFuAdapter() {
16 | this.container = new ServiceContainer();
17 | this.container.LoadFrom(AppDomain.CurrentDomain.BaseDirectory, "LinFu*.dll");
18 | }
19 |
20 | public override Assembly Assembly {
21 | get { return typeof(IServiceContainer).Assembly; }
22 | }
23 |
24 | public override void RegisterSingleton(Type serviceType, Type implementationType) {
25 | this.AddService(serviceType, implementationType, LifecycleType.Singleton);
26 | }
27 |
28 | public override void RegisterTransient(Type serviceType, Type implementationType) {
29 | this.AddService(serviceType, implementationType, LifecycleType.OncePerRequest);
30 | }
31 |
32 | public override void RegisterPerWebRequest(Type serviceType, Type implementationType) {
33 | throw PerWebRequestMayNotBeProvidedButPerThreadIs();
34 | }
35 |
36 | private void AddService(Type serviceType, Type implementationType, LifecycleType lifecycle) {
37 | this.container.AddService(serviceType, implementationType, lifecycle);
38 | }
39 |
40 | public override void RegisterInstance(Type serviceType, object instance) {
41 | this.container.AddService(serviceType, instance);
42 | }
43 |
44 | public override object Resolve(Type serviceType) {
45 | return this.container.GetService(serviceType);
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/DependencyInjection/Adapters/MefAdapter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel.Composition;
4 | using System.ComponentModel.Composition.Hosting;
5 | using System.ComponentModel.Composition.Registration;
6 | using System.Linq;
7 | using System.Reflection;
8 | using FeatureTests.Shared.GenericApiSupport;
9 | using FeatureTests.Shared.GenericApiSupport.GenericPlaceholders;
10 | using FeatureTests.On.DependencyInjection.Adapters.Interface;
11 |
12 | namespace FeatureTests.On.DependencyInjection.Adapters {
13 | public class MefAdapter : ContainerAdapterBase {
14 | private readonly CompositionContainer container;
15 | private readonly AggregateCatalog catalog = new AggregateCatalog();
16 |
17 | public MefAdapter() {
18 | this.container = new CompositionContainer(this.catalog);
19 | }
20 |
21 | public override string Name {
22 | get { return "MEF"; }
23 | }
24 |
25 | public override Assembly Assembly {
26 | get { return typeof(RegistrationBuilder).Assembly; }
27 | }
28 |
29 | public override string PackageId {
30 | get { return null; }
31 | }
32 |
33 | public override void RegisterTransient(Type serviceType, Type implementationType) {
34 | var builder = new RegistrationBuilder();
35 | builder.ForType(implementationType)
36 | .Export(c => c.AsContractType(serviceType))
37 | .SetCreationPolicy(CreationPolicy.NonShared);
38 |
39 | this.catalog.Catalogs.Add(new TypeCatalog(new[] { implementationType }, builder));
40 | }
41 |
42 | public override void RegisterSingleton(Type serviceType, Type implementationType) {
43 | var builder = new RegistrationBuilder();
44 | builder.ForType(implementationType)
45 | .Export(c => c.AsContractType(serviceType))
46 | .SetCreationPolicy(CreationPolicy.Shared);
47 |
48 | this.catalog.Catalogs.Add(new TypeCatalog(new[] { implementationType }, builder));
49 | }
50 |
51 | public override void RegisterPerWebRequest(Type serviceType, Type implementationType) {
52 | throw PerWebRequestMayNotBeProvided();
53 | }
54 |
55 | public override void RegisterInstance(Type serviceType, object instance) {
56 | GenericHelper.RewriteAndInvoke(() => this.container.ComposeExportedValue((X1)instance), serviceType);
57 | }
58 |
59 | public override object Resolve(Type serviceType) {
60 | return GenericHelper.RewriteAndInvoke(() => this.container.GetExportedValue(), serviceType);
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/DependencyInjection/Adapters/MicroSliverAdapter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using FeatureTests.On.DependencyInjection.Adapters.WebRequestSupport;
6 | using FeatureTests.Shared.GenericApiSupport.GenericPlaceholders;
7 | using MicroSliver;
8 | using FeatureTests.Shared.GenericApiSupport;
9 | using FeatureTests.On.DependencyInjection.Adapters.Interface;
10 |
11 | namespace FeatureTests.On.DependencyInjection.Adapters {
12 | public class MicroSliverAdapter : ContainerAdapterBase {
13 | private readonly IoC ioc = new IoC();
14 |
15 | #region DelegateCreator
16 |
17 | private class DelegateCreator : ICreator {
18 | private readonly Func create;
19 |
20 | public DelegateCreator(Func create) {
21 | this.create = create;
22 | }
23 |
24 | public object Create() {
25 | return this.create();
26 | }
27 | }
28 |
29 | #endregion
30 |
31 | public override Assembly Assembly {
32 | get { return typeof(IoC).Assembly; }
33 | }
34 |
35 | public override void RegisterSingleton(Type serviceType, Type implementationType) {
36 | GenericHelper.RewriteAndInvoke(
37 | () => this.ioc.Map, C>().ToSingletonScope(),
38 | serviceType, implementationType
39 | );
40 | }
41 |
42 | public override void RegisterTransient(Type serviceType, Type implementationType) {
43 | GenericHelper.RewriteAndInvoke(
44 | () => this.ioc.Map, C>().ToInstanceScope(),
45 | serviceType, implementationType
46 | );
47 | }
48 |
49 | public override void RegisterPerWebRequest(Type serviceType, Type implementationType) {
50 | GenericHelper.RewriteAndInvoke(
51 | () => this.ioc.Map, C>().ToRequestScope(),
52 | serviceType, implementationType
53 | );
54 | }
55 |
56 | public override void RegisterInstance(Type serviceType, object instance) {
57 | GenericHelper.RewriteAndInvoke(
58 | () => this.ioc.Map(new DelegateCreator(() => instance)),
59 | serviceType
60 | );
61 | }
62 |
63 | public override void BeforeAllWebRequests(WebRequestTestHelper helper) {
64 | helper.RegisterModule();
65 | }
66 |
67 | public override object Resolve(Type serviceType) {
68 | return this.ioc.GetByType(serviceType);
69 | }
70 |
71 | public override bool CrashesOnRecursion {
72 | get { return true; }
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/DependencyInjection/Adapters/MugenAdapter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using Microsoft.Practices.ServiceLocation;
6 | using MugenInjection;
7 | using FeatureTests.On.DependencyInjection.Adapters.Interface;
8 | using MugenInjection.Interface;
9 |
10 | namespace FeatureTests.On.DependencyInjection.Adapters {
11 | public class MugenAdapter : ContainerAdapterBase {
12 | private readonly MugenInjector injector = new MugenInjector();
13 | private IInjector webRequestInjector;
14 |
15 | public override Assembly Assembly {
16 | get { return typeof(MugenInjector).Assembly; }
17 | }
18 |
19 | public override string PackageId {
20 | get { return "MugenInjection"; }
21 | }
22 |
23 | public override void RegisterSingleton(Type serviceType, Type implementationType) {
24 | this.injector.Bind(serviceType).To(implementationType).InSingletonScope();
25 | }
26 |
27 | public override void RegisterTransient(Type serviceType, Type implementationType) {
28 | this.injector.Bind(serviceType).To(implementationType).InTransientScope();
29 | }
30 |
31 | public override void RegisterPerWebRequest(Type serviceType, Type implementationType) {
32 | this.injector.Bind(serviceType).To(implementationType).InUnitOfWorkScope();
33 | }
34 |
35 | public override void RegisterInstance(Type serviceType, object instance) {
36 | this.injector.Bind(serviceType).ToConstant(instance);
37 | }
38 |
39 | public override void AfterBeginWebRequest() {
40 | this.webRequestInjector = this.injector.CreateChild();
41 | }
42 |
43 | public override void BeforeEndWebRequest() {
44 | this.webRequestInjector.Dispose();
45 | this.webRequestInjector = null;
46 | }
47 |
48 | public override object Resolve(Type serviceType) {
49 | return (this.webRequestInjector ?? this.injector).Get(serviceType);
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/DependencyInjection/Adapters/MunqAdapter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using FeatureTests.On.DependencyInjection.Adapters.WebRequestSupport;
6 | using Munq;
7 | using FeatureTests.On.DependencyInjection.Adapters.Interface;
8 | using Munq.LifetimeManagers;
9 |
10 | namespace FeatureTests.On.DependencyInjection.Adapters {
11 | public class MunqAdapter : ContainerAdapterBase {
12 | private readonly IocContainer container = new IocContainer();
13 |
14 | public override Assembly Assembly {
15 | get { return typeof(IocContainer).Assembly; }
16 | }
17 |
18 | public override void RegisterSingleton(Type serviceType, Type implementationType) {
19 | this.container.Register(serviceType, implementationType).AsContainerSingleton();
20 | }
21 |
22 | public override void RegisterTransient(Type serviceType, Type implementationType) {
23 | this.container.Register(serviceType, implementationType).AsAlwaysNew();
24 | }
25 |
26 | public override void RegisterInstance(Type serviceType, object instance) {
27 | this.container.RegisterInstance(serviceType, instance);
28 | }
29 |
30 | public override void RegisterPerWebRequest(Type serviceType, Type implementationType) {
31 | this.container.Register(serviceType, implementationType).AsRequestSingleton();
32 | }
33 |
34 | public override void BeforeAllWebRequests(WebRequestTestHelper helper) {
35 | helper.RegisterModule();
36 | }
37 |
38 | public override object Resolve(Type serviceType) {
39 | return this.container.Resolve(serviceType);
40 | }
41 |
42 | public override bool CrashesOnRecursion {
43 | get { return true; }
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/DependencyInjection/Adapters/NinjectAdapter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using System.Web;
6 | using FeatureTests.On.DependencyInjection.Adapters.WebRequestSupport;
7 | using FeatureTests.Shared;
8 | using Ninject;
9 | using FeatureTests.On.DependencyInjection.Adapters.Interface;
10 | using Ninject.Web.Common;
11 |
12 | namespace FeatureTests.On.DependencyInjection.Adapters {
13 | public class NinjectAdapter : ContainerAdapterBase {
14 | private readonly IKernel kernel;
15 |
16 | public NinjectAdapter() {
17 | this.kernel = new StandardKernel();
18 | }
19 |
20 | public override Assembly Assembly {
21 | get { return typeof(IKernel).Assembly; }
22 | }
23 |
24 | public override void RegisterSingleton(Type serviceType, Type implementationType) {
25 | this.kernel.Bind(serviceType).To(implementationType).InSingletonScope();
26 | }
27 |
28 | public override void RegisterTransient(Type serviceType, Type implementationType) {
29 | this.kernel.Bind(serviceType).To(implementationType).InTransientScope();
30 | }
31 |
32 | public override void RegisterPerWebRequest(Type serviceType, Type implementationType) {
33 | this.kernel.Bind(serviceType).To(implementationType).InRequestScope();
34 | }
35 |
36 | public override void RegisterInstance(Type serviceType, object instance) {
37 | this.kernel.Bind(serviceType).ToConstant(instance);
38 | }
39 |
40 | public override void BeforeAllWebRequests(WebRequestTestHelper helper) {
41 | //this.kernel.Bind>()
42 | // .ToConstant>(() => this.kernel);
43 |
44 | //new Bootstrapper().Initialize(() => this.kernel);
45 | //WebRequestTestHelper.RegisterModule();
46 | throw new SkipException("It is obvious Ninject supports this, but I can't figure this out in a reasonable time.");
47 | }
48 |
49 | public override object Resolve(Type serviceType) {
50 | return this.kernel.Get(serviceType);
51 | }
52 |
53 | public override IEnumerable ResolveAll(Type serviceType) {
54 | return this.kernel.GetAll(serviceType);
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/DependencyInjection/Adapters/SimpleInjectorAdapter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Reflection;
4 | using FeatureTests.On.DependencyInjection.Adapters.WebRequestSupport;
5 | using SimpleInjector;
6 | using SimpleInjector.Advanced;
7 | using SimpleInjector.Extensions;
8 | using FeatureTests.On.DependencyInjection.Adapters.Interface;
9 | using SimpleInjector.Integration.Web;
10 |
11 | namespace FeatureTests.On.DependencyInjection.Adapters {
12 | public class SimpleInjectorAdapter : ContainerAdapterBase {
13 | private readonly Container container = new Container();
14 |
15 | public override string Name {
16 | get { return "Simple Injector"; }
17 | }
18 |
19 | public override Assembly Assembly {
20 | get { return typeof(Container).Assembly; }
21 | }
22 |
23 | public override void RegisterSingleton(Type serviceType, Type implementationType) {
24 | this.Register(serviceType, implementationType, Lifestyle.Singleton);
25 | }
26 |
27 | public override void RegisterTransient(Type serviceType, Type implementationType) {
28 | this.Register(serviceType, implementationType, Lifestyle.Transient);
29 | }
30 |
31 | public override void RegisterPerWebRequest(Type serviceType, Type implementationType) {
32 | this.Register(serviceType, implementationType, new WebRequestLifestyle(true));
33 | }
34 |
35 | public override void RegisterInstance(Type serviceType, object instance) {
36 | this.container.RegisterSingleton(serviceType, instance);
37 | }
38 |
39 | public override void BeforeAllWebRequests(WebRequestTestHelper helper) {
40 | helper.RegisterModule();
41 | }
42 |
43 | public override object Resolve(Type serviceType) {
44 | return this.container.GetInstance(serviceType);
45 | }
46 |
47 | public override IEnumerable ResolveAll(Type serviceType) {
48 | return this.container.GetAllInstances(serviceType);
49 | }
50 |
51 | private void Register(Type serviceType, Type implementationType, Lifestyle lifestyle) {
52 | this.container.Register(serviceType, implementationType, lifestyle);
53 |
54 | // Registering collections in Simple Injector is done using the RegisterAll overloads, but
55 | // this forces all elements to be registered at once. For integration scenarios, the
56 | // AppendToCollection extension method can be used. This allows adding elements to a collection
57 | // one by one.
58 | this.container.AppendToCollection(serviceType, implementationType);
59 | }
60 | }
61 | }
--------------------------------------------------------------------------------
/DependencyInjection/Adapters/SpeediocAdapter.Disabled.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using Speedioc;
6 | using Speedioc.Registration;
7 | using Speedioc.Registration.Builders;
8 |
9 | namespace FeatureTests.On.DependencyInjection.Adapters {
10 | //public class SpeediocAdapter : FrameworkAdapterBase {
11 | // private IContainerBuilder builder = DefaultContainerBuilderFactory.GetInstance();
12 | // private IContainer container;
13 |
14 | // public override Assembly FrameworkAssembly {
15 | // get { return typeof(DefaultContainerBuilderFactory).Assembly; }
16 | // }
17 |
18 | // // NOTE: Registration approach below is not the best approach.
19 | // // As far as I understand, the best approach is to inherit Registry.
20 | // // However that would not work for tests.
21 |
22 | // public override void RegisterSingleton(Type serviceType, Type implementationType) {
23 | // var registry = new Registry();
24 | // registry.Register(implementationType).As(serviceType).WithLifetime(Lifetime.Container);
25 | // this.builder.AddRegistry(registry);
26 | // }
27 |
28 | // public override void RegisterTransient(Type serviceType, Type implementationType) {
29 | // var registry = new Registry();
30 | // registry.Register(implementationType).As(serviceType).WithLifetime(Lifetime.Transient);
31 | // this.builder.AddRegistry(registry);
32 | // }
33 |
34 | // public override void RegisterInstance(Type serviceType, object instance) {
35 | // // How do I do that?
36 | // }
37 |
38 | // public override object Resolve(Type serviceType) {
39 | // this.FreezeContainer();
40 | // return this.container.GetInstance(serviceType);
41 | // }
42 |
43 | // private void FreezeContainer() {
44 | // if (this.container != null)
45 | // return;
46 |
47 | // this.container = this.builder.Build();
48 | // this.builder = null; // simple way to prevent accidental reuse of adapter
49 | // }
50 | //}
51 | }
52 |
--------------------------------------------------------------------------------
/DependencyInjection/Adapters/SpringAdapter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using FeatureTests.Shared;
6 | using Spring.Context.Support;
7 | using Spring.Objects.Factory.Config;
8 | using Spring.Objects.Factory.Support;
9 | using FeatureTests.On.DependencyInjection.Adapters.Interface;
10 |
11 | // long names, Java heritage
12 | namespace FeatureTests.On.DependencyInjection.Adapters {
13 | public class SpringAdapter : ContainerAdapterBase {
14 | private readonly GenericApplicationContext context = new GenericApplicationContext();
15 | private readonly IObjectDefinitionFactory factory = new DefaultObjectDefinitionFactory();
16 |
17 | private bool contextRefreshed = false;
18 |
19 | public override Assembly Assembly {
20 | get { return typeof(IObjectDefinitionFactory).Assembly; }
21 | }
22 |
23 | public override string Name {
24 | get { return "Spring.NET"; }
25 | }
26 |
27 | public override void RegisterSingleton(Type serviceType, Type implementationType) {
28 | this.Register(implementationType, serviceType, true);
29 | }
30 |
31 | public override void RegisterTransient(Type serviceType, Type implementationType) {
32 | this.Register(implementationType, serviceType, false);
33 | }
34 |
35 | public override void RegisterPerWebRequest(Type serviceType, Type implementationType) {
36 | throw new SkipException("It seems possible (scope='request' in XML) but I have no clue how to implement it in code.");
37 | }
38 |
39 | public override void RegisterInstance(Type serviceType, object instance) {
40 | var key = string.Format("{0} ({1})", serviceType, instance);
41 | this.context.ObjectFactory.RegisterSingleton(key, instance);
42 | }
43 |
44 | private void Register(Type implementationType, Type serviceType, bool singleton) {
45 | var builder = ObjectDefinitionBuilder.RootObjectDefinition(this.factory, implementationType)
46 | .SetAutowireMode(AutoWiringMode.AutoDetect)
47 | .SetSingleton(singleton);
48 |
49 | var key = string.Format("{0} ({1})", serviceType, implementationType);
50 | this.context.RegisterObjectDefinition(key, builder.ObjectDefinition);
51 | }
52 |
53 | private void EnsureContextRefreshed() {
54 | if (this.contextRefreshed)
55 | return;
56 |
57 | this.context.Refresh();
58 | this.contextRefreshed = true;
59 | }
60 |
61 | public override object Resolve(Type serviceType) {
62 | this.EnsureContextRefreshed();
63 | return this.context.GetObjectsOfType(serviceType).Values.Cast().Single();
64 | }
65 |
66 | public override IEnumerable ResolveAll(Type serviceType) {
67 | this.EnsureContextRefreshed();
68 | return this.context.GetObjectsOfType(serviceType).Values.Cast();
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/DependencyInjection/Adapters/StashboxAdapter.cs:
--------------------------------------------------------------------------------
1 | using FeatureTests.On.DependencyInjection.Adapters.Interface;
2 | using FeatureTests.On.DependencyInjection.Adapters.WebRequestSupport;
3 | using Stashbox;
4 | using Stashbox.Infrastructure;
5 | using Stashbox.Web.Mvc;
6 | using System;
7 | using System.Collections.Generic;
8 | using System.Reflection;
9 |
10 | namespace FeatureTests.On.DependencyInjection.Adapters {
11 | public class StashboxAdapter : ContainerAdapterBase {
12 | private readonly IStashboxContainer container;
13 | private StashboxPerRequestScopeProvider perRequestScope;
14 |
15 | public StashboxAdapter() {
16 | this.container = new StashboxContainer(config => config
17 | .WithCircularDependencyTracking()
18 | .WithDisposableTransientTracking()
19 | .WithMemberInjectionWithoutAnnotation()
20 | .WithOptionalAndDefaultValueInjection()
21 | .WithUnknownTypeResolution()
22 | .WithCircularDependencyWithLazy());
23 |
24 | this.perRequestScope = new StashboxPerRequestScopeProvider(this.container);
25 | }
26 |
27 | public override Assembly Assembly => typeof(StashboxContainer).Assembly;
28 |
29 | public override string PackageId => "Stashbox";
30 |
31 | public override void RegisterInstance(Type serviceType, object instance) =>
32 | this.container.RegisterInstance(serviceType, instance);
33 |
34 | public override void RegisterPerWebRequest(Type serviceType, Type implementationType) =>
35 | this.container.RegisterType(serviceType, implementationType, context => context.WithLifetime(new PerRequestLifetime()));
36 |
37 | public override void RegisterSingleton(Type serviceType, Type implementationType) =>
38 | this.container.RegisterSingleton(serviceType, implementationType);
39 |
40 | public override void RegisterTransient(Type serviceType, Type implementationType) =>
41 | this.container.RegisterType(serviceType, implementationType);
42 |
43 | public override void AfterBeginWebRequest() =>
44 | this.perRequestScope.GetOrCreateScope();
45 |
46 | public override void BeforeAllWebRequests(WebRequestTestHelper helper) =>
47 | helper.RegisterModule();
48 |
49 | public override object Resolve(Type serviceType) => this.container.Resolve(serviceType);
50 |
51 | public override IEnumerable ResolveAll(Type serviceType) => this.container.ResolveAll(serviceType);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/DependencyInjection/Adapters/StructureMapAdapter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using StructureMap;
6 | using StructureMap.Configuration.DSL;
7 | using StructureMap.Configuration.DSL.Expressions;
8 | using StructureMap.Pipeline;
9 | using FeatureTests.On.DependencyInjection.Adapters.Interface;
10 |
11 | namespace FeatureTests.On.DependencyInjection.Adapters {
12 | public class StructureMapAdapter : ContainerAdapterBase {
13 | private Registry initialRegistry = new Registry();
14 | private Container container;
15 |
16 | public override Assembly Assembly {
17 | get { return typeof(Container).Assembly; }
18 | }
19 |
20 | public override void RegisterSingleton(Type serviceType, Type implementationType) {
21 | RegisterInitialOrConfigure(serviceType, new SingletonLifecycle(), r => r.Use(implementationType));
22 | }
23 |
24 | public override void RegisterTransient(Type serviceType, Type implementationType) {
25 | RegisterInitialOrConfigure(serviceType, new TransientLifecycle(), r => r.Use(implementationType));
26 | }
27 |
28 | public override void RegisterPerWebRequest(Type serviceType, Type implementationType) {
29 | throw PerWebRequestMayNotBeProvided();
30 | }
31 |
32 | public override void RegisterInstance(Type serviceType, object instance) {
33 | RegisterInitialOrConfigure(serviceType, new SingletonLifecycle(), r => r.Use(instance));
34 | }
35 |
36 | private void RegisterInitialOrConfigure(Type serviceType, ILifecycle lifecycle, Action use) {
37 | var registry = this.initialRegistry ?? new Registry();
38 | use(registry.For(serviceType).LifecycleIs(lifecycle));
39 |
40 | if (this.container != null)
41 | this.container.Configure(c => c.AddRegistry(registry));
42 | }
43 |
44 | public override object Resolve(Type serviceType) {
45 | this.EnsureContainer();
46 | return this.container.GetInstance(serviceType);
47 | }
48 |
49 | public override IEnumerable ResolveAll(Type serviceType) {
50 | this.EnsureContainer();
51 | return this.container.GetAllInstances(serviceType).Cast();
52 | }
53 |
54 | private void EnsureContainer() {
55 | if (this.container != null)
56 | return;
57 |
58 | this.container = new Container(this.initialRegistry);
59 | this.initialRegistry = null;
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/DependencyInjection/Adapters/TinyIoCAdapter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using FeatureTests.On.DependencyInjection.Adapters.Interface;
6 | using TinyIoC;
7 |
8 | namespace FeatureTests.On.DependencyInjection.Adapters {
9 | public class TinyIoCAdapter : ContainerAdapterBase {
10 | private readonly TinyIoCContainer container = new TinyIoCContainer();
11 |
12 | public override Assembly Assembly {
13 | get { return null; }
14 | }
15 |
16 | public override string PackageId {
17 | get { return "TinyIoC"; }
18 | }
19 |
20 | public override void RegisterSingleton(Type serviceType, Type implementationType) {
21 | this.container.Register(serviceType, implementationType).AsSingleton();
22 | }
23 |
24 | public override void RegisterTransient(Type serviceType, Type implementationType) {
25 | this.container.Register(serviceType, implementationType).AsMultiInstance();
26 | }
27 |
28 | public override void RegisterPerWebRequest(Type serviceType, Type implementationType) {
29 | throw PerWebRequestMayNotBeProvided();
30 | }
31 |
32 | public override void RegisterInstance(Type serviceType, object instance) {
33 | this.container.Register(serviceType, instance);
34 | }
35 |
36 | public override object Resolve(Type serviceType) {
37 | return this.container.Resolve(serviceType);
38 | }
39 |
40 | public override IEnumerable ResolveAll(Type serviceType) {
41 | return this.container.ResolveAll(serviceType);
42 | }
43 |
44 | public override bool CrashesOnRecursion {
45 | get { return true; }
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/DependencyInjection/Adapters/UnityAdapter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using FeatureTests.On.DependencyInjection.Adapters.WebRequestSupport;
6 | using Microsoft.Practices.Unity;
7 | using FeatureTests.On.DependencyInjection.Adapters.Interface;
8 | using Microsoft.Practices.Unity.Mvc;
9 |
10 | namespace FeatureTests.On.DependencyInjection.Adapters {
11 | public class UnityAdapter : ContainerAdapterBase {
12 | private readonly IUnityContainer container = new UnityContainer();
13 |
14 | public override Assembly Assembly {
15 | get { return typeof(IUnityContainer).Assembly; }
16 | }
17 |
18 | public override string PackageId {
19 | get { return "Unity"; }
20 | }
21 |
22 | public override void RegisterSingleton(Type serviceType, Type implementationType) {
23 | this.Register(serviceType, implementationType, () => new ContainerControlledLifetimeManager());
24 | }
25 |
26 | public override void RegisterTransient(Type serviceType, Type implementationType) {
27 | this.Register(serviceType, implementationType, () => new TransientLifetimeManager());
28 | }
29 |
30 | public override void RegisterPerWebRequest(Type serviceType, Type implementationType) {
31 | this.Register(serviceType, implementationType, () => new PerRequestLifetimeManager());
32 | }
33 |
34 | private void Register(Type serviceType, Type implementationType, Func lifetime) {
35 | this.container.RegisterType(serviceType, implementationType, lifetime());
36 |
37 | var name = serviceType.AssemblyQualifiedName + " => " + implementationType.AssemblyQualifiedName;
38 | this.container.RegisterType(serviceType, implementationType, name, lifetime());
39 | }
40 |
41 | public override void RegisterInstance(Type serviceType, object instance) {
42 | this.container.RegisterInstance(serviceType, instance);
43 | this.container.RegisterInstance(serviceType, serviceType.AssemblyQualifiedName + " => " + instance, instance);
44 | }
45 |
46 | public override void BeforeAllWebRequests(WebRequestTestHelper helper) {
47 | helper.RegisterModule();
48 | }
49 |
50 | public override object Resolve(Type serviceType) {
51 | return this.container.Resolve(serviceType);
52 | }
53 |
54 | public override IEnumerable ResolveAll(Type serviceType) {
55 | return this.container.ResolveAll(serviceType);
56 | }
57 |
58 | public override bool CrashesOnRecursion {
59 | get { return true; }
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/DependencyInjection/Adapters/WebRequestSupport/TestHttpApplication.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 | using System.Web;
6 |
7 | namespace FeatureTests.On.DependencyInjection.Adapters.WebRequestSupport {
8 | public class TestHttpApplication : HttpApplication {
9 | public void RaiseEvent(string name) {
10 | var handler = (EventHandler)this.Events[GetEventKey(name)];
11 | if (handler == null)
12 | return;
13 |
14 | handler(this, EventArgs.Empty);
15 | }
16 |
17 | private object GetEventKey(string name) {
18 | var keyField = typeof(HttpApplication).GetField("Event" + name, BindingFlags.Static | BindingFlags.NonPublic);
19 | return keyField.GetValue(null);
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/DependencyInjection/Adapters/WebRequestSupport/WebRequestTestHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Web;
6 | using AshMind.Extensions;
7 | using ReflectionMagic;
8 |
9 | namespace FeatureTests.On.DependencyInjection.Adapters.WebRequestSupport {
10 | public class WebRequestTestHelper : IDisposable {
11 | private readonly ISet modules = new HashSet();
12 | private readonly TestHttpApplication application;
13 |
14 | //public static WebRequestTestHelper Current {
15 | // get { return (WebRequestTestHelper)CallContext.LogicalGetData("WebRequestTestHelper.Current"); }
16 | // private set { CallContext.LogicalSetData("WebRequestTestHelper.Current", value); }
17 | //}
18 |
19 | //public WebRequestTestHelper() {
20 | // if (Current != null)
21 | // throw
22 | //}
23 |
24 | public WebRequestTestHelper() {
25 | this.application = new TestHttpApplication();
26 | }
27 |
28 | public void RegisterModule()
29 | where THttpModule : IHttpModule, new()
30 | {
31 | RegisterModule(new THttpModule());
32 | }
33 |
34 | public void RegisterModule(IHttpModule module) {
35 | module.Init(this.application);
36 | this.modules.Add(module);
37 | }
38 |
39 | public void BeginWebRequest() {
40 | var context = new HttpContext(
41 | new HttpRequest("", "http://only.test", ""),
42 | new HttpResponse(new StringWriter())
43 | ) { ApplicationInstance = this.application };
44 | this.application.AsDynamic()._context = context;
45 |
46 | HttpContext.Current = context;
47 |
48 | this.application.RaiseEvent("BeginRequest");
49 | }
50 |
51 | public void EndWebRequest() {
52 | this.application.RaiseEvent("EndRequest");
53 | HttpContext.Current = null;
54 | }
55 |
56 | public void Dispose() {
57 | HttpContext.Current = null;
58 | modules.ForEach(m => m.Dispose());
59 | modules.Clear();
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/DependencyInjection/Html/AfterAll.html:
--------------------------------------------------------------------------------
1 |
2 | Not tested
3 |
4 |
List of containers I couldn't test, with corresponding reasons.
5 |
6 |
7 |
8 | fFastInjector
9 | Static only: would require an AppDomain to test properly.
10 |
11 | Funq
12 | Not found on NuGet.
13 |
14 | Griffin
15 | Complex API. Please feel free to do a pull request for it.
16 |
17 | Hiro
18 | Complex API.
19 |
20 | Petite
21 | Code-only NuGet package.
22 |
23 | Speedioc
24 | I can't quickly figure out how to register an instance.
25 |
26 | Stiletto
27 | Seems to use attribute-only registration.
28 |
29 |
--------------------------------------------------------------------------------
/DependencyInjection/Html/Options.json:
--------------------------------------------------------------------------------
1 | {
2 | "PageTitle": "Dependency Injection",
3 | "LinkTitle": "Dependency Injection"
4 | }
--------------------------------------------------------------------------------
/DependencyInjection/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | // General Information about an assembly is controlled through the following
5 | // set of attributes. Change these attribute values to modify the information
6 | // associated with an assembly.
7 | [assembly: AssemblyCopyright("Copyright © Andrey Shchekin 2013")]
8 |
9 | // Setting ComVisible to false makes the types in this assembly not visible
10 | // to COM components. If you need to access a type in this assembly from
11 | // COM, set the ComVisible attribute to true on that type.
12 | [assembly: ComVisible(false)]
13 |
14 | // The following GUID is for the ID of the typelib if this project is exposed to COM
15 | [assembly: Guid("f6e292c8-b01e-44c8-ac80-5b8a5e2a9497")]
16 |
17 | // Version information for an assembly consists of the following four values:
18 | //
19 | // Major Version
20 | // Minor Version
21 | // Build Number
22 | // Revision
23 | //
24 | // You can specify all the values or you can default the Build and Revision Numbers
25 | // by using the '*' as shown below:
26 | // [assembly: AssemblyVersion("1.0.*")]
27 | [assembly: AssemblyVersion("1.0.0.0")]
28 | [assembly: AssemblyFileVersion("1.0.0.0")]
29 |
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/DisposableService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace FeatureTests.On.DependencyInjection.TestTypes {
4 | public class DisposableService : IDisposable {
5 | public void Dispose() {
6 | this.Disposed = true;
7 | }
8 |
9 | public bool Disposed { get; private set; }
10 | }
11 | }
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/GenericService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace FeatureTests.On.DependencyInjection.TestTypes {
6 | public class GenericService : IGenericService {
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/GenericServiceWithIService2Constraint.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace FeatureTests.On.DependencyInjection.TestTypes {
6 | public class GenericServiceWithIService2Constraint : IGenericService
7 | where T : IService2
8 | {
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/IGenericService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace FeatureTests.On.DependencyInjection.TestTypes {
6 | public interface IGenericService {
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/IResolvableUnregisteredService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace FeatureTests.On.DependencyInjection.TestTypes {
6 | public interface IResolvableUnregisteredService {
7 | }
8 | }
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/IService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace FeatureTests.On.DependencyInjection.TestTypes {
6 | public interface IService {
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/IService2.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace FeatureTests.On.DependencyInjection.TestTypes {
6 | public interface IService2 {
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/IServiceWithListDependency.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace FeatureTests.On.DependencyInjection.TestTypes {
6 | public interface IServiceWithListDependency
7 | where TServiceList : IEnumerable
8 | {
9 | TServiceList Services { get; }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/IUnregisteredService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace FeatureTests.On.DependencyInjection.TestTypes {
6 | public interface IUnregisteredService {
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/IndependentService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace FeatureTests.On.DependencyInjection.TestTypes {
6 | public class IndependentService : IService {
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/IndependentService2.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace FeatureTests.On.DependencyInjection.TestTypes {
6 | public class IndependentService2 : IService2 {
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/ServiceThatCreatesRecursiveArrayDependency.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace FeatureTests.On.DependencyInjection.TestTypes {
6 | public class ServiceThatCreatesRecursiveArrayDependency : IService {
7 | public ServiceThatCreatesRecursiveArrayDependency(ServiceWithListConstructorDependency dependency) {}
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/ServiceWithDependencyAndOptionalInt32Parameter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace FeatureTests.On.DependencyInjection.TestTypes {
8 | public class ServiceWithDependencyAndOptionalInt32Parameter {
9 | public int Optional { get; private set; }
10 |
11 | public ServiceWithDependencyAndOptionalInt32Parameter(IService service, int optional = 5) {
12 | Optional = optional;
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/ServiceWithDependencyAndOptionalOtherServiceParameter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace FeatureTests.On.DependencyInjection.TestTypes {
6 | public class ServiceWithDependencyAndOptionalOtherServiceParameter {
7 | public IService2 Optional { get; private set; }
8 |
9 | public ServiceWithDependencyAndOptionalOtherServiceParameter(IService service, IService2 optional = null) {
10 | Optional = optional;
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/ServiceWithDependencyOnServiceWithOtherDependency.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace FeatureTests.On.DependencyInjection.TestTypes {
6 | public class ServiceWithDependencyOnServiceWithOtherDependency : IResolvableUnregisteredService {
7 | private readonly ServiceWithSimpleConstructorDependency service;
8 |
9 | public ServiceWithDependencyOnServiceWithOtherDependency(ServiceWithSimpleConstructorDependency service) {
10 | this.service = service;
11 | }
12 |
13 | public ServiceWithSimpleConstructorDependency Service {
14 | get { return this.service; }
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/ServiceWithFuncConstructorDependency.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace FeatureTests.On.DependencyInjection.TestTypes {
6 | public class ServiceWithFuncConstructorDependency {
7 | private readonly Func factory;
8 |
9 | public ServiceWithFuncConstructorDependency(Func factory) {
10 | this.factory = factory;
11 | }
12 |
13 | public Func Factory {
14 | get { return this.factory; }
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/ServiceWithListConstructorDependency.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace FeatureTests.On.DependencyInjection.TestTypes {
6 | public class ServiceWithListConstructorDependency : IServiceWithListDependency
7 | where TServiceList : IEnumerable
8 | {
9 | private readonly TServiceList services;
10 |
11 | public ServiceWithListConstructorDependency(TServiceList services) {
12 | this.services = services;
13 | }
14 |
15 | public TServiceList Services {
16 | get { return this.services; }
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/ServiceWithMultipleConstructors.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace FeatureTests.On.DependencyInjection.TestTypes {
6 | public class ServiceWithMultipleConstructors {
7 | public static class ConstructorNames {
8 | public const string Default = "Default";
9 | public const string MostResolvable = "Most resolvable";
10 | public const string MostDefined = "Most defined";
11 | public const string Unresolvable = "Unresolvable";
12 | }
13 |
14 | private readonly string usedConstructorName;
15 |
16 | public ServiceWithMultipleConstructors() {
17 | this.usedConstructorName = ConstructorNames.Default;
18 | }
19 |
20 | public ServiceWithMultipleConstructors(IService service) {
21 | this.usedConstructorName = ConstructorNames.MostResolvable;
22 | }
23 |
24 | public ServiceWithMultipleConstructors(IUnregisteredService service) {
25 | this.usedConstructorName = ConstructorNames.Unresolvable;
26 | }
27 |
28 | public ServiceWithMultipleConstructors(IService service1, IUnregisteredService service2) {
29 | this.usedConstructorName = ConstructorNames.MostDefined;
30 | }
31 |
32 | public string UsedConstructorName {
33 | get { return this.usedConstructorName; }
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/ServiceWithRecursiveDependency1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace FeatureTests.On.DependencyInjection.TestTypes {
6 | public class ServiceWithRecursiveDependency1 {
7 | public ServiceWithRecursiveDependency1(ServiceWithRecursiveDependency2 dependency) {
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/ServiceWithRecursiveDependency2.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace FeatureTests.On.DependencyInjection.TestTypes {
6 | public class ServiceWithRecursiveDependency2 {
7 | public ServiceWithRecursiveDependency2(ServiceWithRecursiveDependency1 dependency) {
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/ServiceWithRecursiveLazyDependency1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace FeatureTests.On.DependencyInjection.TestTypes {
6 | public class ServiceWithRecursiveLazyDependency1 {
7 | private readonly Lazy dependency;
8 |
9 | public ServiceWithRecursiveLazyDependency1(Lazy dependency) {
10 | this.dependency = dependency;
11 | }
12 |
13 | public ServiceWithRecursiveLazyDependency2 Dependency {
14 | get { return this.dependency.Value; }
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/ServiceWithRecursiveLazyDependency2.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace FeatureTests.On.DependencyInjection.TestTypes {
6 | public class ServiceWithRecursiveLazyDependency2 {
7 | private readonly Lazy dependency;
8 |
9 | public ServiceWithRecursiveLazyDependency2(Lazy dependency) {
10 | this.dependency = dependency;
11 | }
12 |
13 | public ServiceWithRecursiveLazyDependency1 Dependency {
14 | get { return this.dependency.Value; }
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/ServiceWithSimpleConstructorDependency.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace FeatureTests.On.DependencyInjection.TestTypes {
6 | public class ServiceWithSimpleConstructorDependency {
7 | private readonly IService service;
8 |
9 | public ServiceWithSimpleConstructorDependency(IService service) {
10 | this.service = service;
11 | }
12 |
13 | public IService Service {
14 | get { return this.service; }
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/ServiceWithSimplePropertyDependency.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace FeatureTests.On.DependencyInjection.TestTypes {
6 | public class ServiceWithSimplePropertyDependency {
7 | [Microsoft.Practices.Unity.Dependency]
8 | [StructureMap.Attributes.SetterProperty]
9 | [LinFu.IoC.Configuration.Inject]
10 | [Ninject.Inject]
11 | [MugenInjection.Attributes.Inject]
12 | [IfInjector.Inject]
13 | [System.ComponentModel.Composition.Import]
14 | public IService Service { get; set; }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/DependencyInjection/TestTypes/ServiceWithTwoConstructorDependencies.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace FeatureTests.On.DependencyInjection.TestTypes {
6 | public class ServiceWithTwoConstructorDependencies {
7 | private readonly IService service1;
8 | private readonly IService2 service2;
9 |
10 | public ServiceWithTwoConstructorDependencies(IService service1, IService2 service2) {
11 | this.service1 = service1;
12 | this.service2 = service2;
13 | }
14 |
15 | public IService Service1 {
16 | get { return this.service1; }
17 | }
18 |
19 | public IService2 Service2 {
20 | get { return this.service2; }
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/DependencyInjection/app.config:
--------------------------------------------------------------------------------
1 |
2 |
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 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/DependencyInjection/packages.config:
--------------------------------------------------------------------------------
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 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/FeatureTests.sln.DotSettings:
--------------------------------------------------------------------------------
1 |
2 | HINT
3 | DO_NOT_SHOW
4 | END_OF_LINE
5 | END_OF_LINE
6 | END_OF_LINE
7 | END_OF_LINE
8 | END_OF_LINE
9 | END_OF_LINE
10 | System
11 | System.Collections.Generic
12 | System.Linq
13 | AB
14 | <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"><ExtraRule Prefix="I" Suffix="" Style="AaBb" /></Policy>
15 | <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" />
16 | True
17 | True
18 | True
--------------------------------------------------------------------------------
/JsonSerializers/1_SimpleTypeTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Linq;
5 | using FeatureTests.On.JsonSerializers.Adapters;
6 | using FeatureTests.On.JsonSerializers.TestTypes;
7 | using FeatureTests.Shared;
8 | using Xunit;
9 |
10 | namespace FeatureTests.On.JsonSerializers {
11 | [DisplayOrder(1)]
12 | [DisplayName("Simple types")]
13 | [Description("Tests on simple types -- top level primitive.")]
14 | public class SimpleTypeTests {
15 | private const string Iso8601WithTimeZoneFormat = @"yyyy-MM-ddTHH\:mm\:ss.fffffffK";
16 |
17 | [Feature]
18 | [DisplayName("string")]
19 | public void String(IJsonSerializerAdapter adapter) {
20 | AssertDeserializesTo("ABC", "\"ABC\"", adapter);
21 | }
22 |
23 | [Feature]
24 | [DisplayName("int")]
25 | public void Int32(IJsonSerializerAdapter adapter) {
26 | AssertDeserializesTo(5, "5", adapter);
27 | }
28 |
29 | [Feature]
30 | [DisplayName("DateTime")]
31 | public void DateTime(IJsonSerializerAdapter adapter) {
32 | var date = new DateTime(2014, 08, 02, 12, 34, 56, DateTimeKind.Utc);
33 | AssertDeserializesTo(date, "\"" + date.ToString(Iso8601WithTimeZoneFormat) + "\"", adapter);
34 | }
35 |
36 | [Feature]
37 | [DisplayName("DateTimeOffset")]
38 | public void DateTimeOffset(IJsonSerializerAdapter adapter) {
39 | var date = new DateTimeOffset(2014, 08, 02, 12, 34, 56, TimeSpan.FromHours(3));
40 | AssertDeserializesTo(date, "\"" + date.ToString(Iso8601WithTimeZoneFormat) + "\"", adapter);
41 | }
42 |
43 | [Feature]
44 | [DisplayName("Uri")]
45 | public void Uri(IJsonSerializerAdapter adapter) {
46 | var uri = new Uri("http://google.com");
47 | AssertDeserializesTo(uri, "\"" + uri + "\"", adapter);
48 | }
49 |
50 | // ReSharper disable once UnusedParameter.Local
51 | private void AssertDeserializesTo(T expected, string json, IJsonSerializerAdapter adapter) {
52 | Assert.Equal(expected, adapter.Deserialize(json));
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/JsonSerializers/2_CollectionTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.ComponentModel;
5 | using System.Linq;
6 | using FeatureTests.On.JsonSerializers.Adapters;
7 | using FeatureTests.Shared;
8 | using Xunit;
9 |
10 | namespace FeatureTests.On.JsonSerializers {
11 | [DisplayOrder(2)]
12 | [DisplayName("Collections")]
13 | public class CollectionTests {
14 | private const string ABListJson = "[\"A\", \"B\"]";
15 |
16 | [Feature]
17 | [DisplayName("string[]")]
18 | public void ArrayOfString(IJsonSerializerAdapter adapter) {
19 | AssertDeserializesTo(new[] { "A", "B" }, ABListJson, adapter);
20 | }
21 |
22 | [Feature]
23 | [DisplayName("object[]")]
24 | [Description(@"This test verifies that a mixed-type array can be deserialized.")]
25 | public void ArrayOfObject(IJsonSerializerAdapter adapter) {
26 | AssertDeserializesTo(new object[] { "A", 5 }, "[\"A\", 5]", adapter);
27 | }
28 |
29 | [Feature]
30 | [DisplayName("List")]
31 | public void ListOfString(IJsonSerializerAdapter adapter) {
32 | AssertDeserializesTo(new List { "A", "B" }, ABListJson, adapter);
33 | }
34 |
35 | [Feature]
36 | [DisplayName("IList")]
37 | public void IListOfString(IJsonSerializerAdapter adapter) {
38 | AssertDeserializesTo((IList)new List { "A", "B" }, ABListJson, adapter);
39 | }
40 |
41 | [Feature]
42 | [DisplayName("HashSet")]
43 | public void HashSetOfString(IJsonSerializerAdapter adapter) {
44 | AssertDeserializesTo(new HashSet { "A", "B" }, ABListJson, adapter);
45 | }
46 |
47 | [Feature]
48 | [DisplayName("ISet")]
49 | public void ISetOfString(IJsonSerializerAdapter adapter) {
50 | AssertDeserializesTo((ISet)new HashSet { "A", "B" }, ABListJson, adapter);
51 | }
52 |
53 | [Feature]
54 | [DisplayName("IReadOnlyList")]
55 | public void IReadOnlyListOfString(IJsonSerializerAdapter adapter) {
56 | AssertDeserializesTo((IReadOnlyList)new[] { "A", "B" }, ABListJson, adapter);
57 | }
58 |
59 | [Feature]
60 | [DisplayName("IReadOnlyCollection")]
61 | public void IReadOnlyCollectionOfString(IJsonSerializerAdapter adapter) {
62 | AssertDeserializesTo((IReadOnlyCollection)new[] { "A", "B" }, ABListJson, adapter);
63 | }
64 |
65 | [Feature]
66 | [DisplayName("IEnumerable")]
67 | public void IEnumerableOfString(IJsonSerializerAdapter adapter) {
68 | AssertDeserializesTo((IEnumerable)new[] { "A", "B" }, ABListJson, adapter);
69 | }
70 |
71 | // ReSharper disable once UnusedParameter.Local
72 | private void AssertDeserializesTo(TCollection expected, string json, IJsonSerializerAdapter adapter)
73 | where TCollection : IEnumerable
74 | {
75 | var deserialized = adapter.Deserialize(json);
76 | Assert.Equal(
77 | expected.Cast().ToArray(),
78 | deserialized.Cast().ToArray()
79 | );
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/JsonSerializers/3_DictionaryTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using AshMind.Extensions;
5 | using FeatureTests.On.JsonSerializers.Adapters;
6 | using FeatureTests.Shared;
7 | using Xunit;
8 |
9 | namespace FeatureTests.On.JsonSerializers {
10 | [DisplayOrder(3)]
11 | [DisplayName("Dictionaries")]
12 | [Description(@"
13 | Sometimes it is inconvenient or impossible to define schema as a static type in advance.
14 | This leaves two options -- dictionaries and dynamic types. These tests look at dictionary support.
15 | ")]
16 | public class DictionaryTests {
17 | [Feature]
18 | [DisplayName("Basic")]
19 | public void Basic(IJsonSerializerAdapter adapter) {
20 | var dictionary = adapter.Deserialize>("{ \"key\": \"value\" }");
21 | Assert.NotNull(dictionary);
22 | Assert.Equal("value", dictionary.GetValueOrDefault("key"));
23 | }
24 |
25 | [Feature]
26 | [DisplayName("Nested")]
27 | public void Nested(IJsonSerializerAdapter adapter) {
28 | var dictionary = adapter.Deserialize>("{ \"key\": { \"nested\": \"value\" } }");
29 | Assert.NotNull(dictionary);
30 | var nested = Assert.IsAssignableFrom>(dictionary.GetValueOrDefault("key"));
31 | Assert.Equal("value", nested.GetValueOrDefault("nested"));
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/JsonSerializers/4_ReadOnlyPropertyTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Collections.ObjectModel;
4 | using System.ComponentModel;
5 | using System.Diagnostics;
6 | using System.Linq;
7 | using FeatureTests.On.JsonSerializers.Adapters;
8 | using FeatureTests.On.JsonSerializers.TestTypes;
9 | using FeatureTests.Shared;
10 | using Xunit;
11 |
12 | namespace FeatureTests.On.JsonSerializers {
13 | [DisplayOrder(4)]
14 | [DisplayName("Read-only properties")]
15 | [Description(@"
16 | It is often a good idea to avoid public setters for certain properties.
17 | One classic example is collection properties, which are often recommended
18 | to be readonly to ensure the collection is always non-null.
19 |
20 | Since there are other ways to set those properties (e.g. Add for collections),
21 | there should be no need for bad design just to satisfy the serializer.
22 | ")]
23 | public class ReadOnlyPropertyTests {
24 | [Feature]
25 | [DisplayName("ICollection property")]
26 | public void ICollection(IJsonSerializerAdapter adapter) {
27 | AssertCanBeRoundtripped, Collection>(
28 | adapter, new Collection { "A", "B" }
29 | );
30 | }
31 |
32 | [Feature]
33 | [DisplayName("ISet