Example #1
0
        public async Task EditPost_ReturnsAViewResult_WithInvalidModel()
        {
            mockModelBindingHelperAdaptor.Setup(m => m.TryUpdateModelAsync(It.IsAny <ControllerBase>(), It.IsAny <Student>(), It.IsAny <string>(), It.IsAny <Expression <Func <Student, object> >[]>()))
            .Callback(() => sut.ModelState.AddModelError("mymodelerror", "my error message"))
            .Returns(Task.FromResult(false));

            var result = await sut.EditPost(1);

            Assert.IsType <ViewResult>(result);

            Assert.True(((ViewResult)result).ViewData.ModelState.ContainsKey("mymodelerror"));
        }