Ejemplo n.º 1
0
        public void GetApplicableRulesTest(long subjectId, string permission, long[] entityTypeIds, long[] expectedAccessRuleIds)
        {
            IDictionary <SubjectPermissionTuple, IList <AccessRuleQuery> > rules = new Dictionary <SubjectPermissionTuple, IList <AccessRuleQuery> >
            {
                { new SubjectPermissionTuple(100, Permissions.Read.Id), new List <AccessRuleQuery> {
                      new AccessRuleQuery(100, 101, 102, new StructuredQuery(), false)
                  } },
                { new SubjectPermissionTuple(200, Permissions.Modify.Id), new List <AccessRuleQuery> {
                      new AccessRuleQuery(200, 201, 202, new StructuredQuery(), false)
                  } },
                { new SubjectPermissionTuple(300, Permissions.Delete.Id), new List <AccessRuleQuery> {
                      new AccessRuleQuery(300, 301, 302, new StructuredQuery(), false)
                  } },
                {
                    new SubjectPermissionTuple(400, Permissions.Read.Id), new List <AccessRuleQuery>
                    {
                        new AccessRuleQuery(400, 401, 402, new StructuredQuery(), false),
                        new AccessRuleQuery(700, 701, 702, new StructuredQuery(), false),
                        new AccessRuleQuery(800, 801, 802, new StructuredQuery(), false)
                    }
                },
                { new SubjectPermissionTuple(400, Permissions.Modify.Id), new List <AccessRuleQuery> {
                      new AccessRuleQuery(500, 501, 502, new StructuredQuery(), false)
                  } },
                { new SubjectPermissionTuple(400, Permissions.Delete.Id), new List <AccessRuleQuery> {
                      new AccessRuleQuery(600, 601, 602, new StructuredQuery(), false)
                  } }
            };

            var mockRepo = new MockRepository(MockBehavior.Strict);
            var accessQueryFactoryMock = mockRepo.Create <IAccessRuleQueryFactory>();

            accessQueryFactoryMock.Setup(f => f.GetQueries()).Returns(rules);

            var sysRepo = new SystemAccessRuleQueryRepository(accessQueryFactoryMock.Object);

            var accessRules = sysRepo.GetQueries(subjectId, new EntityRef(permission), entityTypeIds).ToList();

            Assert.AreEqual(expectedAccessRuleIds.Length, accessRules.Count, "The number of access rules is invalid");

            if (expectedAccessRuleIds.Length > 0)
            {
                var accessRuleIds = accessRules.Select(ar => ar.AccessRuleId).ToSet();
                var expectedSet   = new HashSet <long>(expectedAccessRuleIds);

                Assert.IsTrue(accessRuleIds.SetEquals(expectedSet), "The access rules returned is invalid.");
            }

            mockRepo.VerifyAll();
        }
Ejemplo n.º 2
0
        public void NoApplicableRules()
        {
            IDictionary <SubjectPermissionTuple, IList <AccessRuleQuery> > rules = new Dictionary <SubjectPermissionTuple, IList <AccessRuleQuery> >();
            var mockRepo = new MockRepository(MockBehavior.Strict);
            var accessQueryFactoryMock = mockRepo.Create <IAccessRuleQueryFactory>();

            accessQueryFactoryMock.Setup(f => f.GetQueries()).Returns(rules);

            var sysRepo = new SystemAccessRuleQueryRepository(accessQueryFactoryMock.Object);

            var queries = sysRepo.GetQueries(100, Permissions.Read, new List <long> {
                200, 300
            });

            Assert.AreEqual(0, queries.Count(), "The count of queries is invalid.");

            mockRepo.VerifyAll();
        }