Skip to content

Commit

Permalink
+semver:major Moved builders into conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
david-driscoll committed May 27, 2019
1 parent d51a0da commit 89a6202
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 5 deletions.
2 changes: 0 additions & 2 deletions Common.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
<PackageReference Update="Microsoft.Extensions.DependencyModel" Version="2.1.0" />
<PackageReference Update="Microsoft.Extensions.DiagnosticAdapter" Version="2.1.0" />
<PackageReference Update="Microsoft.Extensions.Logging.Abstractions" Version="2.1.0" />
<PackageReference Update="Rocket.Surgery.Builders" Version="3.2.1" />
<PackageReference Update="Rocket.Surgery.Builders.Abstractions" Version="3.2.1" />
<PackageReference Update="System.Diagnostics.DiagnosticSource" Version="4.5.1" />
</ItemGroup>
<ItemGroup>
Expand Down
21 changes: 21 additions & 0 deletions Conventions.sln
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.DependencyThree", "s
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.DependencyTwo", "sample\Sample.DependencyTwo\Sample.DependencyTwo.csproj", "{80FA44CA-BF0F-4783-835E-416386696FAA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rocket.Surgery.Builders.Abstractions", "src\Builders.Abstractions\Rocket.Surgery.Builders.Abstractions.csproj", "{FE33B09D-9E3B-4142-81D4-2D97588F37B4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rocket.Surgery.Builders", "src\Builders\Rocket.Surgery.Builders.csproj", "{28596266-337B-4078-8A3B-B001B267B46F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rocket.Surgery.Builders.Tests", "test\Builders.Tests\Rocket.Surgery.Builders.Tests.csproj", "{B39895CC-6339-4939-8B01-282CDDBBD76F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -82,6 +88,18 @@ Global
{80FA44CA-BF0F-4783-835E-416386696FAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{80FA44CA-BF0F-4783-835E-416386696FAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{80FA44CA-BF0F-4783-835E-416386696FAA}.Release|Any CPU.Build.0 = Release|Any CPU
{FE33B09D-9E3B-4142-81D4-2D97588F37B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FE33B09D-9E3B-4142-81D4-2D97588F37B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FE33B09D-9E3B-4142-81D4-2D97588F37B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FE33B09D-9E3B-4142-81D4-2D97588F37B4}.Release|Any CPU.Build.0 = Release|Any CPU
{28596266-337B-4078-8A3B-B001B267B46F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28596266-337B-4078-8A3B-B001B267B46F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28596266-337B-4078-8A3B-B001B267B46F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28596266-337B-4078-8A3B-B001B267B46F}.Release|Any CPU.Build.0 = Release|Any CPU
{B39895CC-6339-4939-8B01-282CDDBBD76F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B39895CC-6339-4939-8B01-282CDDBBD76F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B39895CC-6339-4939-8B01-282CDDBBD76F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B39895CC-6339-4939-8B01-282CDDBBD76F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -93,6 +111,9 @@ Global
{0AE273C5-B6D1-451D-BBE8-EC004AE90ED5} = {C4335B9B-E327-4B83-A228-735873972363}
{95BE10B9-389E-4709-A359-76143AF3800C} = {C4335B9B-E327-4B83-A228-735873972363}
{80FA44CA-BF0F-4783-835E-416386696FAA} = {C4335B9B-E327-4B83-A228-735873972363}
{FE33B09D-9E3B-4142-81D4-2D97588F37B4} = {52F62811-7776-42E4-921F-E1F9202F8074}
{28596266-337B-4078-8A3B-B001B267B46F} = {52F62811-7776-42E4-921F-E1F9202F8074}
{B39895CC-6339-4939-8B01-282CDDBBD76F} = {F2329C11-7A3F-4D18-A665-6FA91A922DBF}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7EF3BE50-98BC-4A67-A514-EF6078B1DA37}
Expand Down
16 changes: 16 additions & 0 deletions src/Builders.Abstractions/IBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;

namespace Rocket.Surgery.Builders
{
/// <summary>
/// A common interface for creating builder classes
/// </summary>
public interface IBuilder
{
/// <summary>
/// A central location for sharing state between components during the convention building process.
/// </summary>
IDictionary<object, object> Properties { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
</PropertyGroup>
</Project>
58 changes: 58 additions & 0 deletions src/Builders/Builder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;

namespace Rocket.Surgery.Builders
{
/// <summary>
/// Abstract base class for implementing a builder
/// </summary>
public abstract class Builder : IBuilder
{
private readonly IDictionary<object, object> _items;

protected Builder(IDictionary<object, object> properties)
{
_items = properties ?? new Dictionary<object, object>();
}

public virtual object this[object item]
{
get => _items.TryGetValue(item, out var value) ? value : null;
set => _items[item] = value;
}

public IDictionary<object, object> Properties => _items;
}

/// <summary>
/// Abstract base class for creating builders that are attached to some parent builder
/// Useful for creating sub builds that live for a short period to augment the parent.
/// </summary>
/// <typeparam name="TBuilder"></typeparam>
public abstract class Builder<TBuilder> : Builder
where TBuilder : class
{
/// <summary>
/// Constructs a Builder&lt;TBuilder&gt; with the parent instance
/// </summary>
/// <param name="parent">The parent builder TBuilder</param>
protected Builder(TBuilder parent, IDictionary<object, object> properties) : base(properties)
{
Parent = parent ?? throw new ArgumentNullException(nameof(parent));
}

/// <summary>
/// Get the parent value from this builder
/// </summary>
public TBuilder Parent { get; }

/// <summary>
/// Exit the current builder and return the parent
/// </summary>
/// <returns></returns>
public virtual TBuilder Exit()
{
return Parent;
}
}
}
9 changes: 9 additions & 0 deletions src/Builders/Rocket.Surgery.Builders.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Builders.Abstractions\Rocket.Surgery.Builders.Abstractions.csproj" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<TargetFrameworks>netstandard2.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Builders.Abstractions\Rocket.Surgery.Builders.Abstractions.csproj" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
<PackageReference Include="Rocket.Surgery.Builders.Abstractions" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/Conventions/Rocket.Surgery.Conventions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<PackageReference Include="Microsoft.Extensions.DependencyModel" />
<PackageReference Include="Microsoft.Extensions.DiagnosticAdapter" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
<PackageReference Include="Rocket.Surgery.Builders" />
<ProjectReference Include="..\Builders\Rocket.Surgery.Builders.csproj" />
</ItemGroup>
</Project>
61 changes: 61 additions & 0 deletions test/Builders.Tests/BuilderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Collections.Generic;
using FluentAssertions;
using Rocket.Surgery.Extensions.Testing;
using Xunit;
using Xunit.Abstractions;

namespace Rocket.Surgery.Builders.Tests
{
public class BuilderTests : AutoTestBase
{
class TestGenericValueContainer : Builder
{
public TestGenericValueContainer() : base(new Dictionary<object, object>()) {}
}


public BuilderTests(ITestOutputHelper outputHelper) : base(outputHelper) { }

[Fact]
public void ReturnsNullOfNoValue()
{
var container = new TestGenericValueContainer();

container[typeof(string)].Should().BeNull();
}


[Fact]
public void SetAValue()
{
var container = new TestGenericValueContainer();

container[typeof(string)] = "abc";

container[typeof(string)].Should().Be("abc");
}

class ChildBuilder : Builder<TestGenericValueContainer>
{
public ChildBuilder(TestGenericValueContainer parent) : base(parent, new Dictionary<object, object>())
{
}
}

[Fact]
public void ShouldHaveAParent()
{
var parent = new TestGenericValueContainer();
var builder = new ChildBuilder(parent);
builder.Parent.Should().BeSameAs(parent);
}

[Fact]
public void ShouldExitProperly()
{
var parent = new TestGenericValueContainer();
var builder = new ChildBuilder(parent);
builder.Exit().Should().BeSameAs(parent);
}
}
}
9 changes: 9 additions & 0 deletions test/Builders.Tests/Rocket.Surgery.Builders.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;netcoreapp2.1;netcoreapp2.2</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Builders.Abstractions\Rocket.Surgery.Builders.Abstractions.csproj" />
<ProjectReference Include="..\..\src\Builders\Rocket.Surgery.Builders.csproj" />
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions test/Builders.Tests/xunit.runner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"shadowCopy": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ProjectReference Include="..\..\sample\Sample.DependencyOne\Sample.DependencyOne.csproj" />
<ProjectReference Include="..\..\sample\Sample.DependencyThree\Sample.DependencyThree.csproj" />
<ProjectReference Include="..\..\sample\Sample.DependencyTwo\Sample.DependencyTwo.csproj" />
<ProjectReference Include="..\..\src\Builders\Rocket.Surgery.Builders.csproj" />
<ProjectReference Include="..\..\src\Conventions\Rocket.Surgery.Conventions.csproj" />
<PackageReference Include="Rocket.Surgery.Builders" />
</ItemGroup>
</Project>

0 comments on commit 89a6202

Please sign in to comment.