private Mock<ICmsConfiguration> GetCmsConfigurationMock(AccessControlCollection accessControlCollection) { var cmsSecuritySection = new Mock<ICmsSecurityConfiguration>(); cmsSecuritySection.Setup(x => x.DefaultAccessRules).Returns(() => accessControlCollection ?? new AccessControlCollection()); var cmsConfiguration = new Mock<ICmsConfiguration>(); cmsConfiguration.Setup(x => x.Security).Returns(cmsSecuritySection.Object); return cmsConfiguration; }
public void Should_Return_Default_List_With_Principal_Added_And_Ignored() { RunActionInTransaction(session => { var collection = new AccessControlCollection(); collection.Add(new AccessControlElement { AccessLevel = AccessLevel.Deny.ToString(), Identity = SpecialIdentities.Everyone }); collection.Add(new AccessControlElement { AccessLevel = AccessLevel.ReadWrite.ToString(), Identity = SpecialIdentities.AuthenticatedUsers }); var cmsConfig = GetCmsConfigurationMock(collection); var service = new DefaultAccessControlService(Container.Resolve<ISecurityService>(), Container.Resolve<ICacheService>(), cmsConfig.Object, null); var principal = new GenericPrincipal(new GenericIdentity("John Doe"), new string[] { }); var accessLevels = service.GetDefaultAccessList(principal); Assert.AreEqual(2, accessLevels.Count); Assert.AreEqual(accessLevels.First(a => a.Identity == collection[0].Identity).AccessLevel.ToString(), collection[0].AccessLevel); Assert.AreEqual(accessLevels.First(a => a.Identity == collection[1].Identity).AccessLevel.ToString(), collection[1].AccessLevel); }); }