- aopforcodeproject.zip
- AOPClasses
- AOPDemo
- AOPDemo2
- AOPDemo3
- AOPDemo4
- AOPDemo5
- AOPForCodeProject.sln
- AOPLibrary
- AOP
- AOPLibrary.csproj
- AOPLibrary.csproj.user
- MockObjects
- obj
- Debug
- TempPE
- Release
- TempPE
- Properties
- PropertyChangeTracking
- BrainTechLLC.Core
- LinFu.AOP
- .svn
- LinFu.AOP.CecilExtensions
- LinFu.AOP.Examples
- LinFu.AOP.Interfaces
- .svn
- LinFu.AOP.Interfaces.csproj
- obj
- Debug
- LinFu.AOP.Interfaces.dll
- Refactor
- LinFu.AOP.Interfaces.dll
- TempPE
- Release
- LinFu.AOP.Interfaces.dll
- Refactor
- LinFu.AOP.Interfaces.dll
- TempPE
- Properties
- LinFu.AOP.sln
- LinFu.AOP.Tasks
- LinFu.AOP.vssscc
- LinFu.AOP.Weavers.Cecil
- Mono.Cecil.dll
- PostWeaver
- Simple.IoC
|
using System;
using System.Collections.Generic;
using System.Text;
using NMock2;
using NUnit.Framework;
namespace Simple.IoC.Tests
{
[TestFixture]
public class ContainerTests
{
private Mockery mock;
[SetUp]
public void Init()
{
mock = new Mockery();
}
[TearDown]
public void Term()
{
mock.VerifyAllExpectationsHaveBeenMet();
}
[Test]
public void ContainerShouldStoreGenericFactoryInstance()
{
IFactory<ITestObject> factory = mock.NewMock<IFactory<ITestObject>>();
ITestObject testObject = mock.NewMock<ITestObject>();
// Add the factory instance
IContainer container = new SimpleContainer();
container.AddFactory(factory);
// Once a query for that test instance is activated,
// the container should call CreateInstance
Expect.Once.On(factory).Method("CreateInstance").Will(Return.Value(testObject));
ITestObject testResult = container.GetService<ITestObject>();
Assert.AreSame(testObject, testResult);
}
[Test]
public void ContainerShouldStoreFactoryInstance()
{
IFactory factory = mock.NewMock<IFactory>();
ITestObject testObject = mock.NewMock<ITestObject>();
// Add the factory instance
IContainer container = new SimpleContainer();
container.AddFactory(typeof (ITestObject), factory);
// Once a query for that test instance is activated,
// the container should call CreateInstance
Expect.Once.On(factory).Method("CreateInstance").Will(Return.Value(testObject));
ITestObject testResult = container.GetService<ITestObject>();
Assert.AreSame(testObject, testResult);
}
[Test]
public void ContainerShouldAddServiceInstance()
{
ITestObject testObject = mock.NewMock<ITestObject>();
IContainer container = new SimpleContainer();
container.AddService(testObject);
Assert.AreSame(container.GetService<ITestObject>(), testObject);
}
[Test]
public void ContainerShouldInitializeObject()
{
IFactory<ITestObject2> factory = mock.NewMock<IFactory<ITestObject2>>();
ITestObject2 testObject = mock.NewMock<ITestObject2>();
// Add the factory instance
IContainer container = new SimpleContainer();
container.AddFactory(factory);
// Once the container instantiates the object, it should
// initialize it
Expect.Once.On(testObject).Method("Initialize").With(container);
// Once a query for that test instance is activated,
// the container should call CreateInstance
Expect.Once.On(factory).Method("CreateInstance").Will(Return.Value(testObject));
ITestObject2 testResult = container.GetService<ITestObject2>();
Assert.AreSame(testObject, testResult);
}
[Test]
public void ContainerShouldCallInjectorInterface()
{
IFactory<ITestObject2> factory = mock.NewMock<IFactory<ITestObject2>>();
ITestObject2 testObject = mock.NewMock<ITestObject2>();
ITypeInjector injector = mock.NewMock<ITypeInjector>();
IContainer container = new SimpleContainer();
container.TypeInjectors.Add(injector);
container.AddFactory(factory);
Expect.Once.On(injector).Method("CanInject").WithAnyArguments().Will(Return.Value(true));
Expect.Once.On(injector).Method("Inject").WithAnyArguments().Will(Return.Value(testObject));
Expect.Once.On(testObject).Method("Initialize").With(container);
container.AddService(injector);
Expect.Once.On(factory).Method("CreateInstance").Will(Return.Value(testObject));
ITestObject2 testResult = container.GetService<ITestObject2>();
}
[Test]
public void ContainerShouldCallPropertyInjectorInterface()
{
IContainer container = new SimpleContainer();
IPropertyInjector injector = mock.NewMock<IPropertyInjector>();
container.PropertyInjectors.Add(injector);
ITestObject testObject = mock.NewMock<ITestObject>();
container.AddService(testObject);
Expect.Once.On(injector).Method("CanInject").With(testObject, container).Will(Return.Value(true));
Expect.Once.On(injector).Method("InjectProperties").With(testObject, container);
ITestObject other = container.GetService<ITestObject>();
Assert.AreSame(other, testObject);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Currently working as a Senior Silverlight Developer with Troppus Software in Superior, CO. I enjoy statistics, programming, new technology, playing the cello, and reading codeproject articles.