Example #1
0
        public AuthorizationRight RightsFor(IFubuRequest request)
        {
            var entityFilter = new SingleEntityFilter <T>(request.Get <T>());

            _dataRestrictions.Each(entityFilter.ApplyRestriction);
            return(entityFilter.CanView ? AuthorizationRight.None : AuthorizationRight.Deny);
        }
        public void or_will_allow_viewing_if_one_of_the_sides_is_true()
        {
            var theCase = new Case();
            theCase.Title = "The Title";

            var filter = new SingleEntityFilter<Case>(theCase);
            filter.Or(x=> x.WhereEqual(y=> y.Title, "The Title"), x=> x.WhereEqual(y=> y.Title, "Not The Title"));
            filter.CanView.ShouldBeTrue();
        }
        public void where_equal_should_handle_boxed_values()
        {
            var theCase = new Case();
            theCase.IsSecret = true;

            var filter = new SingleEntityFilter<Case>(theCase);
            filter.WhereEqual(x => x.IsSecret, true);

            filter.CanView.ShouldBeTrue();
        }
        public void where_equal_will_allow_viewing_if_the_entitys_property_and_expected_value_is_null()
        {
            var theCase = new Case();
            theCase.Title = null;

            var filter = new SingleEntityFilter<Case>(theCase);
            filter.WhereEqual(x => x.Title, null);

            filter.CanView.ShouldBeTrue();
        }
        public void where_equal_should_handle_entities()
        {
            var person = new Person().WithId();
            var theCase = new Case().WithId();
            theCase.Owner = person;

            var filter = new SingleEntityFilter<Case>(theCase);
            filter.WhereEqual(x => x.Owner, person);

            filter.CanView.ShouldBeTrue();
        }
        public void or_will_not_allow_viewing_if_the_or_clause_is_false()
        {
            var theCase = new Case();
            theCase.Title = "The Title";

            var filter = new SingleEntityFilter<Case>(theCase);
            filter.WhereEqual(x=> x.Title, "The Title");
            filter.CanView.ShouldBeTrue();
            filter.Or(x => x.WhereEqual(y => y.Title, "Not The Title"), x => x.WhereEqual(y => y.Title, "Not The Title"));
            filter.CanView.ShouldBeFalse();
        }
        public void or_will_allow_viewing_if_one_of_the_sides_is_true()
        {
            var theCase = new Case();

            theCase.Title = "The Title";

            var filter = new SingleEntityFilter <Case>(theCase);

            filter.Or(x => x.WhereEqual(y => y.Title, "The Title"), x => x.WhereEqual(y => y.Title, "Not The Title"));
            filter.CanView.ShouldBeTrue();
        }
        public void where_not_equal_should_handle_boxed_values()
        {
            var theCase = new Case();

            theCase.IsSecret = true;

            var filter = new SingleEntityFilter <Case>(theCase);

            filter.WhereNotEqual(x => x.IsSecret, false);

            filter.CanView.ShouldBeTrue();
        }
        public void where_equal_will_allow_viewing_if_the_entitys_property_and_expected_value_is_null()
        {
            var theCase = new Case();

            theCase.Title = null;

            var filter = new SingleEntityFilter <Case>(theCase);

            filter.WhereEqual(x => x.Title, null);

            filter.CanView.ShouldBeTrue();
        }
        public void where_equal_will_allow_viewing_if_the_entitys_property_is_a_specific_value()
        {
            var theCase = new Case();

            theCase.Title = "The Title";

            var filter = new SingleEntityFilter <Case>(theCase);

            filter.WhereEqual(x => x.Title, theCase.Title);

            filter.CanView.ShouldBeTrue();
        }
        public void will_not_allow_viewing_if_there_are_multiple_ors_and_one_is_false()
        {
            var theCase = new Case();

            theCase.Title = "The Title";

            var filter = new SingleEntityFilter <Case>(theCase);

            filter.Or(x => x.WhereEqual(y => y.Title, "really"), x => x.WhereEqual(y => y.Title, "not the title"));
            filter.Or(x => x.WhereEqual(y => y.Title, "The Title"), x => x.WhereEqual(y => y.Title, "Not The Title"));
            filter.CanView.ShouldBeFalse();
        }
        public void where_equal_should_handle_entities()
        {
            var person  = new Person().WithId();
            var theCase = new Case().WithId();

            theCase.Owner = person;

            var filter = new SingleEntityFilter <Case>(theCase);

            filter.WhereEqual(x => x.Owner, person);

            filter.CanView.ShouldBeTrue();
        }
        public void or_will_not_allow_viewing_if_the_or_clause_is_false()
        {
            var theCase = new Case();

            theCase.Title = "The Title";

            var filter = new SingleEntityFilter <Case>(theCase);

            filter.WhereEqual(x => x.Title, "The Title");
            filter.CanView.ShouldBeTrue();
            filter.Or(x => x.WhereEqual(y => y.Title, "Not The Title"), x => x.WhereEqual(y => y.Title, "Not The Title"));
            filter.CanView.ShouldBeFalse();
        }
        public void a_single_deny_among_many_filters_will_deny_the_entity()
        {
            var theCase = new Case();
            theCase.Title = "The Title";
            theCase.Condition = "Open";
            theCase.Reason = "Fun";

            var filter = new SingleEntityFilter<Case>(theCase);
            filter.WhereEqual(x => x.Condition, "Open");
            filter.WhereNotEqual(x => x.Title, theCase.Title);
            filter.WhereEqual(x => x.Reason, "Fun");

            filter.CanView.ShouldBeFalse();
        }
        public void a_single_deny_among_many_filters_will_deny_the_entity()
        {
            var theCase = new Case();

            theCase.Title     = "The Title";
            theCase.Condition = "Open";
            theCase.Reason    = "Fun";

            var filter = new SingleEntityFilter <Case>(theCase);

            filter.WhereEqual(x => x.Condition, "Open");
            filter.WhereNotEqual(x => x.Title, theCase.Title);
            filter.WhereEqual(x => x.Reason, "Fun");

            filter.CanView.ShouldBeFalse();
        }
        public void denying_restriction_indicates_which_restriction_denied_the_entity()
        {
            var theCase = new Case();
            theCase.Title = "The Title";
            theCase.Condition = "Open";
            theCase.Reason = "Fun";

            var filter = new SingleEntityFilter<Case>(theCase);
            var conditionRestriction = new CasePropertyRestriction(x => x.Condition, "Open");
            var titleRestriction = new CasePropertyRestriction(x => x.Title, "Not the Title");
            var originRestriction = new CasePropertyRestriction(x => x.Reason, "Fun");

            filter.ApplyRestriction(conditionRestriction);
            filter.ApplyRestriction(titleRestriction);
            filter.ApplyRestriction(originRestriction);

            filter.DenyingRestriction.ShouldBeTheSameAs(titleRestriction);
        }
        public void denying_restriction_indicates_which_restriction_denied_the_entity()
        {
            var theCase = new Case();

            theCase.Title     = "The Title";
            theCase.Condition = "Open";
            theCase.Reason    = "Fun";

            var filter = new SingleEntityFilter <Case>(theCase);
            var conditionRestriction = new CasePropertyRestriction(x => x.Condition, "Open");
            var titleRestriction     = new CasePropertyRestriction(x => x.Title, "Not the Title");
            var originRestriction    = new CasePropertyRestriction(x => x.Reason, "Fun");

            filter.ApplyRestriction(conditionRestriction);
            filter.ApplyRestriction(titleRestriction);
            filter.ApplyRestriction(originRestriction);

            filter.DenyingRestriction.ShouldBeTheSameAs(titleRestriction);
        }
        public void where_not_equal_will_deny_viewing_if_the_entitys_property_is_a_specific_value()
        {
            var theCase = new Case();
            theCase.Title = "The Title";

            var filter = new SingleEntityFilter<Case>(theCase);
            filter.WhereNotEqual(x => x.Title, theCase.Title);

            filter.CanView.ShouldBeFalse();
        }
        public void will_not_allow_viewing_if_there_are_multiple_ors_and_one_is_false()
        {
            var theCase = new Case();
            theCase.Title = "The Title";

            var filter = new SingleEntityFilter<Case>(theCase);
            filter.Or(x => x.WhereEqual(y => y.Title, "really"), x => x.WhereEqual(y => y.Title, "not the title"));
            filter.Or(x => x.WhereEqual(y => y.Title, "The Title"), x => x.WhereEqual(y => y.Title, "Not The Title"));
            filter.CanView.ShouldBeFalse();
        }