From ad0c53189b37f62ac63e7c1a51d6a1ad74217ea4 Mon Sep 17 00:00:00 2001 From: Simon Gockner Date: Sat, 14 Dec 2019 21:19:36 +0100 Subject: [PATCH] #33: add onCreateTest and remove it from RegistrationBaseTest --- Test.LightweightIocContainer/OnCreateTest.cs | 71 +++++++++++++++++++ .../RegistrationBaseTest.cs | 19 +---- 2 files changed, 73 insertions(+), 17 deletions(-) create mode 100644 Test.LightweightIocContainer/OnCreateTest.cs diff --git a/Test.LightweightIocContainer/OnCreateTest.cs b/Test.LightweightIocContainer/OnCreateTest.cs new file mode 100644 index 0000000..48cce75 --- /dev/null +++ b/Test.LightweightIocContainer/OnCreateTest.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().Object); + IDefaultRegistration testRegistration = (IDefaultRegistration) registrationFactory.Register(Lifestyle.Transient).OnCreate(t => t.DoSomething()); + + Test test = new Test(); + + Assert.Throws(() => testRegistration.OnCreateAction(test)); + } + } +} \ No newline at end of file diff --git a/Test.LightweightIocContainer/RegistrationBaseTest.cs b/Test.LightweightIocContainer/RegistrationBaseTest.cs index b29afa7..fcf6c4f 100644 --- a/Test.LightweightIocContainer/RegistrationBaseTest.cs +++ b/Test.LightweightIocContainer/RegistrationBaseTest.cs @@ -2,7 +2,6 @@ // Created: 2019-06-06 // Copyright(c) 2019 SimonG. All Rights Reserved. -using System; using JetBrains.Annotations; using LightweightIocContainer; using LightweightIocContainer.Exceptions; @@ -21,7 +20,7 @@ namespace Test.LightweightIocContainer private interface ITest { - void DoSomething(); + } private interface IFoo @@ -36,10 +35,7 @@ namespace Test.LightweightIocContainer private class Test : ITest { - public void DoSomething() - { - throw new Exception(); - } + } [UsedImplicitly] @@ -59,17 +55,6 @@ namespace Test.LightweightIocContainer #endregion - [Test] - public void TestOnCreate() - { - RegistrationFactory registrationFactory = new RegistrationFactory(new Mock().Object); - IRegistrationBase testRegistration = registrationFactory.Register(Lifestyle.Transient).OnCreate(t => t.DoSomething()); - - ITest test = new Test(); - - Assert.Throws(() => testRegistration.OnCreateAction(test)); - } - [Test] public void TestWithParameters() {