using System; using System.Collections.Generic; using System.Linq.Expressions; using MyWebsite.Controllers; using MyWebsite.Repositories; using NSubstitute; using NUnit.Framework;
[Test] publicvoidSearchUser() { // Arrange var query = "test"; var model = new UserModel { Id = 1 }; _fakeRepository.Find(Arg.Any<Expression<Func<UserModel, bool>>>()) .Returns(new List<UserModel> { model });
// Act var actual = _target.Get(query);
// Assert Assert.IsTrue(actual.IsSuccess); }
[Test] publicvoidGetUser() { // Arrange var model = new UserModel { Id = 1 }; _fakeRepository.FindById(Arg.Any<int>()).Returns(model);
// Act var actual = _target.Get(model.Id);
// Assert Assert.IsTrue(actual.IsSuccess); }
[Test] publicvoidCreateUser() { // Arrange var model = new UserModel();
// Act var actual = _target.Post(model);
// Assert Assert.IsTrue(actual.IsSuccess); }
[Test] publicvoidUpdateUser() { // Arrange var model = new UserModel { Id = 1 };
// Act var actual = _target.Put(model.Id, model);
// Assert Assert.IsTrue(actual.IsSuccess); }
[Test] publicvoidDeleteUser() { // Arrange var model = new UserModel { Id = 1 };