Created
August 27, 2018 07:11
-
-
Save marhoily/abf3550bf284b16ae1f1b673b55f5f88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using FakeItEasy; | |
using FluentAssertions; | |
using Xunit; | |
namespace DesignPatters | |
{ | |
public class Pattern2 | |
{ | |
sealed class Creation | |
{ | |
private readonly List<string> _features = new List<string>(); | |
public Creation AddHead() { _features.Add("head"); return this; } | |
public Creation AddArm() { _features.Add("arm"); return this; } | |
public Creation AddLeg() { _features.Add("leg"); return this;} | |
public Beast Create() => new Beast(_features); | |
} | |
sealed class Beast | |
{ | |
public IReadOnlyCollection<string> Features { get; } | |
public Beast(IReadOnlyCollection<string> features) { Features = features; } | |
} | |
[Fact] | |
public void Test() | |
{ | |
var beast = new Creation() | |
.AddHead() | |
.AddLeg().AddLeg() | |
.AddArm() | |
.Create(); | |
beast.Features.Should() | |
.Equal("head", "leg", "leg", "arm"); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment