public void shouldReturnTrueWithAValidUser() { //https://github.com/Moq/moq4/wiki/Quickstart //you should use rhino mock or MOQ //more info http://www.developerhandbook.com/2013/08/30/csharp-writing-unit-tests-with-nunit-and-moq/ //http://www.c-sharpcorner.com/UploadFile/dacca2/understand-stub-mock-and-fake-in-unit-testing/ //arrange Watchful watchful = new Watchful(); User user = new User("aliCate", "1234"); //prepare mock var userRepositoryMock = new Mock<UserRepository>(); userRepositoryMock.Setup(it => it.findUser(user.Username)).Returns(new User("aliCate", "1234")); //setup mock watchful.UserRepository = userRepositoryMock.Object; //act bool result = watchful.Validate(user); //arrange Assert.IsTrue(result); userRepositoryMock.Verify(it => it.findUser(user.Username)); }
public bool Validate(User user) { return false; }