-
-
Save fbanke/1e84136b36015570a70450ed6259e059 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; | |
using Moq; | |
using Xunit; | |
namespace UnitTests | |
{ | |
public class UserServiceTest | |
{ | |
[Fact] | |
public void Should_GivenValidCreateUserRequest_CallUserServiceWithMappedData() | |
{ | |
var addUserRequest = new AddUserRequest{ Username = "foo", Email = "foo@bar.com"}; | |
var userService = new Mock<UserService>(); | |
var sut = new UserController(userService.Object); | |
sut.AddUser(addUserRequest); | |
userService.Verify(mock => mock.Create("foo", "foo@bar.com"), Times.Once); | |
} | |
} | |
public class UserController | |
{ | |
private UserService _userService; | |
public UserController(UserService userService) | |
{ | |
_userService = userService; | |
} | |
public AddUserResponse AddUser(AddUserRequest addUserRequest){ | |
var created = _userService.Create(addUserRequest.Username, addUserRequest.Email); | |
if(created){ | |
return AddUserResponse.OK(); | |
}else{ | |
return AddUserResponse.Fail(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment