Last active
December 22, 2015 00:19
-
-
Save blair55/6388729 to your computer and use it in GitHub Desktop.
Comparing Test Spec Frameworks
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
public class WhenICreateIdentifierFromRequest : WithSubjectAndResult<ScoreResourceIdentifierFactory, ScoreResourceIdentifier> | |
{ | |
static CreateScoreResourceRequest _createScoreResourceRequest; | |
Establish _context = () => The<IObjectHasher>().WhenToldTo(m => m.CreateHashFor(_createScoreResourceRequest)).Return("hash"); | |
Because _of = () => Result = Subject.CreateIdentifierFromRequest(_createScoreResourceRequest); | |
It _createsAHashFromTheObject = () => The<IObjectHasher>().WasToldTo(m => m.CreateHashFor(_createScoreResourceRequest)); | |
It _returnsWithCorrectId = () => Result.Id.ShouldEqual("hash"); | |
} |
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
public class WhenICreateIdentifierFromRequest : GivenA<ScoreResourceIdentifierFactory, ScoreResourceIdentifier> | |
{ | |
private readonly Mock<CreateScoreResourceRequest> _mockCreateScoreResourceRequest = new Mock<CreateScoreResourceRequest>(); | |
protected override void Given() | |
{ | |
base.Given(); | |
GetMock<IObjectHasher>().Setup(m => m.CreateHashFor(_mockCreateScoreResourceRequest.Object)).Returns("hash"); | |
} | |
protected override void When() | |
{ | |
base.When(); | |
Result = Target.CreateIdentifierFromRequest(_mockCreateScoreResourceRequest.Object); | |
} | |
[Then] | |
public void TheObjectHashIsCreated() | |
{ | |
Verify<IObjectHasher>(m => m.CreateHashFor(_mockCreateScoreResourceRequest.Object)); | |
} | |
[Then] | |
public void TheIdIsSetOnTheIdentifier() | |
{ | |
Assert.That(Result.Id, Is.EqualTo("hash")); | |
} | |
} |
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
public class ScoreResourceIdentifierFactory : IScoreResourceIdentifierFactory | |
{ | |
private readonly IObjectHasher _objectHasher; | |
public ScoreResourceIdentifierFactory(IObjectHasher objectHasher) | |
{ | |
_objectHasher = objectHasher; | |
} | |
public ScoreResourceIdentifier CreateIdentifierFromRequest(CreateScoreResourceRequest request) | |
{ | |
var hash = _objectHasher.CreateHashFor(request); | |
var identifier = new ScoreResourceIdentifier {Id = hash}; | |
return identifier; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment