public void Test_EnsureAuthorised_RestrictUnauthorisedType()
        {
            MockRestrictedEntity restrictedEntity = new MockRestrictedEntity();

            CreateController controller = new CreateController();
            controller.Container = new MockCreateProjection(typeof(MockRestrictedEntity));
            bool isAuthorised = controller.EnsureAuthorised();

            Assert.IsFalse(isAuthorised, "Returned true when it should have been false.");
        }
        public void Test_Authorise_Entity_PropertyName()
        {
            MockEntity entity = new MockEntity();

            MockRestrictedEntity restrictedEntity = new MockRestrictedEntity();

            entity.RestrictedEntities = new MockRestrictedEntity[]{
                restrictedEntity
            };

            AuthoriseReferenceStrategy.New(entity, "RestrictedEntities").Authorise();

            Assert.AreEqual(0, entity.RestrictedEntities.Length, "Restricted entity wasn't removed from reference property.");
        }
        public void Test_Authorise_RemovesUnauthorisedReferences()
        {
            MockEntity entity = new MockEntity();
            entity.ID = Guid.NewGuid();

            MockRestrictedEntity restrictedEntity = new MockRestrictedEntity();
            restrictedEntity.ID = Guid.NewGuid();

            entity.RestrictedEntities = new MockRestrictedEntity[]{
                restrictedEntity
            };

            AuthoriseReferencesStrategy.New(entity).Authorise(entity);

            Assert.AreEqual(0, entity.RestrictedEntities.Length, "Invalid number of restricted entities found.");
        }
        public void Test_Save_RemovesUnauthorisedReferences()
        {
            MockEntity entity = new MockEntity();
            entity.ID = Guid.NewGuid();

            MockRestrictedEntity restrictedEntity = new MockRestrictedEntity();
            restrictedEntity.ID = Guid.NewGuid();

            entity.RestrictedEntities = new MockRestrictedEntity[]{
                restrictedEntity
            };

            SaveStrategy.New(restrictedEntity, false).Save(restrictedEntity);
            SaveStrategy.New(entity).Save(entity);

            MockEntity foundEntity = RetrieveStrategy.New<MockEntity>(false).Retrieve<MockEntity>("ID", entity.ID);

            Assert.IsNotNull(foundEntity);

            foundEntity.Activate();

            Assert.AreEqual(0, foundEntity.RestrictedEntities.Length, "Restricted entity wasn't removed from reference property.");
        }