public void should_show_topic_list()
        {
            var user = new User {
                UserName = "******"
            };

            _adminApp.GetService <IRepository <User> >().Save(user);

            var topicRepository = _adminApp.GetService <IRepository <Topic> >();

            Enumerable.Range(1, 3)
            .Select(num => $"title {num}")
            .ToList()
            .ForEach(title =>
            {
                topicRepository.Save(new Topic
                {
                    Author = user,
                    Type   = TopicType.Discussion,
                    Title  = title
                });
            });

            var controller = _adminApp.CreateController <TopicManagementController>();

            var list = controller.List();

            Assert.Equal(3, list.TotalItemCount);
            Assert.Equal("title 3", list.Items[0].Title);
            Assert.Equal("title 2", list.Items[1].Title);
            Assert.Equal("title 1", list.Items[2].Title);
        }
예제 #2
0
        public void should_create_for_queryable()
        {
            Create30Articles();


            var sortedArticles = _adminApp.GetService <IRepository <Article> >().All().OrderBy(a => a.Id);
            var pagedList      = sortedArticles.Page(PageSize, 2);

            VerifyPaging(pagedList, 2);
            pagedList.Items
            .Select(article => article.Title)
            .SequenceEqual(new[] { "queryable 4", "queryable 5", "queryable 6" })
            .ShouldEqual(true);
        }
예제 #3
0
        public void should_generate_token_with_7200_validity()
        {
            var adminUserService = _adminApp.GetService <IAdminUserService>();
            var adminUser        = new AdminUser
            {
                Id       = 20,
                Username = "******"
            };

            var token = adminUserService.IssueJwtToken(adminUser);

            Assert.NotNull(token);
            Assert.NotNull(token.TokenString);
            Assert.Equal(7200, token.ValidForSeconds);
        }
예제 #4
0
        public void should_not_register_one_username_a_second_time()
        {
            var password       = "******";
            var hashedPassword = _adminApp.GetService <IAdminUserService>().HashPassword(password);
            var firstAdminUser = new AdminUser {
                Username = "******", HashedPassword = hashedPassword
            };

            _adminUserRepo.Save(firstAdminUser);
            _adminApp.MockAdminUser();


            var newAdminUser = new UserViewModel
            {
                UserName = firstAdminUser.Username,
                Password = "******"
            };
            var accountController = _adminApp.CreateController <AccountController>();
            var apiResponse       = accountController.Register(newAdminUser);


            var users = _adminUserRepo.All().Where(u => u.Username == newAdminUser.UserName).ToList();

            Assert.Equal(400, apiResponse.Code);
            Assert.Equal(1, users.Count);
        }
예제 #5
0
 public AccountControllerSpecs(TestDiscussionAdminApp adminApp)
 {
     _adminApp      = adminApp;
     _adminUserRepo = adminApp.GetService <IRepository <AdminUser> >();
     _adminApp.Reset();
     _adminApp.DeleteAll <AdminUser>();
 }