public override Collection <IFilter> GetFilters()
        {
            List <IFilter> filters       = new List <IFilter>(_innerDescriptor.GetFilters());
            List <IFilter> returnFilters = new List <IFilter>(filters.Count);

            for (int i = 0; i < filters.Count; i++)
            {
                if (FilterTracer.IsFilterTracer(filters[i]))
                {
                    returnFilters.Add(filters[i]);
                }
                else
                {
                    IEnumerable <IFilter> filterTracers = FilterTracer.CreateFilterTracers(
                        filters[i],
                        _traceWriter
                        );
                    foreach (IFilter filterTracer in filterTracers)
                    {
                        returnFilters.Add(filterTracer);
                    }
                }
            }

            return(new Collection <IFilter>(returnFilters));
        }
        public override Collection <FilterInfo> GetFilterPipeline()
        {
            List <FilterInfo> filters       = new List <FilterInfo>(_innerDescriptor.GetFilterPipeline());
            List <FilterInfo> returnFilters = new List <FilterInfo>(filters.Count);

            for (int i = 0; i < filters.Count; i++)
            {
                // If this filter has been wrapped already, use as is
                if (FilterTracer.IsFilterTracer(filters[i].Instance))
                {
                    returnFilters.Add(filters[i]);
                }
                else
                {
                    IEnumerable <FilterInfo> filterTracers = FilterTracer.CreateFilterTracers(
                        filters[i],
                        _traceWriter
                        );
                    foreach (FilterInfo filterTracer in filterTracers)
                    {
                        returnFilters.Add(filterTracer);
                    }
                }
            }

            return(new Collection <FilterInfo>(returnFilters));
        }
        public void CreateFilterTracers_With_IAuthenticationFilter_Returns_Single_Wrapped_IAuthenticationFilter()
        {
            // Arrange
            IAuthenticationFilter expectedInner       = new Mock <IAuthenticationFilter>().Object;
            FilterInfo            inputFilterInfo     = new FilterInfo(expectedInner, FilterScope.Action);
            ITraceWriter          expectedTraceWriter = new TestTraceWriter();

            // Act
            IEnumerable <FilterInfo> filters = FilterTracer.CreateFilterTracers(
                inputFilterInfo,
                expectedTraceWriter
                );

            // Assert
            Assert.NotNull(filters);
            FilterInfo filterInfo = Assert.Single(filters);

            Assert.NotNull(filterInfo);
            IFilter untypedFilter             = filterInfo.Instance;
            AuthenticationFilterTracer tracer = Assert.IsType <AuthenticationFilterTracer>(
                untypedFilter
                );

            Assert.Same(expectedInner, tracer.InnerFilter);
            Assert.Same(expectedTraceWriter, tracer.TraceWriter);
        }
        public void CreateFilterTracers_With_All_Filter_Interfaces_Returns_Wrapped_Filters_For_Each_Filter()
        {
            // Arrange
            FilterInfo filter = new FilterInfo(new TestFilterAllBehaviors(), FilterScope.Action);

            // Act
            FilterInfo[] wrappedFilters = FilterTracer
                                          .CreateFilterTracers(filter, new TestTraceWriter())
                                          .ToArray();

            // Assert
            Assert.Equal(5, wrappedFilters.Length);
            Assert.Single(wrappedFilters, f => f.Instance.GetType() == typeof(ActionFilterTracer));
            Assert.Single(
                wrappedFilters,
                f => f.Instance.GetType() == typeof(AuthorizationFilterTracer)
                );
            Assert.Single(
                wrappedFilters,
                f => f.Instance.GetType() == typeof(AuthenticationFilterTracer)
                );
            Assert.Single(
                wrappedFilters,
                f => f.Instance.GetType() == typeof(ExceptionFilterTracer)
                );
            Assert.Single(
                wrappedFilters,
                f => f.Instance.GetType() == typeof(OverrideFilterTracer)
                );
        }
Beispiel #5
0
        public void Decorator_GetInner_Property_On_FilterTracer_Returns_IFilter()
        {
            // Arrange
            IFilter      expectedInner    = new Mock <IFilter>().Object;
            FilterTracer productUnderTest = new FilterTracer(expectedInner, new TestTraceWriter());

            // Act
            IFilter actualInner = Decorator.GetInner(productUnderTest as IFilter);

            // Assert
            Assert.Same(expectedInner, actualInner);
        }
Beispiel #6
0
        public void CreateFilterTracers_IFilter_With_IAuthorizationFilter_Returns_Single_Wrapped_IAuthorizationFilter()
        {
            // Arrange
            Mock <IAuthorizationFilter> mockFilter = new Mock <IAuthorizationFilter>();

            // Act
            IFilter[] wrappedFilters = FilterTracer.CreateFilterTracers(mockFilter.Object, new TestTraceWriter()).ToArray();

            // Assert
            Assert.Equal(1, wrappedFilters.Length);
            Assert.IsType <AuthorizationFilterTracer>(wrappedFilters[0]);
        }
Beispiel #7
0
        public void CreateFilterTracers_IFilter_With_IAuthorizationFilter_Returns_Single_Wrapped_IAuthorizationFilter()
        {
            // Arrange
            Mock <IAuthorizationFilter> mockFilter = new Mock <IAuthorizationFilter>();

            // Act
            IEnumerable <IFilter> wrappedFilters = FilterTracer.CreateFilterTracers(mockFilter.Object, new TestTraceWriter());

            // Assert
            IFilter wrappedFilter = Assert.Single(wrappedFilters);

            Assert.IsType <AuthorizationFilterTracer>(wrappedFilter);
        }
        public void TraceWriter_IsSpecifiedInstance()
        {
            // Arrange
            IOverrideFilter innerFilter         = CreateDummyInnerFilter();
            ITraceWriter    expectedTraceWriter = CreateDummyTraceWriter();
            FilterTracer    product             = CreateProductUnderTest(innerFilter, expectedTraceWriter);

            // Act
            ITraceWriter traceWriter = product.TraceWriter;

            // Assert
            Assert.Same(expectedTraceWriter, traceWriter);
        }
Beispiel #9
0
        public void CreateFilterTracers_With_AuthorizationFilterAttribute_Returns_Single_Wrapped_Filter()
        {
            // Arrange
            Mock <AuthorizationFilterAttribute> mockFilter = new Mock <AuthorizationFilterAttribute>();
            FilterInfo filter = new FilterInfo(mockFilter.Object, FilterScope.Action);

            // Act
            FilterInfo[] wrappedFilters = FilterTracer.CreateFilterTracers(filter, new TestTraceWriter()).ToArray();

            // Assert
            Assert.Equal(1, wrappedFilters.Length);
            Assert.IsType <AuthorizationFilterAttributeTracer>(wrappedFilters[0].Instance);
        }
Beispiel #10
0
        public void CreateFilterTracers_IFilter_With_ExceptionFilterAttribute_Returns_Single_Wrapped_Filter()
        {
            // Arrange
            Mock <ExceptionFilterAttribute> mockFilter = new Mock <ExceptionFilterAttribute>();

            // Act
            IEnumerable <IFilter> wrappedFilters = FilterTracer.CreateFilterTracers(mockFilter.Object, new TestTraceWriter());

            // Assert
            IFilter wrappedFilter = Assert.Single(wrappedFilters);

            Assert.IsType <ExceptionFilterAttributeTracer>(wrappedFilter);
        }
Beispiel #11
0
        public void CreateFilterTracers_With_AuthorizationFilterAttribute_Returns_Single_Wrapped_Filter()
        {
            // Arrange
            Mock <AuthorizationFilterAttribute> mockFilter = new Mock <AuthorizationFilterAttribute>();
            FilterInfo filter = new FilterInfo(mockFilter.Object, FilterScope.Action);

            // Act
            IEnumerable <FilterInfo> wrappedFilters = FilterTracer.CreateFilterTracers(filter, new TestTraceWriter());

            // Assert
            FilterInfo wrappedFilter = Assert.Single(wrappedFilters);

            Assert.IsType <AuthorizationFilterAttributeTracer>(wrappedFilter.Instance);
        }
        public void CreateFilterTracers_With_All_Filter_Interfaces_Returns_3_Wrapped_Filters()
        {
            // Arrange
            FilterInfo filter = new FilterInfo(new TestFilterAllBehaviors(), FilterScope.Action);

            // Act
            FilterInfo[] wrappedFilters = FilterTracer.CreateFilterTracers(filter, new TestTraceWriter()).ToArray();

            // Assert
            Assert.Equal(3, wrappedFilters.Length);
            Assert.Equal(1, wrappedFilters.Where(f => f.Instance.GetType() == typeof(ActionFilterTracer)).Count());
            Assert.Equal(1, wrappedFilters.Where(f => f.Instance.GetType() == typeof(AuthorizationFilterTracer)).Count());
            Assert.Equal(1, wrappedFilters.Where(f => f.Instance.GetType() == typeof(ExceptionFilterTracer)).Count());
        }
        public void CreateFilterTracers_IFilter_With_All_Filter_Interfaces_Returns_3_Wrapped_Filters()
        {
            // Arrange
            IFilter filter = new TestFilterAllBehaviors();

            // Act
            IFilter[] wrappedFilters = FilterTracer.CreateFilterTracers(filter, new TestTraceWriter()).ToArray();

            // Assert
            Assert.Equal(3, wrappedFilters.Length);
            Assert.Equal(1, wrappedFilters.OfType <ActionFilterTracer>().Count());
            Assert.Equal(1, wrappedFilters.OfType <AuthorizationFilterTracer>().Count());
            Assert.Equal(1, wrappedFilters.OfType <ExceptionFilterTracer>().Count());
        }
Beispiel #14
0
        public void CreateFilterTracers_IFilter_With_All_Filter_Interfaces_Returns_Wrapped_Filters_For_Each_Filter()
        {
            // Arrange
            IFilter filter = new TestFilterAllBehaviors();

            // Act
            IFilter[] wrappedFilters = FilterTracer.CreateFilterTracers(filter, new TestTraceWriter()).ToArray();

            // Assert
            Assert.Equal(5, wrappedFilters.Length);
            Assert.Single(wrappedFilters.OfType <ActionFilterTracer>());
            Assert.Single(wrappedFilters.OfType <AuthorizationFilterTracer>());
            Assert.Single(wrappedFilters.OfType <AuthenticationFilterTracer>());
            Assert.Single(wrappedFilters.OfType <ExceptionFilterTracer>());
            Assert.Single(wrappedFilters.OfType <OverrideFilterTracer>());
        }
Beispiel #15
0
        public void CreateFilterTracers_IFilter_With_IOverrideFilter_Returns_Single_Wrapped_IOverrideFilter()
        {
            // Arrange
            IOverrideFilter expectedInner       = new Mock <IOverrideFilter>().Object;
            ITraceWriter    expectedTraceWriter = new TestTraceWriter();

            // Act
            IEnumerable <IFilter> tracers = FilterTracer.CreateFilterTracers(expectedInner, expectedTraceWriter);

            // Assert
            Assert.NotNull(tracers);
            IFilter untypedFilter       = Assert.Single(tracers);
            OverrideFilterTracer tracer = Assert.IsType <OverrideFilterTracer>(untypedFilter);

            Assert.Same(expectedInner, tracer.InnerFilter);
            Assert.Same(expectedTraceWriter, tracer.TraceWriter);
        }
Beispiel #16
0
        public void CreateFilterTracers_IFilter_With_IAuthenticationFilter_Returns_Single_Wrapped_IAuthenticationFilter()
        {
            // Arrange
            IAuthenticationFilter expectedInner       = new Mock <IAuthenticationFilter>().Object;
            ITraceWriter          expectedTraceWriter = new TestTraceWriter();

            // Act
            IEnumerable <IFilter> tracers = FilterTracer.CreateFilterTracers(expectedInner, expectedTraceWriter);

            // Assert
            Assert.NotNull(tracers);
            Assert.Equal(1, tracers.Count());
            IFilter untypedFilter = tracers.Single();

            Assert.IsType <AuthenticationFilterTracer>(untypedFilter);
            AuthenticationFilterTracer tracer = (AuthenticationFilterTracer)untypedFilter;

            Assert.Same(expectedInner, tracer.InnerFilter);
            Assert.Same(expectedTraceWriter, tracer.TraceWriter);
        }
        public void Decorator_GetInner_Property_On_FilterTracer_Returns_IFilter()
        {
            // Arrange
            IFilter expectedInner = new Mock<IFilter>().Object;
            FilterTracer productUnderTest = new FilterTracer(expectedInner, new TestTraceWriter());

            // Act
            IFilter actualInner = Decorator.GetInner(productUnderTest as IFilter);

            // Assert
            Assert.Same(expectedInner, actualInner);
        }