Skip to content

Instantly share code, notes, and snippets.

@fbanke
Created January 1, 2021 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbanke/1e84136b36015570a70450ed6259e059 to your computer and use it in GitHub Desktop.
Save fbanke/1e84136b36015570a70450ed6259e059 to your computer and use it in GitHub Desktop.
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