Created
October 13, 2014 11:12
-
-
Save blairconrad/a8f90d9d8ea04cee5e84 to your computer and use it in GitHub Desktop.
26329057/fakeiteasy-throws-expectationexception - Blair's passing test
This file contains hidden or 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
internal class JorgBTests | |
{ | |
public interface IUser | |
{ | |
string Username { get; } | |
} | |
internal class UserSignupRequest | |
{ | |
public string Username { get; set; } | |
public DateTime DateOfBirth { get; set; } | |
public string Password { get; set; } | |
} | |
public interface IDataAccessLayer | |
{ | |
Task<bool> ExistsUserAsync(string username, CancellationToken cancellationToken); | |
Task<IUser> CreateUserAsync(string username, string password, DateTime dateOfBirth, | |
CancellationToken cancellationToken); | |
} | |
[Test] | |
public void Test() | |
{ | |
var validSignupRequest = new UserSignupRequest() | |
{ | |
Username = "meh-spacey_space", | |
DateOfBirth = DateTime.Now.Subtract(TimeSpan.FromDays(365*35)), | |
Password = "someproper_passw*rd" | |
}; | |
var testDataAccessLayer = A.Fake<IDataAccessLayer>(options => options.Strict()); | |
var fakeUserInstance = A.Fake<IUser>(); | |
A.CallTo(() => fakeUserInstance.Username).Returns(validSignupRequest.Username); | |
A.CallTo(() => testDataAccessLayer.ExistsUserAsync(validSignupRequest.Username, CancellationToken.None)) | |
.Returns(false); // works | |
A.CallTo( | |
() => | |
testDataAccessLayer.CreateUserAsync( | |
validSignupRequest.Username, | |
validSignupRequest.Password, | |
validSignupRequest.DateOfBirth, | |
CancellationToken.None)) | |
.Returns(fakeUserInstance); // also works | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment