示例#1
0
        public async Task NoAuth()
        {
            var cmd      = new CreateSubverseCommand("mysub", "Some title", null);
            var response = await cmd.Execute();

            Assert.AreEqual(Status.Invalid, response.Status);
        }
        public async Task <ActionResult> CreateSubverse([Bind("Name, Title, Description, Type, Sidebar, CreationDate, Owner")] AddSubverse subverseTmpModel)
        {
            // abort if model state is invalid
            if (!ModelState.IsValid)
            {
                PreventSpamAttribute.Reset(HttpContext);
                return(View(subverseTmpModel));
            }

            var title = subverseTmpModel.Title;

            if (String.IsNullOrEmpty(title))
            {
                title = $"/v/{subverseTmpModel.Name}"; //backwards compatibility, previous code always uses this
            }

            var cmd      = new CreateSubverseCommand(subverseTmpModel.Name, title, subverseTmpModel.Description, subverseTmpModel.Sidebar).SetUserContext(User);
            var respones = await cmd.Execute();

            if (respones.Success)
            {
                return(RedirectToRoute(Models.ROUTE_NAMES.SUBVERSE_INDEX, new { subverse = subverseTmpModel.Name }));
            }
            else
            {
                PreventSpamAttribute.Reset(HttpContext);
                ModelState.AddModelError(string.Empty, respones.DebugMessage());
                return(View(subverseTmpModel));
            }
        }
示例#3
0
        public async Task InvalidSubverseName()
        {
            var user     = TestHelper.SetPrincipal("TestUser500CCP");
            var cmd      = new CreateSubverseCommand("My Subverse", "Some title", null).SetUserContext(user);
            var response = await cmd.Execute();

            Assert.AreEqual(Status.Denied, response.Status, response.Message);
        }
示例#4
0
        public async Task WhiteSpaceSubverseName()
        {
            TestHelper.SetPrincipal("TestUser500CCP");
            var cmd      = new CreateSubverseCommand("    ", "Some title", null);
            var response = await cmd.Execute();

            Assert.AreEqual(Status.Denied, response.Status);
        }
示例#5
0
        public async Task DeniedCreationTest()
        {
            var user        = TestHelper.SetPrincipal(USERNAMES.User0CCP);
            var name        = "UnitTestSubverse2";
            var title       = "Some title";
            var description = "Some Description";
            var cmd         = new CreateSubverseCommand(name, title, description).SetUserContext(user);
            var response    = await cmd.Execute();

            VoatAssert.IsValid(response, Status.Denied);

            //using (var db = new voatEntities())
            //{
            //    var subverse = db.Subverses.FirstOrDefault(x => x.Name == name);
            //    Assert.IsNotNull(subverse, "Expecting to find subverse");
            //    Assert.AreEqual(name, subverse.Name);
            //    Assert.AreEqual(title, subverse.Title);
            //    Assert.AreEqual(description, subverse.Description);
            //}
        }
示例#6
0
        public async Task ValidCreationTest()
        {
            var user        = TestHelper.SetPrincipal(USERNAMES.User500CCP);
            var name        = "UnitTestSubverse";
            var title       = "Some title";
            var description = "Some Description";
            var cmd         = new CreateSubverseCommand(name, title, description).SetUserContext(user);
            var response    = await cmd.Execute();

            Assert.AreEqual(Status.Success, response.Status, response.Message);

            using (var db = new VoatDataContext())
            {
                var subverse = db.Subverse.FirstOrDefault(x => x.Name == name);
                Assert.IsNotNull(subverse, "Expecting to find subverse");
                Assert.AreEqual(name, subverse.Name);
                Assert.AreEqual(description, subverse.Description);
                //for backwards compat - original code set title automatically
                //Assert.AreEqual($"/v/{name}", subverse.Title);
                Assert.AreEqual(title, subverse.Title);
            }
        }