Skip to content

Instantly share code, notes, and snippets.

@derekgreer
Created March 6, 2015 00:11
Show Gist options
  • Save derekgreer/3cad52555a2f7351d3f6 to your computer and use it in GitHub Desktop.
Save derekgreer/3cad52555a2f7351d3f6 to your computer and use it in GitHub Desktop.
My NUnit Test
public class UserServiceSpecs
{
[Subcutaneous]
public class when_creating_an_inactive_account : SubjectBuilderContext
{
const string UserName = "testuser";
static AccountInfo _accountInfo;
static ExpectedObject _expectedUser;
static IUserService _userService;
Cleanup after = () => DnxDatabase.DeleteUser(UserName);
Establish context = () =>
{
_userService = BuildSubject<IUserService>()
.WithContext<UserServiceContext>()
.WithMock<IIdentityMessageService>()
.Build();
_accountInfo = new AccountInfo
{
Email = "test@test.com",
Roles = new[] {"admin", "user"},
UserName = UserName
};
_expectedUser = new
{
UserName,
IsActive = false,
PasswordHash = Expect.Null(),
Email = "test@test.com"
}.ToExpectedObject();
};
Because of = () => _userService.CreateAccount(_accountInfo);
It should_create_expected_account = () => _expectedUser.ShouldMatch(DnxDatabase.GetUserByUserName(UserName));
It should_send_the_activation_email_to_the_user = () => For<IIdentityMessageService>().Verify(x => x.SendAsync(Moq.It.IsAny<IdentityMessage>()), Times.Once());
}
}
@bsommardahl
Copy link

Wait.... wahhhh?? How?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment