public Maybe <TRequestExodata> TryResolve <TRequestExodata, TContext, TSubject>(IExodataRequest <TRequestExodata, TContext, TSubject> request)
 {
     return(ExodataRequest <TExodata, TContext, TSubject>
            .TryToAdapt(request)
            .SelectMaybe(r => _Attribute.TryResolve(r))
            .Cast <TRequestExodata>());
 }
 public virtual Maybe <TExodata> TryResolve <TContext, TSubject>(Maybe <TContext> context, Maybe <TSubject> subject, MemberInfo member)
 {
     return(ExodataResolver
            .ToMaybe()
            .Or(Ioc.TryResolve <IExodataResolver>)
            .SelectMaybe(x => x.TryResolve(ExodataRequest.Create <TExodata, TContext, TSubject>(this, context, subject, member)))
            .SelectMaybe(x => EnsureValid(x, "bound")));
 }
 public Maybe <TRequestExodata> TryResolve <TRequestExodata, TRequestContext, TRequestSubject>(IExodataRequest <TRequestExodata, TRequestContext, TRequestSubject> request)
 {
     return(ExodataRequest <TExodata, TContext, TSubject>
            .TryToAdapt(request)
            .Where(Matches)
            .SelectMaybe(ValueFactory)
            .Cast <TRequestExodata>());
 }
        public void SourceReturnsNoBinding_GivenNoSubjectOrMember()
        {
            var source   = new AttributeExodataBindingSource();
            var bindings = source.GetBindingsFor(ExodataRequest.Create <object, object, object>(new Symbol(), Maybe.NoValue, Maybe.NoValue, null));

            Assert.IsNotNull(bindings);
            Assert.AreEqual(0, bindings.Count());
        }
        public void TryResolve_WithNoBindings_ReturnsNoValue()
        {
            var symbol = new Symbol();
            var source = new ExodataBindingModule();

            var resolver = new ExodataResolver(new[] { source });

            Maybe <int> value = resolver.TryResolve(ExodataRequest.Create <int, object, object>(symbol, Maybe <object> .NoValue, Maybe <object> .NoValue, null));

            Assert.AreEqual(Maybe <int> .NoValue, value);
        }
        public void TryResolve_WithNonAmbiguousBindingSelection_YieldsValue()
        {
            var symbol = new Symbol();
            var source = new ExodataBindingModule();

            source.Bind(symbol, 42);

            var resolver = new ExodataResolver(new[] { source });

            Maybe <int> result = resolver.TryResolve(ExodataRequest.Create <int, object, object>(symbol, Maybe <object> .NoValue, Maybe <object> .NoValue, null));

            Assert.AreEqual(42, result.Value);
        }
        public void TryResolve_WithAmbiguousBindingSelection_ThrowsAmbiguousExodataBindingsException()
        {
            var symbol = new Symbol();
            var source = new ExodataBindingModule();

            source.Bind(symbol, 42);
            source.Bind(symbol, 42);

            var resolver = new ExodataResolver(new[] { source });

            Maybe <int> result = resolver.TryResolve(ExodataRequest.Create <int, object, object>(symbol, Maybe <object> .NoValue, Maybe <object> .NoValue, null));

            var exception = Assert.Throws <AmbiguousExodataBindingsException>(() => { var x = result.HasValue; });

            Assert.IsNotNull(exception);
            Assert.AreEqual(2, exception.Bindings.Count());
        }
 protected override Maybe <TExodata> TryResolve <TSubject>(Maybe <TContext> context, Maybe <TSubject> subject, MemberInfo member)
 {
     return(_Resolver.TryResolve(ExodataRequest.Create <TExodata, TContext, TSubject>(_Symbol, context, subject, member)));
 }