So my problem is as follows...for a project we are bulding an api using RavenDb and Nancy. So my question is about unit testing...we use embeded db, which runs in memory as suggested many times. , how to proper unit test end points. For example, we have a endpoint create account. For that we need to have a user so he can create account. What is the best way to simulate that?
Currently we do it like this:
[Test]
public void UserCanAddAccountToCompany()
{
var user =
new User
{
Name = Guid.NewGuid().ToString(),
Email = Guid.NewGuid().ToString(),
Pwd = "password",
CompanyReference = new CompanyReference { Id = Guid.NewGuid().ToString(), Name = Guid.NewGuid().ToString() }
};
var response = new TestBrowser<User>("User/SignUp", user).Response;
var paramUserAccount = new ParamUserAccount()
{
User = response.Body.DeserializeJson<Result>().User,
Account = new Account() { Name = Guid.NewGuid().ToString() }
};
var response2 = new TestBrowser<ParamUserAccount>("account/create", paramUserAccount).Response;
var res = response2.Body.DeserializeJson<Result>();
Assert.NotNull(res.Account.Id);
Assert.NotNull(res.Account.Name);
}
So we create a user , call user signup end point and then take the params from response and call creat accoutn end point. The obvious problem with this approach is that if you do a change in signup endpoint and for some reason you break it, all tests like this will fail.
So my question is...what's the right approach on that?