mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Adding tests to assert Autofac's expected behavior
--HG-- branch : 1.x
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System.Web.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Environment;
|
||||
@@ -11,5 +13,34 @@ namespace Orchard.Tests.Environment {
|
||||
var host = OrchardStarter.CreateHost(b => b.RegisterInstance(new ControllerBuilder()));
|
||||
Assert.That(host, Is.TypeOf<DefaultOrchardHost>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContainerResolvesServicesInSameOrderTheyAreRegistered() {
|
||||
var container = OrchardStarter.CreateHostContainer(builder => {
|
||||
builder.RegisterType<Component1>().As<IServiceA>();
|
||||
builder.RegisterType<Component2>().As<IServiceA>();
|
||||
});
|
||||
var services = container.Resolve<IEnumerable<IServiceA>>();
|
||||
Assert.That(services.Count(), Is.EqualTo(2));
|
||||
Assert.That(services.First(), Is.TypeOf<Component1>());
|
||||
Assert.That(services.Last(), Is.TypeOf<Component2>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MostRecentlyRegisteredServiceReturnsFromSingularResolve() {
|
||||
var container = OrchardStarter.CreateHostContainer(builder => {
|
||||
builder.RegisterType<Component1>().As<IServiceA>();
|
||||
builder.RegisterType<Component2>().As<IServiceA>();
|
||||
});
|
||||
var service = container.Resolve<IServiceA>();
|
||||
Assert.That(service, Is.Not.Null);
|
||||
Assert.That(service, Is.TypeOf<Component2>());
|
||||
}
|
||||
|
||||
public interface IServiceA {}
|
||||
|
||||
public class Component1 : IServiceA {}
|
||||
|
||||
public class Component2 : IServiceA {}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user