public void treat_inheritors_generic([Values(null, "tag")] string tag) { var expected = new SkipWhileUnit(new IsInheritorOf(typeof(IDisposable), tag)); // --arrange var tree = new BuildChainPatternTree(); var target = new RootTuner(tree); // --act // --assert target.TreatInheritorsOf <IDisposable>(tag); tree.Children.Single().Should().BeEquivalentTo(expected); }
public void should_tune_getting_constructor_without_parameters() { var expected = new IfFirstUnit(Static.Of <IsConstructor>()).UseBuildAction(new GetConstructorByParameterTypes(), BuildStage.Create); // --arrange var target = Constructor.Parameterless(); var root = new BuildChainPatternTree(); // --act target.Tune(root); // --assert root.Children.Single().Should().BeEquivalentTo(expected); }
public void should_tune_getting_constructor_marked_with_inject_attribute([Values(null, "id")] object?id) { var expected = new IfFirstUnit(Static.Of <IsConstructor>()).UseBuildAction(new GetConstructorByInjectPointId(id), BuildStage.Create); // --arrange var target = Constructor.MarkedWithInjectAttribute(id); var root = new BuildChainPatternTree(); // --act target.Tune(root); // --assert root.Children.Single().Should().BeEquivalentTo(expected); }
public void treat_all([Values(null, "tag")] string tag) { var expected = new SkipAllUnits(); // --arrange var tree = new BuildChainPatternTree(); var target = new RootTuner(tree); // --act target.TreatAll(); // --assert tree.Children.Single().Should().BeEquivalentTo(expected); }
public void building_generic([Values(null, "tag")] string tag) { var expected = new SkipWhileUnit(new UnitPattern(typeof(IDisposable), tag)); // --arrange var tree = new BuildChainPatternTree(); var target = new RootTuner(tree); // --act target.Building <IDisposable>(tag); // --assert tree.Children.Single().Should().BeEquivalentTo(expected); }
public void should_add_reflection_creation_strategy([Values(null, "tag")] object?tag) { var expectedType = typeof(IDisposable); var expected = new IfFirstUnit(new UnitPattern(expectedType, tag)).UseBuildAction(new CreateByReflection(), BuildStage.Create); // --arrange var actual = new BuildChainPatternTree(); var target = new CreationTuner(actual, expectedType, tag); // --act target.CreatedByReflection(); // --assert actual.Children.Single().Should().BeEquivalentTo(expected); }
public void treat_open_generic([Values(null, "tag")] string tag) { var expected = new SkipWhileUnit(new IsGenericOfDefinition(typeof(List <>), tag)); // --arrange var tree = new BuildChainPatternTree(); var target = new RootTuner(tree); // --act var tuner = target.TreatOpenGeneric(typeof(List <>), tag); // --assert tree.Children.Single().Should().BeEquivalentTo(expected); tuner.Should().BeOfType <TreatingOpenGenericTuner>(); }
public void should_add_default_creation_strategy([Values(null, "tag")] object?tag) { var expectedType = typeof(IList <>); var expected = new IfFirstUnit(new IsGenericOfDefinition(expectedType, tag)).UseBuildAction(Default.CreationBuildAction, BuildStage.Create); // --arrange var actual = new BuildChainPatternTree(); var target = new OpenGenericCreationTuner(actual, expectedType, tag); // --act target.CreatedByDefault(); // --assert actual.Children.Single().Should().BeEquivalentTo(expected); }
public void amend_weight([Values(null, "tag")] string tag) { const int weight = 3875; var expected = new SkipWhileUnit(new UnitPattern(typeof(IDisposable), tag), weight); // --arrange var tree = new BuildChainPatternTree(); var target = new RootTuner(tree); // --act target.Building <IDisposable>(tag) .AmendWeight(weight); // --assert tree.Children.Single().Should().BeEquivalentTo(expected); }
public void inject_into_should_call_all_passed_tuners() { var expectedNode = new BuildChainPatternTree(); // --arrange var tuner1 = A.Dummy <IInjectPointTuner>(); var tuner2 = A.Dummy <IInjectPointTuner>(); var target = new FinalTuner(expectedNode); // --act target.InjectInto(tuner1, tuner2); // --assert A.CallTo(() => tuner1.Tune(expectedNode, 0)) .MustHaveHappenedOnceAndOnly() .Then(A.CallTo(() => tuner2.Tune(expectedNode, 0)).MustHaveHappenedOnceAndOnly()); }
public void should_return_all_merged_actions() { var singletonAction = new Singleton(); // --arrange var unitIdMatcher = Match.Type <string>(null); var matchString = new IfFirstUnit(unitIdMatcher).UseBuildAction(new CreateByReflection(), BuildStage.Cache); var matchAny = new SkipTillUnit(unitIdMatcher).UseBuildAction(singletonAction, BuildStage.Cache); var target = new BuildChainPatternTree(); target.Children.Add(matchString); target.Children.Add(matchAny); // --act var actual = target.GatherBuildActions(new[] { Unit.IsType <string>() }.ToArrayTail(), out var actionBag); // --assert actual.Should().BeTrue(); actionBag ![BuildStage.Cache]