Exemplo n.º 1
0
        public async Task TestAddByBookmarklet_Get()
        {
            // arrange
            var title         = "タイトル1";
            var url           = "http://www.mochaware.jp/";
            var pagedRefLists = ObjectMother.GetPagedRefLists();
            var queryStrs     = new NameValueCollection()
            {
                { "title", title },
            };

            MapConfig.CreateMaps();
            MochaContainer.RegisterTypes = ObjectMother.RegisterAuthenticatedUserContext;
            MochaContainer.GetContainer();

            var mocks = new ControllerContextMocks();

            mocks.UnvalidatedRequestValues.Setup(u => u.QueryString).Returns(queryStrs);
            mocks.Request.Setup(r => r.IsAuthenticated).Returns(true);

            var handlerMock = new Mock <IRefListHandler>();

            handlerMock.Setup(h => h.GetRefListsAsync(It.IsAny <GetRefListsRequest>())).ReturnsAsync(pagedRefLists);

            var controller = new ListController(null, null, handlerMock.Object, null, null);

            controller.ControllerContext = mocks.CreateControllerContext(controller);

            // act
            var result = await controller.AddByBookmarklet(url) as ViewResult;

            // assert
            var model = result.Model as AddByBookmarkletPageViewModel;

            Assert.IsNotNull(result);
            Assert.AreEqual("", result.ViewName);
            Assert.AreEqual(
                pagedRefLists.RefLists.FirstOrDefault().Title,
                model.RefLists.FirstOrDefault().Title
                );
        }