public void Ctor()
        {
            CachingEntityMemberRequestFactory cachingEntityMemberRequestFactory;
            IEntityMemberRequestFactory       entityMemberRequestFactory;

            entityMemberRequestFactory        = new EntityMemberRequestFactory();
            cachingEntityMemberRequestFactory = new CachingEntityMemberRequestFactory(entityMemberRequestFactory);

            Assert.That(cachingEntityMemberRequestFactory, Has.Property("Factory").EqualTo(entityMemberRequestFactory));
            Assert.That(cachingEntityMemberRequestFactory, Has.Property("Cache").Count.EqualTo(0));
            Assert.That(cachingEntityMemberRequestFactory, Has.Property("CacheInvalidator").Not.Null);
        }
        public void BuildEntityMemberRequest(bool cached, bool useDifferentEntity)
        {
            var readPerm = new[] { Permissions.Read };

            MockRepository mockRepository;
            Mock <IEntityMemberRequestFactory> mockEntityMemberRequestFactory;
            EntityType          entityType;
            EntityMemberRequest entityMemberRequest;
            CachingEntityMemberRequestFactory cachingEntityMemberRequestFactory;

            entityType          = new EntityType();
            entityMemberRequest = new EntityMemberRequest();

            mockRepository = new MockRepository(MockBehavior.Strict);
            mockEntityMemberRequestFactory = mockRepository.Create <IEntityMemberRequestFactory>();
            mockEntityMemberRequestFactory
            .Setup(emrf => emrf.BuildEntityMemberRequest(entityType, readPerm))
            .Returns(() => entityMemberRequest);

            cachingEntityMemberRequestFactory = new CachingEntityMemberRequestFactory(
                mockEntityMemberRequestFactory.Object);
            Assert.That(cachingEntityMemberRequestFactory.BuildEntityMemberRequest(entityType, readPerm),
                        Is.EqualTo(entityMemberRequest));
            if (cached)
            {
                Assert.That(cachingEntityMemberRequestFactory.BuildEntityMemberRequest(entityType, readPerm),
                            Is.EqualTo(entityMemberRequest));
            }
            Assert.That(cachingEntityMemberRequestFactory.Cache,
                        Has.Count.EqualTo(1).And.Exactly(1).Property("Key").EqualTo(entityType.Id).And.Property("Value").EqualTo(entityMemberRequest));

            mockEntityMemberRequestFactory.Verify(emrf => emrf.BuildEntityMemberRequest(entityType, readPerm), Times.Once());

            if (useDifferentEntity)
            {
                entityType = entityType.Clone(CloneOption.Shallow).As <EntityType>( );
                mockEntityMemberRequestFactory.Verify(emrf => emrf.BuildEntityMemberRequest(entityType, readPerm), Times.Never( ));
            }

            mockRepository.VerifyAll();
        }