Skip to content

Instantly share code, notes, and snippets.

@diffused
Created February 1, 2018 22:53
Show Gist options
  • Save diffused/5dbaf697bd759979598aa3a1052b22ed to your computer and use it in GitHub Desktop.
Save diffused/5dbaf697bd759979598aa3a1052b22ed to your computer and use it in GitHub Desktop.
Who has the best flow?
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