public void FeatureSwitcherRegistrationExtensions_Lifecycle_DisposeTransient_Test()
        {
            var mockBehaviour = new MockBooleanBehaviour(false);

            FeatureSwitcher.Configuration.Features.Are.ConfiguredBy.Custom(mockBehaviour.Behaviour);

            WindsorContainer container = new WindsorContainer();

            container.AddFacility <FeatureSwitcherFacility>();

            container.Kernel.Register(
                Component.For <ServiceConsumer>()
                .LifestyleTransient(),
                FeatureSwitch.For <IService>()
                .UsingFeature <TestFeature>()
                .ImplementedBy <ServiceEnabled, ServiceDisabled>()
                .Configure(c => c.LifestyleTransient()));

            var actualConsumer = container.Resolve <ServiceConsumer>();

            container.Release(actualConsumer);

            Assert.True(actualConsumer.Disposed);
            Assert.True(actualConsumer.Service.Disposed);
        }
Beispiel #2
0
        /// <summary>
        /// Remove entities that lack a "core:allowDisplay" relationship to any of the
        /// given <paramref name="subjectIds"/>.
        /// </summary>
        /// <param name="entityData">
        /// The <see cref="EntityData"/> to check. This cannot be null.
        /// </param>
        /// <param name="subjectIds">
        /// The subject IDs to check for. This cannot be null.
        /// </param>
        /// <param name="userId">The ID of the user.</param>
        /// <param name="userIsAdmin">True if the user is an admin</param>
        /// <exception cref="ArgumentNullException">
        /// No argument can be null.
        /// </exception>
        public bool CanSeeElement(EntityData entityData, ISet <long> subjectIds, long userId, bool userIsAdmin)
        {
            if (entityData == null)
            {
                throw new ArgumentNullException("entityData");
            }
            if (subjectIds == null)
            {
                throw new ArgumentNullException("subjectIds");
            }

            // Check for feature switches
            string navFeatureSwitch = entityData.GetField(NavFeatureSwitchId)?.Value?.ValueString;

            if (navFeatureSwitch != null)
            {
                if (!FeatureSwitch.Get(navFeatureSwitch))
                {
                    return(false);
                }
            }

            if (userIsAdmin)
            {
                FieldData isPrivatelyOwnedFieldData = entityData.GetField(WellKnownAliases.CurrentTenant.IsPrivatelyOwned);

                bool isPrivatelyOwned = isPrivatelyOwnedFieldData != null && (bool?)isPrivatelyOwnedFieldData.Value.Value == true;

                if (!isPrivatelyOwned)
                {
                    return(true); // admin can see all public elements
                }
            }
            else
            {
                RelationshipData allowDisplayRelationshipData;

                allowDisplayRelationshipData = entityData.GetRelationship(WellKnownAliases.CurrentTenant.AllowDisplay, Direction.Reverse);

                bool allowDisplay = allowDisplayRelationshipData != null && allowDisplayRelationshipData.Entities.Any(e => subjectIds.Contains(e.Id.Id));
                if (allowDisplay)
                {
                    return(true);
                }
            }

            // Finally, in both cases check if the nav item is owned by the user

            RelationshipData securityOwnerRelationshipData = entityData.GetRelationship(WellKnownAliases.CurrentTenant.SecurityOwner, Direction.Forward);

            bool securityOwner = securityOwnerRelationshipData != null && securityOwnerRelationshipData.Entities.Any(e => userId == e.Id.Id);

            if (securityOwner)
            {
                return(true);
            }

            return(false);
        }
        public void Setup()
        {
            var dict = new Dictionary <string, string>
            {
                { "ApiName", "ExperimentationApi" },
                { "MachineName", "PRSQ02" },
                { "PortNumber", "80" },
            };

            var builder = new ConfigurationBuilder();

            builder.AddInMemoryCollection(dict);

            _sut = new FeatureSwitch(builder.Build());
        }
        private IService Test(bool enabled)
        {
            var mockBehaviour = new MockBooleanBehaviour(enabled);

            FeatureSwitcher.Configuration.Features.Are.ConfiguredBy.Custom(mockBehaviour.Behaviour);

            WindsorContainer container = new WindsorContainer();

            container.AddFacility <FeatureSwitcherFacility>();

            container.Kernel.Register(
                FeatureSwitch.For <IService>()
                .UsingFeature <TestFeature>()
                .ImplementedBy <ServiceEnabled, ServiceDisabled>()
                .Configure(c => c.LifestyleTransient()));

            var actualService = container.Resolve <IService>();

            return(actualService);
        }