public ActionResult Create(BoardCreateModel data)
 {
     int result = db_.Add( new BoardEntity {
         Title = data.Title,
         Text = data.Text
     } );
     
     return Redirect("/Board/Show/" + result);
 }
 public ActionResult Create(BoardCreateModel data)
 {
     var result = db_.Boards.Add( new BoardEntity {
         Title = data.Title,
         Text = data.Text
     } );
     
     db_.SaveChanges();
     return Redirect("/Board/Show/" + result.Id);
 }
        public void PostCreate()
        {
            // モック用意
            var mockset = new Mock<DbSet<BoardEntity>>();
            var mockcontext = new Mock<BoardDbContext>();

            // ダミーデータの生成
            var model = new BoardCreateModel {
                Title = "題名",
                Text = "本文"
            };

            // Addの返り値フック
            var dummy = new BoardEntity { Id = 1, Title = model.Title, Text = model.Text };
            mockset.As<IDbSet<BoardEntity>>().Setup( m => m.Add( It.IsAny<BoardEntity>() ) ).Returns( dummy );

            mockcontext.Setup( m => m.Boards ).Returns( mockset.Object );

            var controller = new BoardController(mockcontext.Object);
            var result = controller.Create(model) as RedirectResult;
            Assert.IsNotNull( result );

            // Addが呼ばれたかチェック
            mockset.Verify( m => m.Add( It.Is<BoardEntity>( o => o.Title == model.Title && o.Text == model.Text ) ), Times.Once );

            // SaveChangesがよばれたかチェック
            mockcontext.Verify( m => m.SaveChanges(), Times.Once );

            Assert.AreEqual( result.Url, "/Board/Show/1" );
        }