I need to have a logged in user for each of my unit tests, which forces me to do an async call (the login) in my test SetUp.
I can't find a way to make this work, I either get null pointer exceptions, or invalid signatures for setup.
public async void SetUp() {}
This makes all my test fail with my objects probably because I'm not logged in.
public async Task SetUp() {}
Makes all my test ignored because the setup has an invalid signature.
And I would like not to have to copy my X lines of setup in each test, since they're all exactly the same and... that's what the setup is for.
What am I missing ? this appears like a trivial problem.
Here is what I have now, for the sake of showing something
CreateTicketViewModel _viewModel;
[SetUp()]
public async void SetUp() //I have tried using Task instead of void
{
IUserService userService = Dependency.Instance.Resolve<IUserService>();
await userService.LoginAsync(this.UserName, this.Password);
_viewModel = Dependency.Instance.Resolve<CreateTicketViewModel>();
}
[TearDown()]
public void TearDown()
{
_viewModel = null; // I have tried removing this
}
[Test()]
public void Initialization()
{
// If I put what's in SetUp here and add "async" before void,
// it works just fine
Assert.IsNotNull(_viewModel);
Assert.IsNotNull(_viewModel.Ticket);
}
IUserServicein Setup method alone?