Skip to content

Instantly share code, notes, and snippets.


fbanke/UserServiceTest.cs Secret

Created Jan 1, 2021
What would you like to do?
using System;
using Moq;
using Xunit;
namespace UnitTests
public class UserServiceTest
public void Should_GivenValidCreateUserRequest_CallUserServiceWithMappedData()
var addUserRequest = new AddUserRequest{ Username = "foo", Email = ""};
var userService = new Mock<UserService>();
var sut = new UserController(userService.Object);
userService.Verify(mock => mock.Create("foo", ""), 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);
return AddUserResponse.OK();
return AddUserResponse.Fail();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment