public void should_build_maybe_use_inject_point_id_as_token_for_dependency() { var builder = CreateTarget(); const string token = Reader1.InjectPointId; builder.Treat <Maybe <Section> >(token).AsInstance(new Section().ToMaybe()); builder .Treat <Maybe <IReader> >() .TreatMaybeValue() .AsCreated <Reader1>() .BuildingWhich( _ => _ .Treat <Section>(Token.Any) .AsMaybeValueOf() .As <Maybe <Section> >(Token.Propagate)) .UsingParameters(ForParameter.OfType <Section>().UseInjectPointIdAsToken()); var actual = builder.Build <Maybe <IReader> >(); // --assert actual.HasValue.Should().BeTrue(); actual.Value.Section.Should().NotBeNull(); }
public void should_build_maybe_use_inject_point_id_as_tag_for_dependency() { var builder = CreateTarget(); const string tag = Reader1.InjectPointId; builder.Treat <Maybe <Section> >(tag).AsInstance(new Section().ToMaybe()); builder .Treat <Maybe <IReader> >() .TreatMaybeValue() .AsCreated <Reader1>() .UsingArguments(ForParameter.OfType <Section>().UseInjectPointIdAsTag()); builder .Building <Reader1>() .Treat <Section>(SpecialTag.Any) .AsMaybeValueOf() .As <Maybe <Section> >(SpecialTag.Propagate); var actual = builder.Build <Maybe <IReader> >() !; // --assert actual.HasValue.Should().BeTrue(); actual.Value.Section.Should().NotBeNull(); }
private static IEnumerable ForParameterSource() { yield return(new TestCaseData(ForParameter.OfType <string>()).SetName("OfType")); yield return(new TestCaseData(ForParameter.Named("text")).SetName("Named")); yield return(new TestCaseData(ForParameter.WithInjectPoint(null)).SetName("WithInjectPoint")); }
public void pass_null_as_valid_value() { // --arrange var target = CreateTarget(); target .Treat <Subject>() .AsIs() .InjectInto(Constructor.MarkedWithInjectAttribute(Subject.StringCtor)); var actual = target.Build <Subject>(ForParameter.OfType <string?>().UseValue(null)) !; // --assert actual.String1.Should().BeNull(); }
public void should_fail_if_value_for_the_same_parameter_registered_more_than_once() { // --arrange var target = CreateTarget(); var adjuster = target .Treat <LevelOne>() .AsIs(); // --act Action actual = () => adjuster.UsingParameters(ForParameter.OfType <string>().UseToken("expected29083"), ForParameter.OfType <string>().UseValue("kldj")); // --assert actual.Should().ThrowExactly <ArmatureException>(); }
public void pass_null_as_valid_value() { // --arrange var target = CreateTarget(); target .Treat <Subject>() .AsIs() .UsingInjectPointConstructor(Subject.StringCtor); // --act var actual = target.Build <Subject>(ForParameter.OfType <string>().UseValue(null)); // --assert actual.String1.Should().BeNull(); }
public void argument_by_parameter_exact_type_should_take_over_type_assignability() { const string expected = "expected"; // --arrange var target = CreateTarget(); target .Treat <Subject>() .AsIs() .UsingArguments(ForParameter.OfType <string>().UseValue(expected), "un" + expected); // --act var actual = target.Build <Subject>(); // --assert actual !.Value.Should().Be(expected); }
public void should_fail_if_value_for_the_same_parameter_registered_more_than_once() { // --arrange var target = CreateTarget(); var tuner = target .Treat <LevelOne>() .AsIs(); // --act Action actual = () => tuner.UsingArguments( ForParameter.OfType <string>().UseTag("expected29083"), ForParameter.OfType <string>().UseValue("bad")); // --assert actual.Should() .ThrowExactly <ArmatureException>() .Where(_ => _.Message.StartsWith($"Building of an argument for the method parameter of type {typeof(string).ToLogString()} is already tuned")); }
public void argument_by_parameter_inject_point_id_should_take_over_exact_type() { const string expected = "expected"; // --arrange var target = CreateTarget(); target .Treat <Subject>() .AsIs() .UsingArguments( ForParameter.OfType <string>().UseValue("un" + expected), ForParameter.WithInjectPoint(Subject.InjectPointId).UseValue(expected)); // --act var actual = target.Build <Subject>(); // --assert actual !.Value.Should().Be(expected); }
public void typed_and_named_parameters_should_work() { const string expectedString1 = "expected1"; const string expectedString2 = "expected2"; // --arrange var target = CreateTarget(); target .Treat <Subject>() .AsIs(); // --act var actual = target .Build <Subject>( ForParameter.OfType <string>().UseValue(expectedString1), ForParameter.Named("string2").UseValue(expectedString2)) !; // --assert actual.String1.Should().Be(expectedString1); actual.String2.Should().Be(expectedString2); }