public async void new_translator_should_return_with_app_model_if_model_is_invalid() { // Arrange var inValidModel = new UserModel { Name = "test name" }; // Act var controller = new AdminController(null, null, null); var view = await controller.NewTranslator(inValidModel) as ViewResult; // Assert Assert.NotNull(view); Assert.NotNull(view.Model); var model = view.Model as UserModel; Assert.NotNull(model); controller.AssertPostAttribute("NewTranslator", new[] { typeof(UserModel) }); }
public async void new_translator_should_redirect_if_model_is_valid() { // Arrange var validModel = new UserModel { Name = "test name", Email = "*****@*****.**" }; var userService = new Mock<IUserService>(); userService.Setup(x => x.Create(It.IsAny<UserModel>(), SetLocaleRole.Translator.Value)).Returns(() => Task.FromResult<int?>(1)); // Act var controller = new AdminController(userService.Object, null, null); var view = await controller.NewTranslator(validModel) as RedirectResult; // Assert Assert.NotNull(view); Assert.AreEqual(view.Url, "/admin/users"); userService.Verify(x => x.Create(It.IsAny<UserModel>(), SetLocaleRole.Translator.Value), Times.Once); controller.AssertPostAttribute("NewTranslator", new[] { typeof(UserModel) }); }