Ejemplo n.º 1
0
 public ContentItem Add(ContentItem contentItem)
 {
     using (DatabaseContext context = new DatabaseContext())
     {
         return context.AddContentItem<MSSQL.Entities.ContentItem, ContentItem>(contentItem);
     }
 }
Ejemplo n.º 2
0
 public void Update(ContentItem contentItem)
 {
     using (DatabaseContext context = new DatabaseContext())
     {
         context.Update<MSSQL.Entities.ContentItem, ContentItem>(contentItem, new string[] { "Id" });
     }
 }
Ejemplo n.º 3
0
 public IHttpActionResult Post(ContentItem contentItem)
 {
     if (!ModelState.IsValid)
     {
         return BadRequest("Content item invalid");
     }
     try
     {
         return Ok(_service.Add(contentItem));
     }
     catch (Exception e)
     {
         return BadRequest("An error occured");
     }
 }
Ejemplo n.º 4
0
        private ContentItem ContentItemsToTree(ContentItem parentContentItem, List<ContentItem> contentItems)
        {
            parentContentItem.Children = contentItems.Where(contentItem => contentItem.ParentId == parentContentItem.Id).ToArray();

            foreach (ContentItem contentItem in parentContentItem.Children)
            {
                contentItems.Remove(contentItem);
            }

            for (int i = 0; i < parentContentItem.Children.Length; i++)
            {
                parentContentItem.Children[i] = ContentItemsToTree(parentContentItem.Children[i], contentItems);
            }

            return parentContentItem;
        }
Ejemplo n.º 5
0
        public Timeline Add(Timeline timeline)
        {
            using (DatabaseContext context = new DatabaseContext())
            {
                ContentItem contentItem = new ContentItem()
                {
                    ParentId = 1,
                    BeginDate = timeline.BeginDate,
                    EndDate = timeline.EndDate,
                    HasChildren = true,
                    Title = timeline.Title,
                    Description = timeline.Description,
                    PictureURLs = new string[1]
                };

                contentItem = context.AddContentItem<MSSQL.Entities.ContentItem, ContentItem>(contentItem);
                timeline.RootContentItemId = contentItem.Id;

                return context.Add<MSSQL.Entities.Timeline, Timeline>(timeline, new string[] { "Id", "Timestamp" });
            }
        }
Ejemplo n.º 6
0
        public IHttpActionResult Put(int id, ContentItem contentItem)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest("Content item invalid");
            }
            if (contentItem.Id == 0)
            {
                return BadRequest("No id specified");
            }

            try
            {
                _service.Update(contentItem);
                return Ok();
            }
            catch (Exception)
            {
                return BadRequest("An error occured");
            }
        }
Ejemplo n.º 7
0
 public void Update(ContentItem contentItem)
 {
     _dao.Update(contentItem);
 }
Ejemplo n.º 8
0
 public ContentItem Add(ContentItem contentItem)
 {
     return _dao.Add(contentItem);
 }
Ejemplo n.º 9
0
        public void ContentItemController_Post_InvalidID_Test()
        {
            // Arrange
            Mock<IContentItemService> mock = new Mock<IContentItemService>(MockBehavior.Strict);
            mock.Setup(setup => setup.Update(It.IsAny<ContentItem>()));
            ContentItemController target = new ContentItemController(mock.Object);
            ContentItem item = new ContentItem()
            {
                BeginDate = -1,
                EndDate = -1,
                Title = "test",
                ParentId = 1,
                HasChildren = false,
                Id = 0,
                SourceRef = string.Empty,
                SourceURL = string.Empty
            };

            // Act
            target.Configuration = new HttpConfiguration();
            target.Validate<ContentItem>(item);
            IHttpActionResult result = target.Post(item);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result is BadRequestErrorMessageResult);
        }
Ejemplo n.º 10
0
        public void ContentItemController_Put_Validation_Test()
        {
            // Arrange
            Mock<IContentItemService> mock = new Mock<IContentItemService>(MockBehavior.Strict);
            mock.Setup(setup => setup.Add(It.IsAny<ContentItem>()));
            ContentItemController target = new ContentItemController(mock.Object);
            ContentItem item = new ContentItem()
            {
                HasChildren = false,
                SourceRef = string.Empty,
                SourceURL = string.Empty
            };

            // Act
            target.Configuration = new HttpConfiguration();
            target.Validate<ContentItem>(item);
            IHttpActionResult result = target.Put(0,item);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result is BadRequestErrorMessageResult);
            Assert.AreEqual(false, target.ModelState.IsValid);
            Assert.AreEqual(3, target.ModelState.Count);
        }
Ejemplo n.º 11
0
        public void ContentItemController_Post_Test()
        {
            // Arrange
            Mock<IContentItemService> mock = new Mock<IContentItemService>(MockBehavior.Strict);
            mock.Setup(setup => setup.Add(It.IsAny<ContentItem>())).Returns(new ContentItem()
            {
                Id = 123
            });
            ContentItemController target = new ContentItemController(mock.Object);
            ContentItem item = new ContentItem()
            {
                BeginDate = -1,
                EndDate = -1,
                Title = "test",
                ParentId = 1,
                HasChildren = false,
                SourceRef = string.Empty,
                SourceURL = string.Empty
            };

            // Act
            target.Configuration = new HttpConfiguration();
            target.Validate<ContentItem>(item);
            IHttpActionResult result = target.Post(item);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result is OkNegotiatedContentResult<ContentItem>);
            Assert.AreEqual(123, (result as OkNegotiatedContentResult<ContentItem>).Content.Id);
            mock.Verify(verify => verify.Add(It.IsAny<ContentItem>()), Times.Once);
        }