コード例 #1
0
        public async void words_should_return_with_word_model()
        {
            //arrange
            var list = new List <Word> {
                new Word {
                    Id = 1
                }, new Word {
                    Id = 2
                }
            };
            var wordService = new Mock <IWordService>();

            wordService.Setup(x => x.GetByUserId(1, 1))
            .Returns(Task.FromResult(new PagedList <Word>(1, 2, 3, list)));

            //act
            var sut = new UserControllerBuilder().WithWordService(wordService.Object)
                      .Build();

            var view = await sut.Words(1, 1);

            var model = view.Model as PageModel <WordModel>;

            //assert
            Assert.NotNull(view);
            Assert.NotNull(model);
            Assert.IsInstanceOf <BaseController>(sut);
            Assert.IsAssignableFrom <PageModel <WordModel> >(view.Model);
            Assert.AreEqual(model.Items.Count, list.Count);
            CollectionAssert.AllItemsAreUnique(model.Items);

            wordService.Verify(x => x.GetByUserId(1, 1), Times.Once);

            sut.AssertGetAttribute(ActionNameWords, new[] { typeof(int), typeof(int) });
        }