예제 #1
0
        public void FilterDoesNotImplementIJobFilter()
        {
            // Arrange
            var filterInstance = new object();

            // Act
            var filter = new JobFilter(filterInstance, JobFilterScope.Method, null);

            // Assert
            Assert.Same(filterInstance, filter.Instance);
            Assert.Equal(JobFilterScope.Method, filter.Scope);
            Assert.Equal(JobFilter.DefaultOrder, filter.Order);
        }
예제 #2
0
        public void ExplicitOrderOverridesIJobFilter()
        {
            // Arrange
            var filterInstance = new Mock<IJobFilter>();
            filterInstance.SetupGet(f => f.Order).Returns(42);

            // Act
            var filter = new JobFilter(filterInstance.Object, JobFilterScope.Type, 2112);

            // Assert
            Assert.Same(filterInstance.Object, filter.Instance);
            Assert.Equal(JobFilterScope.Type, filter.Scope);
            Assert.Equal(2112, filter.Order);
        }
예제 #3
0
        public void FilterImplementsIJobFilter()
        {
            // Arrange
            var filterInstance = new Mock<IJobFilter>();
            filterInstance.SetupGet(f => f.Order).Returns(42);

            // Act
            var filter = new JobFilter(filterInstance.Object, JobFilterScope.Type, null);

            // Assert
            Assert.Same(filterInstance.Object, filter.Instance);
            Assert.Equal(JobFilterScope.Type, filter.Scope);
            Assert.Equal(42, filter.Order);
        }
        public void GetFiltersUsesRegisteredProviders()
        {
            // Arrange
            var filter = new JobFilter(new Object(), JobFilterScope.Method, null);
            var provider = new Mock<IJobFilterProvider>(MockBehavior.Strict);
            var collection = new JobFilterProviderCollection(new[] { provider.Object });
            provider.Setup(p => p.GetFilters(_job)).Returns(new[] { filter });

            // Act
            IEnumerable<JobFilter> result = collection.GetFilters(_job);

            // Assert
            Assert.Same(filter, result.Single());
        }
        public void GetFiltersIncludesLastFilterOnlyWithAttributeUsageAllowMultipleFalse()
        {
            // Arrange
            var globalFilter = new JobFilter(new AllowMultipleFalseAttribute(), JobFilterScope.Global, null);
            var controllerFilter = new JobFilter(new AllowMultipleFalseAttribute(), JobFilterScope.Type, null);
            var actionFilter = new JobFilter(new AllowMultipleFalseAttribute(), JobFilterScope.Method, null);
            var provider = new Mock<IJobFilterProvider>(MockBehavior.Strict);
            var collection = new JobFilterProviderCollection(new[] { provider.Object });
            provider.Setup(p => p.GetFilters(_job))
                .Returns(new[] { controllerFilter, actionFilter, globalFilter });

            // Act
            IEnumerable<JobFilter> result = collection.GetFilters(_job);

            // Assert
            Assert.Same(actionFilter, result.Single());
        }
        public void GetFiltersSortsFiltersByOrderFirstThenScope()
        {
            // Arrange
            var actionFilter = new JobFilter(new Object(), JobFilterScope.Method, null);
            var controllerFilter = new JobFilter(new Object(), JobFilterScope.Type, null);
            var globalFilter = new JobFilter(new Object(), JobFilterScope.Global, null);
            var earlyActionFilter = new JobFilter(new Object(), JobFilterScope.Method, -100);
            var lateGlobalFilter = new JobFilter(new Object(), JobFilterScope.Global, 100);
            var provider = new Mock<IJobFilterProvider>(MockBehavior.Strict);
            var collection = new JobFilterProviderCollection(new[] { provider.Object });
            provider.Setup(p => p.GetFilters(_job))
                .Returns(new[] { actionFilter, controllerFilter, globalFilter, earlyActionFilter, lateGlobalFilter });

            // Act
            JobFilter[] result = collection.GetFilters(_job).ToArray();

            // Assert
            Assert.Equal(5, result.Length);
            Assert.Same(earlyActionFilter, result[0]);
            Assert.Same(globalFilter, result[1]);
            Assert.Same(controllerFilter, result[2]);
            Assert.Same(actionFilter, result[3]);
            Assert.Same(lateGlobalFilter, result[4]);
        }
        public void GetFiltersIncludesAllFiltersWithAttributeUsageAllowMultipleTrue()
        {
            // Arrange
            var globalFilter = new JobFilter(new AllowMultipleTrueAttribute(), JobFilterScope.Global, null);
            var controllerFilter = new JobFilter(new AllowMultipleTrueAttribute(), JobFilterScope.Type, null);
            var actionFilter = new JobFilter(new AllowMultipleTrueAttribute(), JobFilterScope.Method, null);
            var provider = new Mock<IJobFilterProvider>(MockBehavior.Strict);
            var collection = new JobFilterProviderCollection(new[] { provider.Object });
            provider.Setup(p => p.GetFilters(_job))
                .Returns(new[] { controllerFilter, actionFilter, globalFilter });

            // Act
            List<JobFilter> result = collection.GetFilters(_job).ToList();

            // Assert
            Assert.Same(globalFilter, result[0]);
            Assert.Same(controllerFilter, result[1]);
            Assert.Same(actionFilter, result[2]);
        }