Created
February 1, 2018 22:53
-
-
Save diffused/5dbaf697bd759979598aa3a1052b22ed to your computer and use it in GitHub Desktop.
Who has the best flow?
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 System.Linq; | |
using Xunit; | |
using FluentAssertions; | |
using FakeItEasy; | |
namespace HipHopFlow | |
{ | |
public class FlowService | |
{ | |
readonly IDudeService _dudeService; | |
const string THE_ONE = "Scribe"; | |
public FlowService(IDudeService dudeService) | |
{ | |
_dudeService = dudeService; | |
} | |
public List<Dude> DudesThatFlowLikeThis() | |
{ | |
var dudes = _dudeService.All(); | |
var responseDudes = dudes | |
.Where(dude => dude.Name == THE_ONE) | |
.ToList(); | |
return responseDudes; | |
} | |
} | |
public class Dude | |
{ | |
public string Name { get; set; } | |
} | |
public interface IDudeService | |
{ | |
List<Dude> All(); | |
} | |
public class ScribeServiceFlowLikeThisShould | |
{ | |
readonly IDudeService _dudeService; | |
readonly FlowService _sut; | |
public ScribeServiceFlowLikeThisShould() | |
{ | |
_dudeService = A.Fake<IDudeService>(); | |
_sut = new FlowService(_dudeService); | |
} | |
[Fact] | |
public void Return_NotMany() | |
{ | |
var expectedName = "Scribe"; | |
var dudeFixture = new List<Dude> | |
{ | |
new Dude { Name = "JahRule" }, | |
new Dude { Name = "50 Cent" }, | |
new Dude { Name = expectedName }, | |
}; | |
A.CallTo(() => _dudeService.All()).Returns(dudeFixture); | |
var result = _sut.DudesThatFlowLikeThis(); | |
result.First().Name.Should().Be(expectedName); | |
} | |
[Fact] | |
public void Return_IfAny() | |
{ | |
// no scribe | |
var dudeFixture = new List<Dude> | |
{ | |
new Dude { Name = "JahRule" }, | |
new Dude { Name = "50 Cent" }, | |
}; | |
A.CallTo(() => _dudeService.All()).Returns(dudeFixture); | |
var result = _sut.DudesThatFlowLikeThis(); | |
result.Count.Should().Be(0); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment