示例#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) });
        }
示例#2
0
        public async void apps_should_return_with_app_model()
        {
            //arrange
            var list = new List<App> { new App { Id = 1, Tokens = new List<Token>() }, new App { Id = 2, Tokens = new List<Token>() } };
            var appService = new Mock<IAppService>();
            appService.Setup(x => x.GetByUserId(1, 1))
                      .Returns(Task.FromResult(new PagedList<App>(1, 2, 3, list))); 

            //act
            var sut = new UserControllerBuilder().WithAppService(appService.Object)
                                                 .Build();
            var view = await sut.Apps(1, 1) as ViewResult;
            var model = view.Model as PageModel<AppModel>;

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

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

            sut.AssertGetAttribute(ActionNameApps, new[] { typeof(int), typeof(int) }); 
        }
示例#3
0
        public async void logout_should_redirect()
        {
            //arrange    
            var formsAuthenticationService = new Mock<IFormsAuthenticationService>();
            formsAuthenticationService.Setup(x => x.SignOut());

            //act
            var sut = new UserControllerBuilder().WithFormsAuthenticationService(formsAuthenticationService.Object)
                                                 .Build();

            var view = sut.Logout() as RedirectResult;

            //assert
            Assert.NotNull(view);
            Assert.AreEqual(view.Url, "/");
            sut.AssertGetAttribute("Logout");
        }
示例#4
0
        public void login_should_return_with_login_model()
        {
            //act
            var sut = new UserControllerBuilder().Build();
            var view = sut.Login() as ViewResult;

            //assert
            Assert.NotNull(view);
            var model = view.Model;
            Assert.NotNull(model);
            Assert.IsAssignableFrom(typeof(LoginModel), model);

            sut.AssertGetAttribute("Login");
            sut.AssertAllowAnonymousAttribute("Login");
        }
示例#5
0
        public void reset_should_return_with_reset_model()
        {
            //act
            var sut = new UserControllerBuilder().BuildWithMockControllerContext();
            var view = sut.Reset() as ViewResult;

            //assert
            Assert.NotNull(view);
            var model = view.Model;
            Assert.NotNull(model);
            Assert.IsAssignableFrom(typeof(ResetModel), model);

            sut.AssertGetAttribute("Reset");
            sut.AssertAllowAnonymousAttribute("Reset");
        }