public void Resolves_most_recent_String()
        {
            var ctx = Context.PushState("4242").PushState("42");
            var resolver = new ContextStateResolveBuilder<String>();

            var mr = new ManualResolver(() => new ResolveContext<HarshProvisionerContext>(ctx));
            var many = mr.Resolve(resolver);

            Assert.Single(many, "42");
        }
        public void Flattens_enumerable_states()
        {
            var ctx = Context
                .PushState("123")
                .PushState(new[] { "42", "4242" });

            var resolver = new ContextStateResolveBuilder<String>();

            var mr = new ManualResolver(() => new ResolveContext<HarshProvisionerContext>(ctx));
            var many = mr.Resolve(resolver);

            Assert.Collection(
                many,
                x => Assert.Equal("42", x),
                x => Assert.Equal("4242", x),
                x => Assert.Equal("123", x)
            );
        }
예제 #3
0
        private static Object GetValueFromContext(DefaultFromContextProperty prop, HarshProvisionerContextBase context)
        {
            if (prop.TagType != null)
            {
                Logger.Debug(
                    "Property {PropertyName} gets default value form context by the tag type {TagType}",
                    prop.Name,
                    prop.TagType
                    );

                return(context
                       .GetState(prop.TagType)
                       .Cast <IDefaultFromContextTag>()
                       .FirstOrDefault()?
                       .Value);
            }

            if (prop.ResolvedPropertyInfo != null)
            {
                Logger.Debug(
                    "Property {PropertyName} resolves objects of type {ResolvedType}",
                    prop.Name,
                    prop.ResolvedPropertyInfo.ResolvedType
                    );

                return(ContextStateResolveBuilder.Create(
                           prop.ResolvedPropertyInfo.ResolvedType
                           ));
            }

            Logger.Debug(
                "Property {PropertyName} gets default value from context directly by its own type {PropertyType}",
                prop.Name,
                prop.PropertyType
                );

            return(context
                   .GetState(prop.PropertyType)
                   .FirstOrDefault());
        }