public void Sync_chain_terminating_on_first()
            {
                ISynchronousFilterChain filterChain = new DefaultSynchronousFilterChain(dataStore: null)
                    .Add(new CreateInterceptorFilter())
                    .Add(new DeleteInterceptorFilter());

                var request = new DefaultResourceDataRequest(ResourceAction.Create, typeof(IAccount), new CanonicalUri("http://api.foo.bar"), false);
                var result = filterChain.Filter(request, Substitute.For<ILogger>());

                result.Action.ShouldBe(ResourceAction.Create);
                result.Body.ShouldContainKeyAndValue("Foo", "bar");
            }
        IResourceDataResult ISynchronousFilterChain.Filter(IResourceDataRequest request, ILogger logger)
        {
            bool hasFilters = !this.filters.IsNullOrEmpty();
            if (!hasFilters)
            {
                throw new ApplicationException("Empty filter chain");
            }

            if (this.filters.Count == 1)
            {
                return this.filters.Single().Filter(
                    request,
                    chain: null,
                    logger: logger);
            }

            var remainingChain = new DefaultSynchronousFilterChain(this.dataStore, this.filters.Skip(1));
            return this.filters.First().Filter(request, remainingChain, logger);
        }
Exemple #3
0
        IResourceDataResult ISynchronousFilterChain.Filter(IResourceDataRequest request, ILogger logger)
        {
            bool hasFilters = !this.filters.IsNullOrEmpty();

            if (!hasFilters)
            {
                throw new ApplicationException("Empty filter chain");
            }

            if (this.filters.Count == 1)
            {
                return(this.filters.Single().Filter(
                           request,
                           chain: null,
                           logger: logger));
            }

            var remainingChain = new DefaultSynchronousFilterChain(this.dataStore, this.filters.Skip(1));

            return(this.filters.First().Filter(request, remainingChain, logger));
        }
 public DefaultSynchronousFilterChain(DefaultSynchronousFilterChain original)
     : this(original.dataStore, original.filters)
 {
 }
Exemple #5
0
 public DefaultSynchronousFilterChain(DefaultSynchronousFilterChain original)
     : this(original.dataStore, original.filters)
 {
 }
            public void Sync_with_inline_filter()
            {
                ISynchronousFilterChain defaultFilterChain = new DefaultSynchronousFilterChain(dataStore: null)
                    .Add(new DeleteInterceptorFilter());

                ISynchronousFilterChain finalChain = new DefaultSynchronousFilterChain(defaultFilterChain as DefaultSynchronousFilterChain)
                    .Add(new DefaultSynchronousFilter((req, next, logger) =>
                    {
                        return new DefaultResourceDataResult(
                            ResourceAction.Create,
                            typeof(IDictionary<string, object>),
                            req.Uri,
                            httpStatus: 200,
                            body: new Dictionary<string, object>() { { "Foo", "bar" } });
                    }));

                var request = new DefaultResourceDataRequest(ResourceAction.Create, typeof(IAccount), new CanonicalUri("http://api.foo.bar"), false);
                var result = finalChain.Filter(request, Substitute.For<ILogger>());

                result.Action.ShouldBe(ResourceAction.Create);
                result.Body.ShouldContainKeyAndValue("Foo", "bar");
            }