├── .gitignore ├── .paket ├── paket.bootstrapper.exe └── paket.targets ├── Licence.txt ├── README.markdown ├── Source ├── FeatureSwitcher.Contexteer.Specs │ ├── BehaviorConfigs │ │ └── DatabaseBehaviorConfig.cs │ ├── Domain │ │ ├── ConfigureByDatabase.cs │ │ ├── FeatureConfiguration.cs │ │ ├── FeatureConfigurationRepository.cs │ │ ├── IFeatureConfigurationRepository.cs │ │ ├── User.cs │ │ └── UserRole.cs │ ├── FeatureSwitcher.Contexteer.Specs.csproj │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── When_features_are_configured_via_database.cs │ └── paket.references ├── FeatureSwitcher.Examples.sln ├── FeatureSwitcher.Examples │ ├── App.config │ ├── ConsoleColors.cs │ ├── DisableAll.cs │ ├── EnableAll.cs │ ├── Examples.cs │ ├── FeatureSwitcher.Examples.csproj │ ├── IShowExample.cs │ ├── PreserveOutputAfterExample.cs │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── paket.references └── FeatureSwitcher.Specs │ ├── BehaviorConfigs │ └── DatabaseBehaviorConfig.cs │ ├── Domain │ ├── ConfigureByDatabase.cs │ ├── FeatureConfiguration.cs │ ├── FeatureConfigurationRepository.cs │ ├── IFeatureConfigurationRepository.cs │ ├── User.cs │ └── UserRole.cs │ ├── FeatureSwitcher.Specs.csproj │ ├── Properties │ └── AssemblyInfo.cs │ ├── When_features_are_configured_via_database.cs │ └── paket.references ├── build.cmd ├── build.fsx ├── paket.dependencies └── paket.lock /.gitignore: -------------------------------------------------------------------------------- 1 | /.paket/paket.exe 2 | /packages 3 | /.fake 4 | /Build 5 | /Release 6 | /Source/*/bin 7 | /Source/*/obj 8 | *.suo 9 | *.user 10 | *.ncrunch* 11 | *.cache 12 | -------------------------------------------------------------------------------- /.paket/paket.bootstrapper.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mexx/FeatureSwitcher.Examples/3833bbb0ecdfa73e55a617f1dc0490c2b2714a90/.paket/paket.bootstrapper.exe -------------------------------------------------------------------------------- /.paket/paket.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | true 6 | 7 | true 8 | $(MSBuildThisFileDirectory) 9 | $(MSBuildThisFileDirectory)..\ 10 | /Library/Frameworks/Mono.framework/Commands/mono 11 | mono 12 | 13 | 14 | 15 | $(PaketToolsPath)paket.exe 16 | $(PaketToolsPath)paket.bootstrapper.exe 17 | "$(PaketExePath)" 18 | $(MonoPath) --runtime=v4.0.30319 "$(PaketExePath)" 19 | "$(PaketBootStrapperExePath)" $(PaketBootStrapperCommandArgs) 20 | $(MonoPath) --runtime=v4.0.30319 $(PaketBootStrapperExePath) $(PaketBootStrapperCommandArgs) 21 | 22 | $(MSBuildProjectDirectory)\paket.references 23 | $(MSBuildStartupDirectory)\paket.references 24 | $(MSBuildProjectFullPath).paket.references 25 | $(PaketCommand) restore --references-files "$(PaketReferences)" 26 | $(PaketBootStrapperCommand) 27 | 28 | RestorePackages; $(BuildDependsOn); 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Licence.txt: -------------------------------------------------------------------------------- 1 | Copyright 2012 Max Malook 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | Examples showing how to use [FeatureSwitcher](https://github.com/mexx/FeatureSwitcher). -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Contexteer.Specs/BehaviorConfigs/DatabaseBehaviorConfig.cs: -------------------------------------------------------------------------------- 1 | using Contexteer.Configuration; 2 | using FeatureSwitcher.Configuration; 3 | using FeatureSwitcher.Contexteer.Specs.Domain; 4 | using Machine.Fakes; 5 | using System.Collections.Generic; 6 | 7 | namespace FeatureSwitcher.Contexteer.Specs.BehaviorConfigs 8 | { 9 | public class DatabaseBehaviorConfig 10 | { 11 | OnEstablish context = fakeAccessor => 12 | { 13 | var config1 = new Domain.FeatureConfiguration() { Id = 1, FeatureName = "Test1Feature", ClientId = 1 }; 14 | var config2 = new Domain.FeatureConfiguration() { Id = 2, FeatureName = "Test1Feature", UseraccountId = 111 }; 15 | var config3 = new Domain.FeatureConfiguration() { Id = 3, FeatureName = "Test2Feature", Role = UserRole.Normalo }; 16 | var features = new List { config1, config2, config3 }; 17 | 18 | var dbConfiguration = new ConfigureByDatabase(features); 19 | In.Contexts.FeaturesAre(). 20 | ConfiguredBy.Custom(dbConfiguration.IsEnabled).And. 21 | NamedBy.Custom(dbConfiguration.AreNamed); 22 | }; 23 | 24 | OnCleanup clean = fakeAccessor => In.Contexts.FeaturesAre().HandledByDefault(); 25 | } 26 | } -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Contexteer.Specs/Domain/ConfigureByDatabase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace FeatureSwitcher.Contexteer.Specs.Domain 6 | { 7 | public class Test1Feature : IFeature 8 | { 9 | } 10 | 11 | public class Test2Feature : IFeature 12 | { 13 | } 14 | 15 | public class ConfigureByDatabase 16 | { 17 | private readonly IList _configurations; 18 | 19 | public ConfigureByDatabase(IList configurations) 20 | { 21 | _configurations = configurations; 22 | } 23 | 24 | //user in context 25 | public Feature.Behavior[] IsEnabled(User user) 26 | { 27 | return new Feature.Behavior[] { name => Ask(name, user) }; 28 | } 29 | 30 | private bool? Ask(Feature.Name name, User user) 31 | { 32 | var x = _configurations.Where(f => f.FeatureName == name.Value); 33 | if (!x.Any()) 34 | return null; 35 | 36 | return x.Any(f => f.UseraccountId == user.Id) 37 | || x.Any(f => f.UseraccountId == null && f.Role == user.Role); 38 | } 39 | 40 | public Feature.Name AreNamed(Type type) 41 | { 42 | return new Feature.Name(type, type.Name.Replace(type.Namespace + ".", "")); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Contexteer.Specs/Domain/FeatureConfiguration.cs: -------------------------------------------------------------------------------- 1 | namespace FeatureSwitcher.Contexteer.Specs.Domain 2 | { 3 | public class FeatureConfiguration 4 | { 5 | public long Id { get; set; } 6 | public string FeatureName { get; set; } 7 | public long? ClientId { get; set; } 8 | public long? UseraccountId { get; set; } 9 | public UserRole Role { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Contexteer.Specs/Domain/FeatureConfigurationRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace FeatureSwitcher.Contexteer.Specs.Domain 4 | { 5 | //class FeatureConfigurationRepository 6 | public class FeatureConfigurationRepository : IFeatureConfigurationRepository 7 | { 8 | /// 9 | /// Constructs the list of existent features 10 | /// 11 | /// 12 | public FeatureConfigurationRepository(IList featureConfigurations) 13 | { 14 | FeatureConfigurations = featureConfigurations; 15 | } 16 | 17 | /// 18 | /// Existent features 19 | /// 20 | public IList FeatureConfigurations { get; private set; } 21 | } 22 | } -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Contexteer.Specs/Domain/IFeatureConfigurationRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace FeatureSwitcher.Contexteer.Specs.Domain 4 | { 5 | public interface IFeatureConfigurationRepository 6 | { 7 | IList FeatureConfigurations { get; } 8 | } 9 | } -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Contexteer.Specs/Domain/User.cs: -------------------------------------------------------------------------------- 1 | using Contexteer; 2 | 3 | namespace FeatureSwitcher.Contexteer.Specs.Domain 4 | { 5 | public class User : IContext 6 | { 7 | public User(UserRole role, long? userId, long? clientId) 8 | { 9 | Role = role; 10 | Id = userId; 11 | ClientId = clientId; 12 | } 13 | 14 | public long? ClientId { get; private set; } 15 | 16 | public UserRole Role { get; private set; } 17 | 18 | public long? Id { get; private set; } 19 | } 20 | } -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Contexteer.Specs/Domain/UserRole.cs: -------------------------------------------------------------------------------- 1 | namespace FeatureSwitcher.Contexteer.Specs.Domain 2 | { 3 | public enum UserRole 4 | { 5 | Admin, 6 | Normalo 7 | } 8 | } -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Contexteer.Specs/FeatureSwitcher.Contexteer.Specs.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {F4A4E4BE-EE04-425B-AEB2-136D01432896} 8 | Library 9 | Properties 10 | FeatureSwitcher.Contexteer.Specs 11 | FeatureSwitcher.Contexteer.Specs 12 | v4.0 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 63 | 64 | 65 | 66 | 67 | ..\..\packages\Contexteer\lib\4.0\Contexteer.dll 68 | True 69 | True 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | ..\..\packages\FakeItEasy\lib\win8\FakeItEasy.dll 79 | True 80 | True 81 | 82 | 83 | 84 | 85 | 86 | 87 | ..\..\packages\FakeItEasy\lib\net35\FakeItEasy.dll 88 | True 89 | True 90 | 91 | 92 | 93 | 94 | 95 | 96 | ..\..\packages\FakeItEasy\lib\net40\FakeItEasy.dll 97 | True 98 | True 99 | 100 | 101 | 102 | 103 | 104 | 105 | ..\..\packages\FakeItEasy\lib\sl50\FakeItEasy.dll 106 | True 107 | True 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | ..\..\packages\FeatureSwitcher\lib\4.0\FeatureSwitcher.dll 117 | True 118 | True 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | ..\..\packages\FeatureSwitcher.Configuration\lib\4.0\FeatureSwitcher.Configuration.dll 128 | True 129 | True 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | ..\..\packages\FeatureSwitcher.Contexteer\lib\4.0\FeatureSwitcher.Contexteer.dll 139 | True 140 | True 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | ..\..\packages\Machine.Fakes\lib\net40\Machine.Fakes.dll 150 | True 151 | True 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | ..\..\packages\Machine.Fakes.FakeItEasy\lib\net40\Machine.Fakes.Adapters.FakeItEasy.dll 161 | True 162 | True 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | ..\..\packages\Machine.Specifications\lib\net20\Machine.Specifications.dll 172 | True 173 | True 174 | 175 | 176 | 177 | 178 | 179 | 180 | ..\..\packages\Machine.Specifications\lib\net40\Machine.Specifications.Clr4.dll 181 | True 182 | True 183 | 184 | 185 | ..\..\packages\Machine.Specifications\lib\net40\Machine.Specifications.dll 186 | True 187 | True 188 | 189 | 190 | 191 | 192 | 193 | 194 | ..\..\packages\Machine.Specifications\lib\net45\Machine.Specifications.Clr4.dll 195 | True 196 | True 197 | 198 | 199 | ..\..\packages\Machine.Specifications\lib\net45\Machine.Specifications.dll 200 | True 201 | True 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | ..\..\packages\Machine.Specifications.Should\lib\net20\Machine.Specifications.Should.dll 211 | True 212 | True 213 | 214 | 215 | 216 | 217 | 218 | 219 | ..\..\packages\Machine.Specifications.Should\lib\net40\Machine.Specifications.Should.dll 220 | True 221 | True 222 | 223 | 224 | 225 | 226 | 227 | 228 | ..\..\packages\Machine.Specifications.Should\lib\net45\Machine.Specifications.Should.dll 229 | True 230 | True 231 | 232 | 233 | 234 | 235 | -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Contexteer.Specs/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("FeatureSwitcher.Contexteer.Specs")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("FeatureSwitcher.Contexteer.Specs")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("f4a4e4be-ee04-425b-aeb2-136d01432896")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Contexteer.Specs/When_features_are_configured_via_database.cs: -------------------------------------------------------------------------------- 1 | using FeatureSwitcher.Contexteer.Specs.BehaviorConfigs; 2 | using FeatureSwitcher.Contexteer.Specs.Domain; 3 | using Machine.Specifications; 4 | using Machine.Fakes; 5 | 6 | namespace FeatureSwitcher.Contexteer.Specs 7 | { 8 | [Subject("ConfigureByDatabase")] 9 | public class When_features_configurations_are_verified_for_a_normal_user : WithSubject 10 | { 11 | Establish context = () => With(); 12 | 13 | Because of = () => 14 | { 15 | Subject = new User(UserRole.Normalo, 2, 2); 16 | }; 17 | 18 | It should_have_feature_1_disabled = () => Feature.Is().EnabledInContextOf(Subject).ShouldBeFalse(); 19 | It should_have_feature_2_enabled = () => Feature.Is().EnabledInContextOf(Subject).ShouldBeTrue(); 20 | } 21 | 22 | [Subject("ConfigureByDatabase")] 23 | public class When_features_configurations_are_verified_for_an_exact_user_id : WithSubject 24 | { 25 | Establish context = () => With(); 26 | 27 | Because of = () => 28 | { 29 | Subject = new User(UserRole.Admin, 111, null); 30 | }; 31 | 32 | It should_have_feature_1_disabled = () => Feature.Is().EnabledInContextOf(Subject).ShouldBeTrue(); 33 | It should_have_feature_2_disabled = () => Feature.Is().EnabledInContextOf(Subject).ShouldBeFalse(); 34 | } 35 | } -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Contexteer.Specs/paket.references: -------------------------------------------------------------------------------- 1 | FeatureSwitcher.Configuration 2 | FeatureSwitcher.Contexteer 3 | Machine.Fakes.FakeItEasy 4 | Machine.Specifications.Should 5 | -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Examples.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.24720.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".paket", ".paket", "{690FC18E-C88C-4BE8-8797-7C5F4882E4B8}" 7 | ProjectSection(SolutionItems) = preProject 8 | ..\paket.dependencies = ..\paket.dependencies 9 | EndProjectSection 10 | EndProject 11 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FeatureSwitcher.Examples", "FeatureSwitcher.Examples\FeatureSwitcher.Examples.csproj", "{E4727D47-E8DA-4730-8B04-01014ECDE524}" 12 | EndProject 13 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{BC6156A9-5095-4006-860C-E4D81C4ED025}" 14 | ProjectSection(SolutionItems) = preProject 15 | ..\build.cmd = ..\build.cmd 16 | ..\build.fsx = ..\build.fsx 17 | ..\Licence.txt = ..\Licence.txt 18 | ..\README.markdown = ..\README.markdown 19 | EndProjectSection 20 | EndProject 21 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FeatureSwitcher.Specs", "FeatureSwitcher.Specs\FeatureSwitcher.Specs.csproj", "{3B2BAC6C-FEB6-4EDF-B4DE-B7A05810C24C}" 22 | EndProject 23 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FeatureSwitcher.Contexteer.Specs", "FeatureSwitcher.Contexteer.Specs\FeatureSwitcher.Contexteer.Specs.csproj", "{F4A4E4BE-EE04-425B-AEB2-136D01432896}" 24 | EndProject 25 | Global 26 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 27 | Debug|Any CPU = Debug|Any CPU 28 | Release|Any CPU = Release|Any CPU 29 | EndGlobalSection 30 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 31 | {E4727D47-E8DA-4730-8B04-01014ECDE524}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 32 | {E4727D47-E8DA-4730-8B04-01014ECDE524}.Debug|Any CPU.Build.0 = Debug|Any CPU 33 | {E4727D47-E8DA-4730-8B04-01014ECDE524}.Release|Any CPU.ActiveCfg = Release|Any CPU 34 | {E4727D47-E8DA-4730-8B04-01014ECDE524}.Release|Any CPU.Build.0 = Release|Any CPU 35 | {3B2BAC6C-FEB6-4EDF-B4DE-B7A05810C24C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 36 | {3B2BAC6C-FEB6-4EDF-B4DE-B7A05810C24C}.Debug|Any CPU.Build.0 = Debug|Any CPU 37 | {3B2BAC6C-FEB6-4EDF-B4DE-B7A05810C24C}.Release|Any CPU.ActiveCfg = Release|Any CPU 38 | {3B2BAC6C-FEB6-4EDF-B4DE-B7A05810C24C}.Release|Any CPU.Build.0 = Release|Any CPU 39 | {F4A4E4BE-EE04-425B-AEB2-136D01432896}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 40 | {F4A4E4BE-EE04-425B-AEB2-136D01432896}.Debug|Any CPU.Build.0 = Debug|Any CPU 41 | {F4A4E4BE-EE04-425B-AEB2-136D01432896}.Release|Any CPU.ActiveCfg = Release|Any CPU 42 | {F4A4E4BE-EE04-425B-AEB2-136D01432896}.Release|Any CPU.Build.0 = Release|Any CPU 43 | EndGlobalSection 44 | GlobalSection(SolutionProperties) = preSolution 45 | HideSolutionNode = FALSE 46 | EndGlobalSection 47 | EndGlobal 48 | -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Examples/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |
6 |
7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Examples/ConsoleColors.cs: -------------------------------------------------------------------------------- 1 | using FeatureSwitcher.Configuration; 2 | 3 | namespace FeatureSwitcher.Examples 4 | { 5 | class ConsoleColors : IShowExample, IFeature 6 | { 7 | public string Name { get { return "Switch console colors"; } } 8 | 9 | public void Show() 10 | { 11 | Features.Are.ConfiguredBy.Custom(Features.OfType.Enabled); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Examples/DisableAll.cs: -------------------------------------------------------------------------------- 1 | using FeatureSwitcher.Configuration; 2 | 3 | namespace FeatureSwitcher.Examples 4 | { 5 | class DisableAll : IShowExample 6 | { 7 | public string Name { get { return "Disable all features"; } } 8 | 9 | public void Show() 10 | { 11 | Features.Are.AlwaysDisabled(); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Examples/EnableAll.cs: -------------------------------------------------------------------------------- 1 | using FeatureSwitcher.Configuration; 2 | 3 | namespace FeatureSwitcher.Examples 4 | { 5 | class EnableAll : IShowExample 6 | { 7 | public string Name { get { return "Enable all features"; } } 8 | 9 | public void Show() 10 | { 11 | Features.Are.AlwaysEnabled(); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Examples/Examples.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | namespace FeatureSwitcher.Examples 5 | { 6 | class Examples 7 | { 8 | public static void Show() 9 | { 10 | var showExamples = typeof(Program).Assembly.GetTypes() 11 | .Where(x => typeof(IShowExample).IsAssignableFrom(x)) 12 | .Where(x => !x.IsAbstract && !x.IsInterface) 13 | .Select(x => (IShowExample)Activator.CreateInstance(x)) 14 | .ToArray(); 15 | 16 | if (showExamples.Any()) 17 | { 18 | var exampleSelection = showExamples 19 | .Select((x, i) => string.Format("{0} - {1}", i + 1, x.Name)) 20 | .ToList(); 21 | 22 | var showAgain = true; 23 | do 24 | { 25 | if (Feature.Is().Enabled) 26 | { 27 | Console.ForegroundColor = ConsoleColor.Yellow; 28 | Console.BackgroundColor = ConsoleColor.Blue; 29 | } 30 | Console.WriteLine("Available examples:"); 31 | exampleSelection.ForEach(Console.WriteLine); 32 | 33 | Console.WriteLine(); 34 | Console.WriteLine("Which example should I show you? Enter 0 to exit."); 35 | Console.Write(" > "); 36 | 37 | int choise; 38 | if (int.TryParse(Console.ReadLine(), out choise)) 39 | { 40 | var exampleIndex = choise - 1; 41 | if (exampleIndex == -1) 42 | showAgain = false; 43 | else if (exampleIndex >= 0 && exampleIndex < showExamples.Length) 44 | { 45 | showExamples[exampleIndex].Show(); 46 | Console.ResetColor(); 47 | if (Feature.Is().Disabled) 48 | Console.Clear(); 49 | } 50 | else 51 | { 52 | Console.Clear(); 53 | Console.WriteLine("There is no example number {0}...", choise); 54 | Console.WriteLine("Please try enter the correct number of the example."); 55 | Console.WriteLine(); 56 | } 57 | } 58 | else 59 | { 60 | Console.Clear(); 61 | Console.WriteLine("I couldn't understand your wish..."); 62 | Console.WriteLine("Please try enter the number of the example."); 63 | Console.WriteLine(); 64 | } 65 | } while (showAgain); 66 | } 67 | else 68 | Console.WriteLine("No example available!"); 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Examples/FeatureSwitcher.Examples.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {E4727D47-E8DA-4730-8B04-01014ECDE524} 9 | Exe 10 | Properties 11 | FeatureSwitcher.Examples 12 | FeatureSwitcher.Examples 13 | v4.0 14 | Client 15 | 512 16 | ..\..\Source\ 17 | 18 | 19 | true 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | full 23 | AnyCPU 24 | prompt 25 | true 26 | true 27 | true 28 | 29 | 30 | bin\Release\ 31 | TRACE 32 | true 33 | pdbonly 34 | AnyCPU 35 | prompt 36 | true 37 | true 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 64 | 65 | 66 | 67 | 68 | 69 | ..\..\packages\Contexteer\lib\4.0\Contexteer.dll 70 | True 71 | True 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | ..\..\packages\FeatureSwitcher\lib\4.0\FeatureSwitcher.dll 81 | True 82 | True 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | ..\..\packages\FeatureSwitcher.Configuration\lib\4.0\FeatureSwitcher.Configuration.dll 92 | True 93 | True 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | ..\..\packages\FeatureSwitcher.Contexteer\lib\4.0\FeatureSwitcher.Contexteer.dll 103 | True 104 | True 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Examples/IShowExample.cs: -------------------------------------------------------------------------------- 1 | namespace FeatureSwitcher.Examples 2 | { 3 | internal interface IShowExample 4 | { 5 | string Name { get; } 6 | void Show(); 7 | } 8 | } -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Examples/PreserveOutputAfterExample.cs: -------------------------------------------------------------------------------- 1 | using FeatureSwitcher.Configuration; 2 | 3 | namespace FeatureSwitcher.Examples 4 | { 5 | class PreserveOutputAfterExample : IShowExample, IFeature 6 | { 7 | public string Name { get { return "Preserve output after example"; } } 8 | 9 | public void Show() 10 | { 11 | Features.Are.ConfiguredBy.Custom(Features.OfType.Enabled); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Examples/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Linq; 4 | using Contexteer; 5 | using Contexteer.Configuration; 6 | using FeatureSwitcher.Configuration; 7 | 8 | namespace FeatureSwitcher.Examples 9 | { 10 | internal class Myth : IFeature {} 11 | 12 | internal class BlueBackground : IFeature {} 13 | 14 | internal class TestNamed: IFeature {} 15 | 16 | internal class BusinessBranch : IContext 17 | { 18 | public static readonly BusinessBranch HQ = new BusinessBranch(); 19 | 20 | private BusinessBranch() 21 | { 22 | } 23 | } 24 | 25 | class Program 26 | { 27 | static void Main(string[] args) 28 | { 29 | Examples.Show(); 30 | 31 | Features.Are. 32 | AlwaysEnabled(); 33 | In.Contexts.FeaturesAre(). 34 | AlwaysEnabled(); 35 | In.Contexts.FeaturesAre(). 36 | AlwaysEnabled(); 37 | 38 | Features.Are. 39 | AlwaysEnabled(); 40 | 41 | Features.Are. 42 | AlwaysDisabled().And. 43 | NamedBy.TypeName(); 44 | 45 | Features.Are. 46 | NamedBy.TypeFullName(); 47 | 48 | Features.Are. 49 | NamedBy.TypeFullName().And. 50 | AlwaysEnabled(); 51 | 52 | In.Contexts.FeaturesAre(). 53 | AlwaysDisabled(); 54 | 55 | In.Contexts.FeaturesAre(). 56 | AlwaysEnabled().And. 57 | NamedBy.TypeFullName(); 58 | 59 | In.Contexts.FeaturesAre(). 60 | NamedBy.TypeName(); 61 | 62 | In.Contexts.FeaturesAre(). 63 | NamedBy.TypeName().And. 64 | AlwaysEnabled(); 65 | 66 | Features.Are. 67 | ConfiguredBy.AppConfig().And. 68 | NamedBy.TypeName(); 69 | 70 | Features.Are. 71 | ConfiguredBy.AppConfig().UsingConfigSectionGroup("featureSwitcher.hq").And. 72 | NamedBy.TypeName(); 73 | 74 | Features.Are. 75 | ConfiguredBy.AppConfig().IgnoreConfigurationErrors().And. 76 | NamedBy.TypeName(); 77 | 78 | Features.Are. 79 | ConfiguredBy.AppConfig().UsingConfigSectionGroup("featureSwitcher.hq").IgnoreConfigurationErrors().And. 80 | NamedBy.TypeName(); 81 | 82 | Features.Are. 83 | ConfiguredBy.AppConfig().IgnoreConfigurationErrors().UsingConfigSectionGroup("featureSwitcher.hq").And. 84 | NamedBy.TypeName(); 85 | 86 | Features.Are. 87 | ConfiguredBy.AppConfig().UsingConfigSectionGroup("featureSwitcher.hq"); 88 | 89 | Features.Are. 90 | NamedBy.TypeFullName(); 91 | 92 | Features.Are. 93 | NamedBy.TypeFullName().And. 94 | ConfiguredBy.AppConfig().UsingConfigSectionGroup("featureSwitcher.hq"); 95 | 96 | Features.Are. 97 | HandledByDefault(); 98 | 99 | Features.Are. 100 | ConfiguredBy.AppConfig().IgnoreConfigurationErrors(); 101 | 102 | if (Feature.Is().Enabled) 103 | Console.BackgroundColor = ConsoleColor.Blue; 104 | 105 | Console.WriteLine("Myth feature is {0}", Feature.Is().Enabled ? "enabled" : "disabled"); 106 | if (Debugger.IsAttached) 107 | Console.ReadLine(); 108 | 109 | 110 | var branch = BusinessBranch.HQ; 111 | var named = new TestNamed(); 112 | 113 | var a = Feature.Is().Enabled; 114 | var c = Feature.Is().EnabledInContextOf(branch); 115 | 116 | var d = named.Is().Enabled; 117 | var f = named.Is().EnabledInContextOf(branch); 118 | 119 | var features = new IFeature[] {new Myth(), new BlueBackground()}; 120 | foreach (var feature in features. 121 | Where(x => x.Is().Enabled). 122 | Where(x => x.Is().EnabledInContextOf(branch))) 123 | { 124 | var b = feature.Is().Enabled; 125 | } 126 | foreach (var feature in features.Select(Feature.Is). 127 | Where(x => x.Enabled). 128 | Where(x => x.EnabledInContextOf(branch))) 129 | { 130 | var b = feature.Enabled; 131 | } 132 | } 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Examples/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mexx/FeatureSwitcher.Examples/3833bbb0ecdfa73e55a617f1dc0490c2b2714a90/Source/FeatureSwitcher.Examples/Properties/AssemblyInfo.cs -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Examples/paket.references: -------------------------------------------------------------------------------- 1 | FeatureSwitcher.Configuration 2 | FeatureSwitcher.Contexteer -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Specs/BehaviorConfigs/DatabaseBehaviorConfig.cs: -------------------------------------------------------------------------------- 1 | using FeatureSwitcher.Configuration; 2 | using FeatureSwitcher.Specs.Domain; 3 | using Machine.Fakes; 4 | using System.Collections.Generic; 5 | 6 | namespace FeatureSwitcher.Specs.BehaviorConfigs 7 | { 8 | public class DatabaseBehaviorConfig 9 | { 10 | OnEstablish context = fakeAccessor => 11 | { 12 | var config1 = new FeatureConfiguration() { Id = 1, FeatureName = "Test1Feature", ClientId = 1 }; 13 | var config2 = new FeatureConfiguration() { Id = 2, FeatureName = "Test1Feature", UseraccountId = 111 }; 14 | var config3 = new FeatureConfiguration() { Id = 3, FeatureName = "Test2Feature", Role = UserRole.Normalo }; 15 | var features = new List { config1, config2, config3 }; 16 | 17 | fakeAccessor.The() 18 | .WhenToldTo(x => x.FeatureConfigurations) 19 | .Return(features); 20 | }; 21 | 22 | OnCleanup clean = fakeAccessor => Features.Are.HandledByDefault(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Specs/Domain/ConfigureByDatabase.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace FeatureSwitcher.Specs.Domain 5 | { 6 | public class Test1Feature : IFeature 7 | { 8 | } 9 | 10 | public class Test2Feature : IFeature 11 | { 12 | } 13 | 14 | public static class ConfigureByDatabase 15 | { 16 | //user in context 17 | 18 | public static Feature.Behavior IsEnabled(IList configurations 19 | , User user) 20 | { 21 | return name => Ask(name, configurations, user); 22 | } 23 | 24 | private static bool? Ask(Feature.Name name, IList configurations 25 | , User user) 26 | { 27 | var x = configurations.Where(f => f.FeatureName == name.Value); 28 | if (!x.Any()) 29 | return null; 30 | 31 | return x.Any(f => f.UseraccountId == user.Id) || x.Any(f => f.UseraccountId == null && f.Role == user.Role); 32 | } 33 | 34 | public static Feature.NamingConvention NamingConvention 35 | { 36 | get 37 | { 38 | return type => new Feature.Name(type, type.Name.Replace(type.Namespace + ".", "")); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Specs/Domain/FeatureConfiguration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace FeatureSwitcher.Specs.Domain 7 | { 8 | /// 9 | /// Repository DTO 10 | /// 11 | public class FeatureConfiguration 12 | { 13 | /// 14 | /// 15 | /// 16 | public long Id { get; set; } 17 | /// 18 | /// 19 | /// 20 | public string FeatureName { get; set; } 21 | /// 22 | /// 23 | /// 24 | public long? ClientId { get; set; } 25 | /// 26 | /// 27 | /// 28 | public long? UseraccountId { get; set; } 29 | /// 30 | /// 31 | /// 32 | public UserRole Role { get; set; } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Specs/Domain/FeatureConfigurationRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace FeatureSwitcher.Specs.Domain 4 | { 5 | //class FeatureConfigurationRepository 6 | public class FeatureConfigurationRepository : IFeatureConfigurationRepository 7 | { 8 | /// 9 | /// Constructs the list of existent features 10 | /// 11 | /// 12 | public FeatureConfigurationRepository(IList featureConfigurations) 13 | { 14 | FeatureConfigurations = featureConfigurations; 15 | } 16 | 17 | /// 18 | /// Existent features 19 | /// 20 | public IList FeatureConfigurations { get; private set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Specs/Domain/IFeatureConfigurationRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace FeatureSwitcher.Specs.Domain 4 | { 5 | public interface IFeatureConfigurationRepository 6 | { 7 | IList FeatureConfigurations { get; } 8 | } 9 | } -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Specs/Domain/User.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace FeatureSwitcher.Specs.Domain 7 | { 8 | /// 9 | /// 10 | /// 11 | public class User 12 | { 13 | /// 14 | /// Logged on user 15 | /// 16 | public User(UserRole role, long? userId, long? clientId) 17 | { 18 | Role = role; 19 | Id = userId; 20 | ClientId = clientId; 21 | } 22 | 23 | /// 24 | /// 25 | /// 26 | public long? ClientId { get; private set; } 27 | 28 | /// 29 | /// 30 | /// 31 | public UserRole Role { get; private set; } 32 | /// 33 | /// 34 | /// 35 | public long? Id { get; private set; } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Specs/Domain/UserRole.cs: -------------------------------------------------------------------------------- 1 | namespace FeatureSwitcher.Specs.Domain 2 | { 3 | /// 4 | /// Some possible user roles 5 | /// 6 | public enum UserRole 7 | { 8 | /// 9 | /// 10 | /// 11 | Admin, 12 | /// 13 | /// 14 | /// 15 | Normalo 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Specs/FeatureSwitcher.Specs.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {3B2BAC6C-FEB6-4EDF-B4DE-B7A05810C24C} 9 | Library 10 | Properties 11 | FeatureSwitcher.Specs 12 | FeatureSwitcher.Specs 13 | v4.0 14 | 512 15 | ..\..\Source\ 16 | 17 | 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 63 | 64 | 65 | 66 | 67 | 68 | ..\..\packages\FakeItEasy\lib\win8\FakeItEasy.dll 69 | True 70 | True 71 | 72 | 73 | 74 | 75 | 76 | 77 | ..\..\packages\FakeItEasy\lib\net35\FakeItEasy.dll 78 | True 79 | True 80 | 81 | 82 | 83 | 84 | 85 | 86 | ..\..\packages\FakeItEasy\lib\net40\FakeItEasy.dll 87 | True 88 | True 89 | 90 | 91 | 92 | 93 | 94 | 95 | ..\..\packages\FakeItEasy\lib\sl50\FakeItEasy.dll 96 | True 97 | True 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | ..\..\packages\FeatureSwitcher\lib\4.0\FeatureSwitcher.dll 107 | True 108 | True 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | ..\..\packages\FeatureSwitcher.Configuration\lib\4.0\FeatureSwitcher.Configuration.dll 118 | True 119 | True 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | ..\..\packages\Machine.Fakes\lib\net40\Machine.Fakes.dll 129 | True 130 | True 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | ..\..\packages\Machine.Fakes.FakeItEasy\lib\net40\Machine.Fakes.Adapters.FakeItEasy.dll 140 | True 141 | True 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | ..\..\packages\Machine.Specifications\lib\net20\Machine.Specifications.dll 151 | True 152 | True 153 | 154 | 155 | 156 | 157 | 158 | 159 | ..\..\packages\Machine.Specifications\lib\net40\Machine.Specifications.Clr4.dll 160 | True 161 | True 162 | 163 | 164 | ..\..\packages\Machine.Specifications\lib\net40\Machine.Specifications.dll 165 | True 166 | True 167 | 168 | 169 | 170 | 171 | 172 | 173 | ..\..\packages\Machine.Specifications\lib\net45\Machine.Specifications.Clr4.dll 174 | True 175 | True 176 | 177 | 178 | ..\..\packages\Machine.Specifications\lib\net45\Machine.Specifications.dll 179 | True 180 | True 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | ..\..\packages\Machine.Specifications.Should\lib\net20\Machine.Specifications.Should.dll 190 | True 191 | True 192 | 193 | 194 | 195 | 196 | 197 | 198 | ..\..\packages\Machine.Specifications.Should\lib\net40\Machine.Specifications.Should.dll 199 | True 200 | True 201 | 202 | 203 | 204 | 205 | 206 | 207 | ..\..\packages\Machine.Specifications.Should\lib\net45\Machine.Specifications.Should.dll 208 | True 209 | True 210 | 211 | 212 | 213 | 214 | -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Specs/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("FeatureSwitcher.Specs")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("FeatureSwitcher")] 12 | [assembly: AssemblyProduct("FeatureSwitcher")] 13 | [assembly: AssemblyCopyright("Copyright © FeatureSwitcher 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("e9bdd2ad-da38-49b1-9924-b3a9bb380936")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | [assembly: AssemblyVersion("1.0.0.0")] 33 | [assembly: AssemblyFileVersion("1.0.0.0")] 34 | -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Specs/When_features_are_configured_via_database.cs: -------------------------------------------------------------------------------- 1 | using FeatureSwitcher.Configuration; 2 | using FeatureSwitcher.Specs.BehaviorConfigs; 3 | using FeatureSwitcher.Specs.Domain; 4 | using Machine.Specifications; 5 | using Machine.Fakes; 6 | 7 | namespace FeatureSwitcher.Specs 8 | { 9 | [Subject("ConfigureByDatabase")] 10 | public class When_features_configurations_are_verified_for_a_normal_user : WithSubject 11 | { 12 | Establish context = () => With(); 13 | 14 | Because of = () => 15 | { 16 | Subject = new User(UserRole.Normalo, 2, 2); 17 | Features.Are.ConfiguredBy.Custom( 18 | ConfigureByDatabase.IsEnabled(The().FeatureConfigurations, Subject)).And.NamedBy.Custom(ConfigureByDatabase.NamingConvention); 19 | }; 20 | 21 | It should_have_feature_1_disabled = () => Feature.Is().Enabled.ShouldBeFalse(); 22 | It should_have_feature_2_enabled = () => Feature.Is().Enabled.ShouldBeTrue(); 23 | } 24 | 25 | [Subject("ConfigureByDatabase")] 26 | public class When_features_configurations_are_verified_for_an_exact_user_id : WithSubject 27 | { 28 | Establish context = () => With(); 29 | 30 | Because of = () => 31 | { 32 | Subject = new User(UserRole.Admin, 111, null); 33 | Features.Are.ConfiguredBy.Custom( 34 | ConfigureByDatabase.IsEnabled(The().FeatureConfigurations, Subject)).And.NamedBy.Custom(ConfigureByDatabase.NamingConvention); 35 | }; 36 | 37 | It should_have_feature_1_disabled = () => Feature.Is().Enabled.ShouldBeTrue(); 38 | It should_have_feature_2_disabled = () => Feature.Is().Enabled.ShouldBeFalse(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Source/FeatureSwitcher.Specs/paket.references: -------------------------------------------------------------------------------- 1 | FeatureSwitcher.Configuration 2 | Machine.Fakes.FakeItEasy 3 | Machine.Specifications.Should 4 | -------------------------------------------------------------------------------- /build.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | cls 3 | 4 | .paket\paket.bootstrapper.exe 5 | if errorlevel 1 ( 6 | exit /b %errorlevel% 7 | ) 8 | 9 | .paket\paket.exe restore 10 | if errorlevel 1 ( 11 | exit /b %errorlevel% 12 | ) 13 | 14 | packages\build\FAKE\tools\FAKE.exe build.fsx %* 15 | -------------------------------------------------------------------------------- /build.fsx: -------------------------------------------------------------------------------- 1 | #I @"packages\build\Fake\tools" 2 | #r "FakeLib.dll" 3 | 4 | open Fake 5 | 6 | (* properties *) 7 | let authors = ["Max Malook"] 8 | let projectName = "FeatureSwitcher.Examples" 9 | 10 | TraceEnvironmentVariables() 11 | 12 | let version = if isLocalBuild then getBuildParamOrDefault "version" "0.0.0.1" else buildVersion 13 | 14 | (* Directories *) 15 | let sourceDir = "./Source/" 16 | 17 | let buildDir = "./Build/" 18 | let testDir = buildDir 19 | let testOutputDir = buildDir @@ "Specs/" 20 | let deployDir = "./Release/" 21 | 22 | (* files *) 23 | let slnReferences = !! (sourceDir @@ "*.sln") 24 | 25 | (* Targets *) 26 | Target "Clean" (fun _ -> 27 | CleanDirs [buildDir; testDir; testOutputDir; deployDir] 28 | ) 29 | 30 | Target "BuildApp" (fun _ -> 31 | MSBuildRelease buildDir "Build" slnReferences 32 | |> Log "AppBuild-Output: " 33 | ) 34 | 35 | Target "Test" (fun _ -> 36 | ActivateFinalTarget "DeployTestResults" 37 | !! (testDir @@ "/*.Specs.dll") 38 | |> MSpec (fun p -> 39 | {p with 40 | HtmlOutputDir = testOutputDir}) 41 | ) 42 | 43 | FinalTarget "DeployTestResults" (fun () -> 44 | !! (testOutputDir @@ "/**/*.*") 45 | |> Zip testOutputDir (deployDir @@ "MSpecResults.zip") 46 | ) 47 | 48 | Target "BuildZip" (fun _ -> 49 | !! (buildDir @@ "**/*.*") 50 | |> Zip buildDir (deployDir @@ sprintf "%s-%s.zip" projectName version) 51 | ) 52 | 53 | Target "Default" DoNothing 54 | 55 | // Build order 56 | "Clean" 57 | ==> "BuildApp" 58 | ==> "Test" 59 | ==> "BuildZip" 60 | ==> "Default" 61 | 62 | // start build 63 | RunParameterTargetOrDefault "target" "Default" 64 | -------------------------------------------------------------------------------- /paket.dependencies: -------------------------------------------------------------------------------- 1 | source https://www.nuget.org/api/v2/ 2 | 3 | nuget FeatureSwitcher.Configuration 1.0.1 4 | nuget FeatureSwitcher.Contexteer 1.0.1 5 | nuget Machine.Fakes.FakeItEasy 2.7.0 6 | nuget Machine.Specifications.Should 0.8.0 7 | 8 | group Build 9 | source https://nuget.org/api/v2 10 | 11 | nuget FAKE 12 | 13 | group Test 14 | source https://nuget.org/api/v2 15 | 16 | nuget Machine.Specifications.Runner.Console 0.9.1 17 | -------------------------------------------------------------------------------- /paket.lock: -------------------------------------------------------------------------------- 1 | NUGET 2 | remote: https://www.nuget.org/api/v2 3 | specs: 4 | Contexteer (1.0.0) 5 | FakeItEasy (1.25.3) 6 | FeatureSwitcher (1.1.0) 7 | FeatureSwitcher.Configuration (1.0.1) 8 | FeatureSwitcher (>= 1.0.1) 9 | FeatureSwitcher.Contexteer (1.0.1) 10 | Contexteer (>= 1.0.0) 11 | FeatureSwitcher (>= 1.0.1) 12 | Machine.Fakes (2.7) 13 | Machine.Specifications (>= 0.9.1) 14 | Machine.Fakes.FakeItEasy (2.7.0) 15 | FakeItEasy (>= 1.25.3) 16 | Machine.Fakes (2.7) 17 | Machine.Specifications (0.9.3) 18 | Machine.Specifications.Should (0.8.0) 19 | Machine.Specifications (>= 0.9 < 1.0) 20 | 21 | GROUP Build 22 | NUGET 23 | remote: https://www.nuget.org/api/v2 24 | specs: 25 | FAKE (4.12.0) 26 | 27 | GROUP Test 28 | NUGET 29 | remote: https://www.nuget.org/api/v2 30 | specs: 31 | Machine.Specifications.Runner.Console (0.9.1) 32 | --------------------------------------------------------------------------------