public void Should_not_throw_from_ctor_when_wrapped_result_contains_errors()
        {
            var result = SettingsBindingResult.Error <Implementation>("error");

            var wrappedResult = new SettingsBindingResultWrapper <IAbstraction, Implementation>(result);

            wrappedResult.Errors.Should().Equal(result.Errors);
        }
Пример #2
0
        public void TestSetup()
        {
            innerBinder = Substitute.For <ISafeSettingsBinder <int> >();
            innerBinder.Bind(Arg.Any <ISettingsNode>()).Returns(
                callInfo => callInfo.Arg <ISettingsNode>()?.Value == "42" ?
                SettingsBindingResult.Success(42) :
                SettingsBindingResult.Error <int>(":("));

            binder = new NullableBinder <int>(innerBinder);
        }
Пример #3
0
        public void TestSetup()
        {
            var boolBinder = Substitute.For <ISafeSettingsBinder <bool> >();

            boolBinder.Bind(Arg.Any <ISettingsNode>())
            .Returns(callInfo => (callInfo.Arg <ISettingsNode>() as ValueNode)?.Value == "true" ?
                     SettingsBindingResult.Success(true) : SettingsBindingResult.Error <bool>(":("));

            binder = new ListBinder <bool>(boolBinder);
        }
        public void TestSetup()
        {
            var boolBinder = Substitute.For <ISafeSettingsBinder <object> >();

            boolBinder.Bind(Arg.Is <ISettingsNode>(n => n is ValueNode && ((ValueNode)n).Value == "true"))
            .Returns(SettingsBindingResult.Success <object>(true));
            boolBinder.ReturnsForAll(_ => SettingsBindingResult.Error <object>(":("));

            provider = Substitute.For <ISettingsBinderProvider>();
            provider.CreateFor(typeof(bool)).Returns(boolBinder);
        }
Пример #5
0
        public void TestSetup()
        {
            stringBinder = Substitute.For <ISafeSettingsBinder <string> >();
            stringBinder.Bind(Arg.Any <ISettingsNode>())
            .Returns(callInfo =>
                     callInfo.Arg <ISettingsNode>()?.Value != "BAD" ?
                     SettingsBindingResult.Success(callInfo.Arg <ISettingsNode>()?.Value) :
                     SettingsBindingResult.Error <string>(":("));

            binder = new SetBinder <string>(stringBinder);
        }
Пример #6
0
        public void TestSetup()
        {
            stringBinder = Substitute.For <ISafeSettingsBinder <string> >();
            stringBinder.Bind(Arg.Any <ISettingsNode>())
            .Returns(callInfo => SettingsBindingResult.Success(callInfo.Arg <ISettingsNode>().Value));

            var boolBinder = Substitute.For <ISafeSettingsBinder <bool> >();

            boolBinder.Bind(Arg.Any <ISettingsNode>())
            .Returns(callInfo => (callInfo.Arg <ISettingsNode>() as ValueNode)?.Value == "true" ?
                     SettingsBindingResult.Success(true) : SettingsBindingResult.Error <bool>(":("));

            binder = new DictionaryBinder <string, bool>(stringBinder, boolBinder);
        }
        public SettingsBindingResult <T> Bind(ISettingsNode rawSettings)
        {
            var tryParseMethod = ParseMethodFinder.FindTryParseMethod(typeof(T));

            if (tryParseMethod != null)
            {
                return(new PrimitiveBinder <T>(new TryParseMethodParser(tryParseMethod)).Bind(rawSettings));
            }

            var parseMethod = ParseMethodFinder.FindParseMethod(typeof(T));

            if (parseMethod != null)
            {
                return(new PrimitiveBinder <T>(new ParseMethodParser(parseMethod)).Bind(rawSettings));
            }

            return(SettingsBindingResult.Error <T>($"Failed to find a '{nameof(int.TryParse)}' or '{nameof(int.Parse)}' method on '{typeof(T)}' type."));
        }