Skip to content

Instantly share code, notes, and snippets.

@fbanke

fbanke/UserServiceTest.cs Secret

Created Jan 1, 2021
Embed
What would you like to do?
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