Exemple #1
0
        private static void Main(string[] a)
        {
            //2. Define the availability-checking function
            Func <FeatureSetting <Feature, DefaultTenantEnum>, EmptyArgs, bool> fn =
                (f, args) =>
                DefaultFunctions.AvailabilityCheckFunction(f,
                                                           Tuple.Create(FeatureVisibilityMode.Normal,
                                                                        DateTime.Now));

            //3. Take care of feature manifest initialization
            //NOTE: I suggest hiding this ugly initialization logic away in the IOC container configuration
            var featureSettingRepo  = new AppConfigFeatureSettingRepository <Feature>();
            var availabilityChecker = new FeatureSettingAvailabilityChecker <Feature>(fn);
            //from step 2
            var featureSettingService =
                new FeatureSettingService <Feature>(availabilityChecker,
                                                    featureSettingRepo);
            var manifestCreationStrategy =
                new ManifestCreationStrategyDefault <Feature>(featureSettingRepo,
                                                              featureSettingService);
            //we use the default for this example
            var featureManifestService = new FeatureManifestService <Feature>(manifestCreationStrategy);
            var featureManifest        = featureManifestService.GetManifest();

            //4. Configure feature dependencies (see the web.config - we do not specify any dependencies for this demo)

            //5. Add code that is conditional on feature availability. featureManifest ideally supplied via IOC container
            if (Feature.MyFeature.IsAvailable(featureManifest))
            {
                Console.WriteLine("MyFeature is available.");
            }
            else
            {
                throw new FeatureNotAvailableException(
                          "MyFeature is not available. This is unexpected behavior for the default implementation of NFeature.Example.Console.",
                          new[] {
                    "Check your app.config.", "Ensure built DLLs are up to date.",
                    "Ensure you have not modified this application or its configuration."
                });
            }

            //6. Optionally configure feature-specific settings using JSON
            Console.WriteLine(Feature.MyFeature.Setting(MyFeatureSettings.mySetting, featureManifest));
            Console.ReadLine();

            //7. Optionally specify dates for feature availability

            //8. At some future date optionally mark your feature as
            //Established to indicate that it is now integral to your
            //application and cannot be turned off (see footnote 2)

            //9. ...

            //10. Profit!
        }
		public void Setup() {
			var availabilityChecker =
				new FeatureSettingAvailabilityChecker<Feature>(MyAvailabilityCheckFunction);
			var featureSettingRepo = new AppConfigFeatureSettingRepository<Feature>();
			var featureSettingService =
				new FeatureSettingService<Feature>(availabilityChecker, featureSettingRepo);
			var manifestCreationStrategy =
				new ManifestCreationStrategyDefault<Feature>(featureSettingRepo, featureSettingService);
			var featureManifestService = new FeatureManifestService<Feature>(manifestCreationStrategy);
			_featureManifest = featureManifestService.GetManifest();
		}
Exemple #3
0
        public void Setup()
        {
            var availabilityChecker =
                new FeatureSettingAvailabilityChecker <Feature>(MyAvailabilityCheckFunction);
            var featureSettingRepo    = new AppConfigFeatureSettingRepository <Feature>();
            var featureSettingService =
                new FeatureSettingService <Feature>(availabilityChecker, featureSettingRepo);
            var manifestCreationStrategy =
                new ManifestCreationStrategyDefault <Feature>(featureSettingRepo, featureSettingService);
            var featureManifestService = new FeatureManifestService <Feature>(manifestCreationStrategy);

            _featureManifest = featureManifestService.GetManifest();
        }
Exemple #4
0
		private static void Main(string[] a) {
			//2. Define the availability-checking function
			Func<FeatureSetting<Feature, DefaultTenantEnum>, EmptyArgs, bool> fn =
				(f, args) =>
				DefaultFunctions.AvailabilityCheckFunction(f,
				                                           Tuple.Create(FeatureVisibilityMode.Normal,
				                                                        DateTime.Now));

			//3. Take care of feature manifest initialization
			//NOTE: I suggest hiding this ugly initialization logic away in the IOC container configuration	
			var featureSettingRepo = new AppConfigFeatureSettingRepository<Feature>();
			var availabilityChecker = new FeatureSettingAvailabilityChecker<Feature>(fn);
			//from step 2
			var featureSettingService =
				new FeatureSettingService<Feature>(availabilityChecker,
				                                   featureSettingRepo);
			var manifestCreationStrategy =
				new ManifestCreationStrategyDefault<Feature>(featureSettingRepo,
				                                             featureSettingService);
			//we use the default for this example
			var featureManifestService = new FeatureManifestService<Feature>(manifestCreationStrategy);
			var featureManifest = featureManifestService.GetManifest();

			//4. Configure feature dependencies (see the web.config - we do not specify any dependencies for this demo)

			//5. Add code that is conditional on feature availability. featureManifest ideally supplied via IOC container
			if (Feature.MyFeature.IsAvailable(featureManifest)) {
				Console.WriteLine("MyFeature is available.");
			} else {
				throw new FeatureNotAvailableException(
					"MyFeature is not available. This is unexpected behavior for the default implementation of NFeature.Example.Console.",
					new[] {
						"Check your app.config.", "Ensure built DLLs are up to date.",
						"Ensure you have not modified this application or its configuration."
					});
			}

			//6. Optionally configure feature-specific settings using JSON
			Console.WriteLine(Feature.MyFeature.Setting(MyFeatureSettings.mySetting, featureManifest));
			Console.ReadLine();

			//7. Optionally specify dates for feature availability

			//8. At some future date optionally mark your feature as 
			//Established to indicate that it is now integral to your 
			//application and cannot be turned off (see footnote 2)

			//9. ...

			//10. Profit!
		}
Exemple #5
0
        IsAvailable_PreviewableAndCookieAvailableAndDependencySettingsMissing_ThrowsException()
        {
            var fsRepo = new Mock <IFeatureSettingRepository <Feature, Tenant> >();

            fsRepo.Setup(
                s =>
                s.GetFeatureSettings()).Returns(new[] {
                new FeatureSetting <Feature, Tenant> {
                    Feature =
                        Feature.
                        TestFeatureA,
                    FeatureState =
                        FeatureState.
                        Previewable,
                    Dependencies =
                        new[] {
                        Feature
                        .
                        TestFeatureE
                    }
                },
            });

            var request = new Mock <HttpRequestBase>();

            request.Setup(
                s =>
                s.Cookies).Returns(new HttpCookieCollection {
                new HttpCookie(
                    ManifestCreationStrategyConsideringStateCookieTenantAndTime
                    <Feature, Tenant> .
                    FeaturePreviewCookieName)
            });

            var httpContext = new Mock <HttpContextBase>();

            httpContext.Setup(
                s =>
                s.Request).Returns(request.Object);

            var tenancyContext = new Mock <ITenancyContext <Tenant> >();

            tenancyContext.Setup(
                s =>
                s.CurrentTenant).Returns(Tenant.TenantA);

            var fsSvc =
                new FeatureSettingService <Feature, Tenant, TArgs>(
                    new FeatureSettingAvailabilityChecker <Feature, TArgs, Tenant>
                        (DefaultFunctions.AvailabilityCheckFunction),
                    fsRepo.Object);

            var manifestService =
                new FeatureManifestService <Feature>(
                    new ManifestCreationStrategyConsideringStateCookieTenantAndTime <Feature, Tenant>(fsSvc,
                                                                                                      fsRepo.
                                                                                                      Object,
                                                                                                      httpContext
                                                                                                      .Object,
                                                                                                      tenancyContext
                                                                                                      .Object,
                                                                                                      new ApplicationClock
                                                                                                          ()));

            Assert.Throws <FeatureNotConfiguredException <Feature> >(() => manifestService.GetManifest());
        }
			IsAvailable_PreviewableAndCookieAvailableAndDependencySettingsMissing_ThrowsException() {
			var fsRepo = new Mock<IFeatureSettingRepository<Feature, Tenant>>();
			fsRepo.Setup(
				s =>
				s.GetFeatureSettings()).Returns(new[] {
					new FeatureSetting<Feature, Tenant> {
						Feature =
				                                	Feature.
				                                	TestFeatureA,
						FeatureState =
				                                	FeatureState.
				                                	Previewable,
						Dependencies =
				                                	new[] {
				                                		Feature
				                                	.
				                                	TestFeatureE
				                                	}
					},
				});

			var request = new Mock<HttpRequestBase>();
			request.Setup(
				s =>
				s.Cookies).Returns(new HttpCookieCollection {
					new HttpCookie(
				                   	ManifestCreationStrategyConsideringStateCookieTenantAndTime
				                   		<Feature, Tenant>.
				                   		FeaturePreviewCookieName)
				});

			var httpContext = new Mock<HttpContextBase>();
			httpContext.Setup(
				s =>
				s.Request).Returns(request.Object);

			var tenancyContext = new Mock<ITenancyContext<Tenant>>();
			tenancyContext.Setup(
				s =>
				s.CurrentTenant).Returns(Tenant.TenantA);

			var fsSvc =
				new FeatureSettingService<Feature, Tenant, TArgs>(
					new FeatureSettingAvailabilityChecker<Feature, TArgs, Tenant>
						(DefaultFunctions.AvailabilityCheckFunction),
					fsRepo.Object);

			var manifestService =
				new FeatureManifestService<Feature>(
					new ManifestCreationStrategyConsideringStateCookieTenantAndTime<Feature, Tenant>(fsSvc,
					                                                                                 fsRepo.
					                                                                                 	Object,
					                                                                                 httpContext
					                                                                                 	.Object,
					                                                                                 tenancyContext
					                                                                                 	.Object,
					                                                                                 new ApplicationClock
					                                                                                 	()));

			Assert.Throws<FeatureNotConfiguredException<Feature>>(() => manifestService.GetManifest());
		}