#33: add onCreateTest and remove it from RegistrationBaseTest

pull/37/head
Simon Gockner 6 years ago
parent d682ebc233
commit ad0c53189b
  1. 71
      Test.LightweightIocContainer/OnCreateTest.cs
  2. 19
      Test.LightweightIocContainer/RegistrationBaseTest.cs

@ -0,0 +1,71 @@
// Author: Simon Gockner
// Created: 2019-12-10
// Copyright(c) 2019 SimonG. All Rights Reserved.
using System;
using JetBrains.Annotations;
using LightweightIocContainer;
using LightweightIocContainer.Interfaces;
using LightweightIocContainer.Interfaces.Registrations;
using LightweightIocContainer.Registrations;
using Moq;
using NUnit.Framework;
namespace Test.LightweightIocContainer
{
[TestFixture]
public class OnCreateTest
{
#region TestClasses
private interface ITest
{
void DoSomething();
}
private interface IFoo
{
}
private interface IBar
{
}
private class Test : ITest
{
public void DoSomething()
{
throw new Exception();
}
}
[UsedImplicitly]
private class Foo : IFoo
{
public Foo(IBar bar, ITest test)
{
}
}
private class Bar : IBar
{
}
#endregion
[Test]
public void TestOnCreate()
{
RegistrationFactory registrationFactory = new RegistrationFactory(new Mock<IIocContainer>().Object);
IDefaultRegistration<ITest> testRegistration = (IDefaultRegistration<ITest>) registrationFactory.Register<ITest, Test>(Lifestyle.Transient).OnCreate(t => t.DoSomething());
Test test = new Test();
Assert.Throws<Exception>(() => testRegistration.OnCreateAction(test));
}
}
}

@ -2,7 +2,6 @@
// Created: 2019-06-06 // Created: 2019-06-06
// Copyright(c) 2019 SimonG. All Rights Reserved. // Copyright(c) 2019 SimonG. All Rights Reserved.
using System;
using JetBrains.Annotations; using JetBrains.Annotations;
using LightweightIocContainer; using LightweightIocContainer;
using LightweightIocContainer.Exceptions; using LightweightIocContainer.Exceptions;
@ -21,7 +20,7 @@ namespace Test.LightweightIocContainer
private interface ITest private interface ITest
{ {
void DoSomething();
} }
private interface IFoo private interface IFoo
@ -36,10 +35,7 @@ namespace Test.LightweightIocContainer
private class Test : ITest private class Test : ITest
{ {
public void DoSomething()
{
throw new Exception();
}
} }
[UsedImplicitly] [UsedImplicitly]
@ -59,17 +55,6 @@ namespace Test.LightweightIocContainer
#endregion #endregion
[Test]
public void TestOnCreate()
{
RegistrationFactory registrationFactory = new RegistrationFactory(new Mock<IIocContainer>().Object);
IRegistrationBase<ITest> testRegistration = registrationFactory.Register<ITest, Test>(Lifestyle.Transient).OnCreate(t => t.DoSomething());
ITest test = new Test();
Assert.Throws<Exception>(() => testRegistration.OnCreateAction(test));
}
[Test] [Test]
public void TestWithParameters() public void TestWithParameters()
{ {

Loading…
Cancel
Save