public void ItemRemovesFromSiteMap()
        {
            //Assemble
            var content = new SimpleContent {
                Id = "Unmappable", Title = "DontMapMe", Content = "<b>not mapped</b>"
            };

            s_repo.CreateContentAsync(content).GetAwaiter().GetResult();
            s_mapRepo.AddItemToSiteMapAsync(
                new SiteMapEntry {
                ContentIdentifier = content.Id, Title = content.Title
            });

            var controller = new ManageSimpleController(s_repo, s_mapRepo);

            //Act
            var result       = controller.Remove(content.Id).GetAwaiter().GetResult() as ViewResult;
            var isEntryInMap = s_mapRepo.IsItemInSiteMapAsync(content.Id).GetAwaiter().GetResult();
            var foundEntry   = s_mapRepo.GetMapAsync().GetAwaiter().GetResult()
                               .Entries.Where(
                (e) => e.ContentIdentifier == content.Id)
                               .FirstOrDefault();

            //Assert
            Assert.AreEqual <string>("SiteMapConfirm", result.ViewName, "Incorrect view returned");
            Assert.IsFalse(isEntryInMap, "Map entry reported as in the site map");
            Assert.IsNull(foundEntry, "Entry found manually in map");
        }
Ejemplo n.º 2
0
        public async Task AttemptingToCreateSimpleContentWithIdAlreadyInUse()
        {
            await s_repo.CreateContentAsync(new SimpleContent { Id = "existing", Title = "Exists", Content = "Already here" });

            var toAdd = new SimpleContent {
                Id = "existing", Title = "Usurper", Content = "Trying to overwrite"
            };
            var controller = new ManageSimpleController(s_repo, s_mapRepo);
            var result     = await controller.Create(toAdd) as ViewResult;

            Assert.AreEqual("Create", result.ViewName, "Shows Create view again");
            Assert.AreSame(toAdd, result.Model, "Passes model back to view");
            Assert.AreEqual("Content with this id already exists", controller.ModelState["Id"].Errors.Single().ErrorMessage);
        }
Ejemplo n.º 3
0
        public void AddingSimpleContent()
        {
            //Assemble
            var           controller = new ManageSimpleController(s_repo, s_mapRepo);
            SimpleContent content    = new SimpleContent {
                Title = "Added", Content = "<b>Added</b>"
            };

            //Act
            var result     = controller.Create(content).GetAwaiter().GetResult() as ViewResult;
            var items      = s_repo.GetListOfItemsAsync(ContentType.Simple.ToString()).GetAwaiter().GetResult();
            var targetItem = items.Where((i) => i.Title == "Added").FirstOrDefault();

            //Assert
            Assert.AreEqual <string>("Confirm", result.ViewName, "Confirmation view not returned");
            Assert.IsNotNull(targetItem, "Item not found after adding");
        }
Ejemplo n.º 4
0
        public void RemoveSimpleContent()
        {
            //assemble
            var content = new SimpleContent {
                Id = "DeleteMe", Title = "To be deleted"
            };

            s_repo.CreateContentAsync(content).GetAwaiter().GetResult();

            var controller = new ManageSimpleController(s_repo, s_mapRepo);

            //act
            var result      = controller.Delete("DeleteMe", content);
            var items       = s_repo.GetListOfItemsAsync(ContentType.Simple.ToString()).GetAwaiter().GetResult();
            var missingItem = items.Where((i) => i.Id == "DeleteMe").FirstOrDefault();

            //assert
            Assert.IsNull(missingItem, "Item should not be found in repository");
        }
Ejemplo n.º 5
0
        public void EditSimpleContentReturnsItem()
        {
            //assemble
            var content = new SimpleContent {
                Id = "EditMe", Title = "To be edited"
            };

            s_repo.CreateContentAsync(content).GetAwaiter().GetResult();

            var controller = new ManageSimpleController(s_repo, s_mapRepo);

            //act
            var result = controller.Edit(content.Id).GetAwaiter().GetResult() as ViewResult;
            var model  = result.Model as SimpleContent;

            //assert
            Assert.IsNotNull(model, "Item should be set as the model from repository");
            Assert.AreEqual <string>(content.Id, model.Id);
            Assert.AreEqual <string>(content.Title, model.Title);
        }
Ejemplo n.º 6
0
        public void EditSimpleContent()
        {
            //Assemble
            var controller = new ManageSimpleController(s_repo, s_mapRepo);

            controller.ControllerContext = new ControllerContext(new FakeHttpContext(), new System.Web.Routing.RouteData(), controller);
            SimpleContent content = new SimpleContent {
                Id = "Edit", Title = "Edit", Content = "<b>Edit</b>"
            };

            s_repo.CreateContentAsync(content);
            content.Title   = "Edited";
            content.Content = "<i>Edited</i>";

            //Act
            var result     = controller.Edit(content.Id, content).GetAwaiter().GetResult() as ViewResult;
            var items      = s_repo.GetListOfItemsAsync(ContentType.Simple.ToString()).GetAwaiter().GetResult();
            var targetItem = items.Where((i) => i.Id == "Edit").FirstOrDefault();

            //Assert
            Assert.AreEqual <string>("Confirm", result.ViewName, "Confirmation view not returned");
            Assert.IsNotNull(targetItem, "Item not found after editing");
            Assert.AreEqual <string>("Edited", targetItem.Title, "Title does not reflect edits");
        }