From caf762a7242d46428bed3196c78ad8c690925097 Mon Sep 17 00:00:00 2001 From: MehadiFalamazi Date: Mon, 17 May 2021 17:02:25 +0430 Subject: [PATCH 1/2] Added BasicDecorator With Conditional Dependencies Tests #279 --- .../Simple/BasicServiceDecorator2Base.cs | 6 ++ ...coratorWithConditionalDependenciesTests.cs | 64 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 tests/Grace.Tests/Classes/Simple/BasicServiceDecorator2Base.cs create mode 100644 tests/Grace.Tests/DependencyInjection/Decorator/BasicDecoratorWithConditionalDependenciesTests.cs diff --git a/tests/Grace.Tests/Classes/Simple/BasicServiceDecorator2Base.cs b/tests/Grace.Tests/Classes/Simple/BasicServiceDecorator2Base.cs new file mode 100644 index 00000000..24478f3f --- /dev/null +++ b/tests/Grace.Tests/Classes/Simple/BasicServiceDecorator2Base.cs @@ -0,0 +1,6 @@ +namespace Grace.Tests.Classes.Simple +{ + public class BasicServiceDecorator2Base + { + } +} \ No newline at end of file diff --git a/tests/Grace.Tests/DependencyInjection/Decorator/BasicDecoratorWithConditionalDependenciesTests.cs b/tests/Grace.Tests/DependencyInjection/Decorator/BasicDecoratorWithConditionalDependenciesTests.cs new file mode 100644 index 00000000..d4d588df --- /dev/null +++ b/tests/Grace.Tests/DependencyInjection/Decorator/BasicDecoratorWithConditionalDependenciesTests.cs @@ -0,0 +1,64 @@ +using Grace.DependencyInjection; +using Grace.DependencyInjection.Conditions; +using Grace.Tests.Classes.Simple; +using Xunit; + +namespace Grace.Tests.DependencyInjection.Decorator +{ + public class BasicDecoratorWithConditionalDependenciesTests + { + [Fact] + public void Decorate_BasicService_When_Injected_Into_BasicServiceDecorator() + { + var container = new DependencyInjectionContainer(); + + container.Configure(c => + { + c.Export() + .As() + .When.InjectedInto(); + + c.ExportDecorator(typeof(BasicServiceDecorator)).As(typeof(IBasicService)); + }); + + var instance = container.Locate(); + + Assert.NotNull(instance); + Assert.IsType(instance); + } + + [Fact] + public void Decorate_BasicService_When_Meets_Activation_Type_Is_BasicService_Condition() + { + var container = new DependencyInjectionContainer(); + + container.Configure(c => + { + c.Export() + .As() + .When.MeetsCondition(new WhenActivationTypeIs()); + + c.ExportDecorator(typeof(BasicServiceDecorator)).As(typeof(IBasicService)); + }); + + var instance = container.Locate(); + + Assert.NotNull(instance); + Assert.IsType(instance); + } + } + + public class WhenActivationTypeIs : ICompiledCondition where T : class + { + /// + /// Test if strategy meets condition at configuration time + /// + /// strategy to test + /// static injection context + /// meets condition + public bool MeetsCondition(IActivationStrategy strategy, StaticInjectionContext staticInjectionContext) + { + return typeof(T).IsAssignableFrom(strategy.ActivationType); + } + } +} From a3de73be8e5b4ad6589bab9085370b782323c09d Mon Sep 17 00:00:00 2001 From: MehadiFalamazi Date: Mon, 17 May 2021 17:04:58 +0430 Subject: [PATCH 2/2] Removed BasicServiceDecorator2Base Because It Wasn't Intended to be Created #279 --- .../Classes/Simple/BasicServiceDecorator2Base.cs | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 tests/Grace.Tests/Classes/Simple/BasicServiceDecorator2Base.cs diff --git a/tests/Grace.Tests/Classes/Simple/BasicServiceDecorator2Base.cs b/tests/Grace.Tests/Classes/Simple/BasicServiceDecorator2Base.cs deleted file mode 100644 index 24478f3f..00000000 --- a/tests/Grace.Tests/Classes/Simple/BasicServiceDecorator2Base.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Grace.Tests.Classes.Simple -{ - public class BasicServiceDecorator2Base - { - } -} \ No newline at end of file