Esempio n. 1
0
        public async void new_translator_should_return_with_app_model_if_model_is_invalid()
        {
            //arrange
            var inValidModel = new UserModel {
                Name = "test name"
            };

            //act
            var sut  = new AdminControllerBuilder().Build();
            var view = await sut.NewTranslator(inValidModel) as ViewResult;

            //assert
            Assert.NotNull(view);
            Assert.NotNull(view.Model);
            Assert.IsAssignableFrom(typeof(UserModel), view.Model);

            sut.AssertPostAndAntiForgeryTokenAttribute("NewTranslator", new[] { typeof(UserModel) });
        }
Esempio n. 2
0
        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 sut = new AdminControllerBuilder().WithUserService(userService.Object)
                      .Build();
            var view = await sut.NewTranslator(validModel) as RedirectResult;

            //assert
            Assert.NotNull(view);
            Assert.AreEqual(view.Url, "/admin/users");
            Assert.IsInstanceOf <BaseController>(sut);

            userService.Verify(x => x.Create(It.IsAny <UserModel>(), SetLocaleRole.Translator.Value), Times.Once);
            sut.AssertPostAndAntiForgeryTokenAttribute("NewTranslator", new[] { typeof(UserModel) });
        }