From 0da9b7e8e849bc676afd3a6de0674995fe60861d Mon Sep 17 00:00:00 2001 From: JacopoWolf Date: Sun, 27 Sep 2020 12:53:28 +0200 Subject: [PATCH] updated tests --- .../{Test.Exceptions.cs => Exceptions.cs} | 2 +- .../Features/Test.InstantiationDiff.cs | 98 +++++++++++++++++++ .../{Test.Async.cs => UseCases/Async.cs} | 6 +- .../{Test.Sync.cs => UseCases/Sync.cs} | 4 +- 4 files changed, 104 insertions(+), 6 deletions(-) rename tests/StackInjector.TEST.BlackBox/{Test.Exceptions.cs => Exceptions.cs} (98%) create mode 100644 tests/StackInjector.TEST.BlackBox/Features/Test.InstantiationDiff.cs rename tests/StackInjector.TEST.BlackBox/{Test.Async.cs => UseCases/Async.cs} (94%) rename tests/StackInjector.TEST.BlackBox/{Test.Sync.cs => UseCases/Sync.cs} (97%) diff --git a/tests/StackInjector.TEST.BlackBox/Test.Exceptions.cs b/tests/StackInjector.TEST.BlackBox/Exceptions.cs similarity index 98% rename from tests/StackInjector.TEST.BlackBox/Test.Exceptions.cs rename to tests/StackInjector.TEST.BlackBox/Exceptions.cs index 542a991..9f0896a 100644 --- a/tests/StackInjector.TEST.BlackBox/Test.Exceptions.cs +++ b/tests/StackInjector.TEST.BlackBox/Exceptions.cs @@ -10,7 +10,7 @@ namespace StackInjector.TEST.BlackBox #pragma warning disable IDE0051, IDE0044, CS0169, CS0649 - internal class TestExceptions + internal class Exceptions { private class BaseNotAServiceThrower {[Served] private List integers; } diff --git a/tests/StackInjector.TEST.BlackBox/Features/Test.InstantiationDiff.cs b/tests/StackInjector.TEST.BlackBox/Features/Test.InstantiationDiff.cs new file mode 100644 index 0000000..087a3b0 --- /dev/null +++ b/tests/StackInjector.TEST.BlackBox/Features/Test.InstantiationDiff.cs @@ -0,0 +1,98 @@ +using StackInjector; +using System; +using NUnit.Framework; +using StackInjector.Wrappers; +using StackInjector.Attributes; +using StackInjector.Settings; + +namespace StackInjector.TEST.BlackBox.Features +{ +#pragma warning disable CS0649 + + class InstantiationDiff + { + [Service] + class WrapperBase + { + [Served] + public readonly ServiceA serviceA; + + public void Work() + { + this.serviceA.sharedCondition = true; + } + + } + + [Service] + class ServiceA : IDisposable + { + public bool sharedCondition; + + public void Dispose() + { + Console.WriteLine("I've been disposed!"); + } + + } + + + [Test] + public void SimpleCloneWithDispose () + { + + var settings = StackWrapperSettings.Default + .TrackInstantiationDiff(); + + IStackWrapper wrapperB; + + using( var wrapperA = Injector.From(settings) ) + { + wrapperA.Start(e => e.Work()); + wrapperB = wrapperA.CloneCore().ToWrapper(); + } + + + Assert.Throws( () => wrapperB.Entry.Work() ); + + } + + [Test] + public void SimpleClone () + { + var settings = StackWrapperSettings.Default + .TrackInstantiationDiff(); + + IStackWrapper wrapperB; + + var wrapperA = Injector.From(settings); + + wrapperA.Start(e => e.Work()); + wrapperB = wrapperA.CloneCore().ToWrapper(); + + + + Assert.DoesNotThrow( () => wrapperB.Entry.Work() ); + } + + + + [Test] + public void DeepCloneWithDispose () + { + var settings = StackWrapperSettings.Default + .TrackInstantiationDiff(); + + IStackWrapper wrapperB; + + using( var wrapperA = Injector.From(settings) ) + { + wrapperA.Start(e => e.Work()); + wrapperB = wrapperA.DeepCloneCore().ToWrapper(); + } + + // wrapper B is a deep clone. Being different objects, disposing one won't interact with the other + Assert.DoesNotThrow( () => wrapperB.Entry.Work() ); + } + } +} \ No newline at end of file diff --git a/tests/StackInjector.TEST.BlackBox/Test.Async.cs b/tests/StackInjector.TEST.BlackBox/UseCases/Async.cs similarity index 94% rename from tests/StackInjector.TEST.BlackBox/Test.Async.cs rename to tests/StackInjector.TEST.BlackBox/UseCases/Async.cs index 907004a..22e40a0 100644 --- a/tests/StackInjector.TEST.BlackBox/Test.Async.cs +++ b/tests/StackInjector.TEST.BlackBox/UseCases/Async.cs @@ -8,12 +8,12 @@ using StackInjector.Settings; using CTkn = System.Threading.CancellationToken; -namespace StackInjector.TEST.BlackBox +namespace StackInjector.TEST.BlackBox.UseCases { #pragma warning disable IDE0051, IDE0044, CS0169, CS0649 - internal class TestAsync + internal class Async { //todo test is broken. Rewrite. /*x @@ -68,7 +68,7 @@ public void AsyncConcurrentExecution () ); // test callback - wrapper.OnElaborated += ( i ) => Console.Write(i); + wrapper.OnElaborated += ( i ) => Console.Write(i); // test submit wrapper.Submit(420); diff --git a/tests/StackInjector.TEST.BlackBox/Test.Sync.cs b/tests/StackInjector.TEST.BlackBox/UseCases/Sync.cs similarity index 97% rename from tests/StackInjector.TEST.BlackBox/Test.Sync.cs rename to tests/StackInjector.TEST.BlackBox/UseCases/Sync.cs index 53d1c45..efb2e6e 100644 --- a/tests/StackInjector.TEST.BlackBox/Test.Sync.cs +++ b/tests/StackInjector.TEST.BlackBox/UseCases/Sync.cs @@ -4,12 +4,12 @@ using StackInjector.Attributes; using StackInjector.Settings; -namespace StackInjector.TEST.BlackBox +namespace StackInjector.TEST.BlackBox.UseCases { #pragma warning disable IDE0051, IDE0044, CS0169, CS0649 - internal class TestSync + internal class Sync { [Test]