Skip to content

Commit

Permalink
Move tests closer to working
Browse files Browse the repository at this point in the history
  • Loading branch information
Boggin committed Aug 23, 2019
1 parent 6c0247f commit 994b889
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 43 deletions.
2 changes: 1 addition & 1 deletion FeatureFlagger.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 25,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FeatureFlagger.Tests", "tes
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FeatureFlagger.ConfigurationWriters", "src\FeatureFlagger.ConfigurationWriters\FeatureFlagger.ConfigurationWriters.csproj", "{46131F8A-055F-4CD4-8A47-405DF4103C68}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FeatureFlagger.Authorisation", "src\FeatureFlagger.Authorisation\FeatureFlagger.Authorisation.csproj", "{1B510588-5AF7-48AD-AED6-A7F04452799D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FeatureFlagger.Authorisation", "src\FeatureFlagger.Authorisation\FeatureFlagger.Authorisation.csproj", "{1B510588-5AF7-48AD-AED6-A7F04452799D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
5 changes: 5 additions & 0 deletions NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 7,8 @@
[Paket](https://fsprojects.github.io/Paket/) is an alternative to NuGet.

Some setup is required before you can being. Refer to the guides.

### TODO

- Make FeatureFlagger a meta-package and create FF.Core.
- Use MEF meta data instead of "name" for choosing readers and writers.
8 changes: 1 addition & 7 deletions src/FeatureFlagger.ConfigurationReaders/ConfigReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 7,10 @@
using System.Linq;
using FeatureFlagger.Domain;

[ExportMetadata("Name", "CONFIG")]
[Export(typeof(IConfigurationReader))]
public class ConfigReader : IConfigurationReader
{
private ConfigReader()
{
Name = "CONFIG";
}

public string Name { get; }

public Feature Read(string featureName, IEnumerable<Feature> features)
{
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 6,6 @@

public interface IConfigurationReader
{
/// <summary>
/// The Name of the implementation.
/// </summary>
string Name { get; }

/// <summary>
/// Read a feature from the configuration.
/// </summary>
Expand Down
7 changes: 0 additions & 7 deletions src/FeatureFlagger.ConfigurationReaders/StoreReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 12,6 @@ namespace FeatureFlagger.ConfigurationReaders
[Export(typeof(IConfigurationReader))]
public class StoreReader : IConfigurationReader
{
private StoreReader()
{
Name = "STORE";
}

public string Name { get; }

public Feature Read(string featureName, IEnumerable<Feature> features)
{
return
Expand Down
11 changes: 8 additions & 3 deletions src/FeatureFlagger/FeatureFlagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 6,7 @@
using System.Composition.Hosting;
using System.Configuration;
using System.Linq;

using System.Reflection;
using Behaviours;
using ConfigurationReaders;
using ConfigurationWriters;
Expand All @@ -30,7 30,7 @@ private FeatureFlagger()
[ImportMany]
public static IEnumerable<IBehaviour> Behaviours { get; private set; }

[ImportMany]
[ImportMany(typeof(IConfigurationReader))]
private static IEnumerable<IConfigurationReader> Readers { get; set; }

[ImportMany]
Expand Down Expand Up @@ -79,7 79,12 @@ private static void SetWriter()

private void SetImports()
{
var configuration = new ContainerConfiguration().WithAssembly(typeof(IBehaviour).Assembly);
var configuration =
new ContainerConfiguration().WithAssemblies(
new List<Assembly> {
typeof(IBehaviour).Assembly,
typeof(IConfigurationReader).Assembly,
typeof(IConfigurationWriter).Assembly });
var container = configuration.CreateContainer();
container.SatisfyImports(this);
Behaviours = container.GetExports<IBehaviour>();
Expand Down
18 changes: 18 additions & 0 deletions tests/FeatureFlagger.Tests/App.config
Original file line number Diff line number Diff line change
@@ -0,0 1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="features" type="FeatureFlagger.ConfigurationReaders.FeaturesSection, FeatureFlagger.ConfigurationReaders" />
</configSections>
<features>
<flag name="example" enabled="true"></flag>
<flag name="disabled" enabled="false"></flag>
<flag name="from" enabled="true">
<from date="2015-03-20" />
</flag>
<flag name="test" enabled="true">
<from date="2015-03-20" />
<rollout percentage="25" basis="user" name="barndoor" />
<fullmoon />
</flag>
</features>
</configuration>
14 changes: 14 additions & 0 deletions tests/FeatureFlagger.Tests/FeatureFlagger.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 2,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<ApplicationIcon />
<Win32Resource />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Moq" Version="4.12.0" />
<PackageReference Include="NSubstitute" Version="4.2.1" />
<PackageReference Include="Shouldly" Version="3.0.2" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.assert" Version="2.4.1" />
<PackageReference Include="xunit.extensibility.execution" Version="2.4.1" />
<PackageReference Include="xunit.runner.console" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\FeatureFlagger.Authorisation\FeatureFlagger.Authorisation.csproj" />
<ProjectReference Include="..\..\src\FeatureFlagger.ConfigurationReaders\FeatureFlagger.ConfigurationReaders.csproj" />
<ProjectReference Include="..\..\src\FeatureFlagger\FeatureFlagger.csproj" />
</ItemGroup>
</Project>
31 changes: 11 additions & 20 deletions tests/FeatureFlagger.Tests/FeatureFlaggerTests.cs
Original file line number Diff line number Diff line change
@@ -1,52 1,43 @@
namespace FeatureFlagger.Tests
{
using Shouldly;
using Xunit;

public class FeatureFlaggerTests
{
[Fact]
public void ShouldUseBasicEnabledFlag()
{
var featureFlag = new ExampleFeatureFlagger();

var isEnabled = featureFlag.IsEnabled();

Assert.True(isEnabled);
featureFlag.IsEnabled().ShouldBeTrue();
}

[Fact]
public void ShouldFailDisabledFlag()
{
var featureFlag = new DisabledFeatureFlagger();

var isEnabled = featureFlag.IsEnabled();

Assert.False(isEnabled);
featureFlag.IsEnabled().ShouldBeFalse();
}

[Fact]
public void ShouldUseFromFlag()
{
var featureFlag = new FromFeatureFlagger();

var isEnabled = featureFlag.IsEnabled();

Assert.True(isEnabled);
featureFlag.IsEnabled().ShouldBeTrue();
}

[Fact]
public void ShouldUseUserFlag()
{
var featureFlag = new UserFeatureFlagger();

var isEnabled = featureFlag.IsEnabled();

Assert.True(isEnabled);
featureFlag.IsEnabled().ShouldBeTrue();
}

[Fact]
public void ShouldFailUserNotListedFlag()
{
var featureFlag = new UnuserFeatureFlagger();

var isEnabled = featureFlag.IsEnabled();

Assert.False(isEnabled);
featureFlag.IsEnabled().ShouldBeFalse();
}
}
}
2 changes: 2 additions & 0 deletions tests/FeatureFlagger.Tests/UserAuthorisationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 12,7 @@

public class UserAuthorisationTests
{
[Fact]
public void ShouldPassCustomAttribute()
{
var attribute =
Expand All @@ -30,6 31,7 @@ public void ShouldPassCustomAttribute()
mockActionContext.Response.StatusCode);
}

[Fact]
public void ShouldNotPassCustomAttribute()
{
var attribute =
Expand Down

0 comments on commit 994b889

Please sign in to comment.