public void AddUser() { // Arrange DBSetup(); Mock<IUserService> userService = new Mock<IUserService>(); userService.Setup(x => x.AddUser(It.IsAny<IDocumentSession>(), It.IsAny<User>())).Returns("users/1"); UserApiController controller = new UserApiController(userService.Object); // Act var bindingModel = new AddUserBindingModel() { FirstName = "TestFN", LastName = "TestLN", Email = "*****@*****.**", StreetAddress = "TestSA", City = "TestCity", State = "TestState", Zip = "99999" }; IHttpActionResult result = controller.AddUser(bindingModel); // Assert Assert.IsNotNull(result); Assert.AreEqual(typeof(OkResult), result.GetType()); }
public void DeleteUser() { // Arrange DBSetup(); Mock<IUserService> userService = new Mock<IUserService>(); userService.Setup(x => x.DeleteUser(It.IsAny<IDocumentSession>(), It.IsAny<string>())).Returns("users/1"); UserApiController controller = new UserApiController(userService.Object); // Act IHttpActionResult result = controller.DeleteUser("1"); // Assert Assert.IsNotNull(result); Assert.AreEqual(typeof(OkResult), result.GetType()); }
public void GetAllUsers() { // Arrange DBSetup(); var userModel1 = new User() { Id = "users/1", FirstName = "TestFN", LastName = "TestLN", Email = "*****@*****.**", StreetAddress = "TestSA", City = "TestCity", State = "TestState", Zip = "99999" }; var userModel2 = new User() { Id = "users/2", FirstName = "TestFN", LastName = "TestLN", Email = "*****@*****.**", StreetAddress = "TestSA", City = "TestCity", State = "TestState", Zip = "99999" }; Mock<IUserService> userService = new Mock<IUserService>(); userService.Setup(x => x.GetAllUsers(It.IsAny<IDocumentSession>())).Returns(new List<User>() { userModel1, userModel2 }); UserApiController controller = new UserApiController(userService.Object); // Act IHttpActionResult result = controller.GetAllUsers(); // Assert Assert.IsNotNull(result); Assert.AreEqual(typeof(OkNegotiatedContentResult<List<User>>), result.GetType()); }
public void DeleteUserFail() { // Arrange DBSetup(); Mock<IUserService> userService = new Mock<IUserService>(); userService.Setup(x => x.UpdateUser(It.IsAny<IDocumentSession>(), It.IsAny<User>())).Returns<User>(null); UserApiController controller = new UserApiController(userService.Object); // Act IHttpActionResult result = controller.DeleteUser("1"); // Assert Assert.IsNotNull(result); Assert.AreEqual(typeof(BadRequestErrorMessageResult), result.GetType()); Assert.AreEqual((result as BadRequestErrorMessageResult).Message, "User not found!"); }
public void UpdateUserFail() { // Arrange DBSetup(); Mock<IUserService> userService = new Mock<IUserService>(); userService.Setup(x => x.UpdateUser(It.IsAny<IDocumentSession>(), It.IsAny<User>())).Returns<User>(null); UserApiController controller = new UserApiController(userService.Object); // Act var userViewModel = new UserViewModel() { Id = "users/1", FirstName = "TestFN", LastName = "TestLN", Email = "*****@*****.**", StreetAddress = "ChangeTestSA", City = "TestCity", State = "TestState", Zip = "99999" }; IHttpActionResult result = controller.UpdateUser(userViewModel); // Assert Assert.IsNotNull(result); Assert.AreEqual(typeof(BadRequestErrorMessageResult), result.GetType()); Assert.AreEqual((result as BadRequestErrorMessageResult).Message, "User not found!"); }