public void Test_Creation()
        {
            CounterEntityAccessControlChecker checker;

            checker = new CounterEntityAccessControlChecker();
            Assert.That(checker, Has.Property("Checker").Not.Null);
            Assert.That(checker, Has.Property("AccessControlCounters").Not.Null);
            Assert.That(checker, Has.Property("AccessControlPermissionCounters").Not.Null);
        }
        public void Test_CheckAccess()
        {
            CounterEntityAccessControlChecker checker;
            MockRepository mockRepository;
            Mock <IEntityAccessControlChecker> mockChecker;
            Mock <ISingleInstancePerformanceCounterCategory> mockSingleInstancePerformanceCounterCategory;
            Mock <IMultiInstancePerformanceCounterCategory>  mockMultiInstancePerformanceCounterCategory;

            EntityRef[] entities;
            EntityRef[] permissions;
            EntityRef   user;

            entities    = new EntityRef[] { 1 };
            permissions = new EntityRef[] { 2 };
            user        = new EntityRef(100);

            mockRepository = new MockRepository(MockBehavior.Strict);
            mockChecker    = mockRepository.Create <IEntityAccessControlChecker>();
            mockChecker.Setup(c => c.CheckAccess(
                                  It.Is <IList <EntityRef> >(x => x.SequenceEqual(entities)),
                                  It.Is <IList <EntityRef> >(x => x.SequenceEqual(permissions)),
                                  user)).Returns(() => new Dictionary <long, bool>()
            {
                { entities[0].Id, true }
            });

            mockSingleInstancePerformanceCounterCategory = mockRepository.Create <ISingleInstancePerformanceCounterCategory>();
            mockSingleInstancePerformanceCounterCategory
            .Setup(c => c.GetPerformanceCounter <RatePerSecond32PerformanceCounter>(It.IsAny <string>()))
            .Returns(mockRepository.Create <RatePerSecond32PerformanceCounter>(MockBehavior.Loose).Object);
            mockSingleInstancePerformanceCounterCategory
            .Setup(c => c.GetPerformanceCounter <NumberOfItems64PerformanceCounter>(It.IsAny <string>()))
            .Returns(mockRepository.Create <NumberOfItems64PerformanceCounter>(MockBehavior.Loose).Object);
            mockSingleInstancePerformanceCounterCategory
            .Setup(c => c.GetPerformanceCounter <AverageTimer32PerformanceCounter>(It.IsAny <string>()))
            .Returns(mockRepository.Create <AverageTimer32PerformanceCounter>(MockBehavior.Loose).Object);

            mockMultiInstancePerformanceCounterCategory = mockRepository.Create <IMultiInstancePerformanceCounterCategory>();
            mockMultiInstancePerformanceCounterCategory
            .Setup(c => c.GetPerformanceCounter <RatePerSecond32PerformanceCounter>(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(mockRepository.Create <RatePerSecond32PerformanceCounter>(MockBehavior.Loose).Object);
            mockMultiInstancePerformanceCounterCategory
            .Setup(c => c.GetPerformanceCounter <NumberOfItems64PerformanceCounter>(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(mockRepository.Create <NumberOfItems64PerformanceCounter>(MockBehavior.Loose).Object);

            checker = new CounterEntityAccessControlChecker(mockChecker.Object,
                                                            mockSingleInstancePerformanceCounterCategory.Object,
                                                            mockMultiInstancePerformanceCounterCategory.Object);
            checker.CheckAccess(entities, permissions, user);

            mockRepository.VerifyAll();
        }
        public void Test_CheckTypeAccess( )
        {
            CounterEntityAccessControlChecker checker;
            MockRepository mockRepository;
            Mock <IEntityAccessControlChecker> mockChecker;
            Mock <ISingleInstancePerformanceCounterCategory> mockSingleInstancePerformanceCounterCategory;
            Mock <IMultiInstancePerformanceCounterCategory>  mockMultiInstancePerformanceCounterCategory;
            IList <EntityType> entityTypes;
            EntityRef          user;
            EntityRef          permission;

            entityTypes = new [] { new EntityType() };
            user        = new EntityRef(100);
            permission  = new EntityRef(101);

            mockRepository = new MockRepository(MockBehavior.Strict);
            mockChecker    = mockRepository.Create <IEntityAccessControlChecker>();
            mockChecker
            .Setup(c => c.CheckTypeAccess(It.Is <IList <EntityType> >(ets => ets.SequenceEqual(entityTypes)), permission, user))
            .Returns(entityTypes.ToDictionary(et => et.Id, et => true));

            mockSingleInstancePerformanceCounterCategory = mockRepository.Create <ISingleInstancePerformanceCounterCategory>();
            mockSingleInstancePerformanceCounterCategory
            .Setup(c => c.GetPerformanceCounter <RatePerSecond32PerformanceCounter>(It.IsAny <string>()))
            .Returns(mockRepository.Create <RatePerSecond32PerformanceCounter>(MockBehavior.Loose).Object);
            mockSingleInstancePerformanceCounterCategory
            .Setup(c => c.GetPerformanceCounter <NumberOfItems64PerformanceCounter>(It.IsAny <string>()))
            .Returns(mockRepository.Create <NumberOfItems64PerformanceCounter>(MockBehavior.Loose).Object);
            mockSingleInstancePerformanceCounterCategory
            .Setup(c => c.GetPerformanceCounter <AverageTimer32PerformanceCounter>(It.IsAny <string>()))
            .Returns(mockRepository.Create <AverageTimer32PerformanceCounter>(MockBehavior.Loose).Object);

            mockMultiInstancePerformanceCounterCategory = mockRepository.Create <IMultiInstancePerformanceCounterCategory>();
            mockMultiInstancePerformanceCounterCategory
            .Setup(c => c.GetPerformanceCounter <RatePerSecond32PerformanceCounter>(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(mockRepository.Create <RatePerSecond32PerformanceCounter>(MockBehavior.Loose).Object);
            mockMultiInstancePerformanceCounterCategory
            .Setup(c => c.GetPerformanceCounter <NumberOfItems64PerformanceCounter>(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(mockRepository.Create <NumberOfItems64PerformanceCounter>(MockBehavior.Loose).Object);

            checker = new CounterEntityAccessControlChecker(mockChecker.Object,
                                                            mockSingleInstancePerformanceCounterCategory.Object,
                                                            mockMultiInstancePerformanceCounterCategory.Object);
            checker.CheckTypeAccess(entityTypes, permission, user);

            mockRepository.VerifyAll();
        }