1

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?

1 Answer 1

0

You are intergration testing, not unit testing. To properly unit test, you need to test without the db by using mocking objects.

Sign up to request clarification or add additional context in comments.

1 Comment

Although you are right your answer is very compressed. Could you please guide the user how to do first steps in this direction or at least link to a similar question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.