Esempio n. 1
0
        public void CanAddPageToSite()
        {
            //Arrange - Specify values for new page.
            repository.Create(testSite);
            var pageModel = new MockPageEditModel ();
            var siteToBeTested = repository.Get().First();
            var siteModel = new UpdateSiteModel { Id = siteToBeTested.Id};
            siteModel.Pages.Add(pageModel);
            //Act - Command the controller to update the site with the page's values.
            var response = controller.Post(siteModel);

            //Assert - Make sure that the page is contained within the site in the repository.
            Assert.IsNotEmpty(siteToBeTested.Pages);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
Esempio n. 2
0
        public void CanAddItemTypeToSite()
        {
            //Arrange - Specify Values for new item type. Make sure a site already exists within the repo.
            repository.Create(testSite);
            var siteBeingUpdated = repository.Get().First();
            var updateModel = new UpdateSiteModel{ Id = siteBeingUpdated.Id};
            updateModel.ItemTypes.Add(new ItemTypeEditModel { Name = "Test Item Type" });

            //Act - Command the controller to update the site given the update values.
            var response = controller.Post(updateModel);

            //Assert
            var updatedSite = repository.Get(updateModel.Id);
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsNotEmpty(siteBeingUpdated.ItemTypes);
            Assert.AreEqual("Test Item Type", siteBeingUpdated.ItemTypes.First().Name);
        }
Esempio n. 3
0
        public void CanAddItemTypeWithPropertiesToSite()
        {
            //Arrange - Specify Values for new item type.
            repository.Create(testSite);
            var siteBeingUpdated = repository.Get().First();
            var updateModel = new UpdateSiteModel { Id = siteBeingUpdated.Id };
            var testItemType = new ItemTypeEditModel { Name = "Test Item Type" };

            testItemType.Properties.Add(new ItemPropertyEditModel { Name = "Test Item Property", PropertyType = 1});
            updateModel.ItemTypes.Add(testItemType);

            //Act - Command the controller to update the site given the update values.
            var response = controller.Post(updateModel);

            //Assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsNotEmpty(siteBeingUpdated.ItemTypes.First().Properties);
            Assert.AreEqual("Test Item Type", siteBeingUpdated.ItemTypes.First().Name);
        }
Esempio n. 4
0
        public HttpResponseMessage Post(UpdateSiteModel updateModel)
        {
            var site = repository.Get(updateModel.Id);
            //This is where we do the updating.
            site.Name = updateModel.Name;
            //This section for the newly created values.
            foreach (var itemTypeModel in updateModel.ItemTypes.Where(itemType => itemType.Id == 0))
            {
                //Determine whether or not the list of item types is empty to determine the key for the new item type.
                var idOfNewItemType = site.ItemTypes.Any()
                    ? site.ItemTypes.Max(itemType => itemType.Id) + 1 : 1;
                //Create the item type and populate its properties.
                var newItemType = new ItemType(idOfNewItemType);
                newItemType.Name = itemTypeModel.Name;
                foreach(var itemPropertyModel in itemTypeModel.Properties)
                {
                    var newPropertyId = newItemType.Properties.Any()
                                            ? newItemType.Properties.Max(propKvp => propKvp.Value.Id) + 1
                                            : 1;
                    var newProperty = new KeyValuePair<string, ItemProperty>(itemPropertyModel.Name, new ItemProperty(newPropertyId));
                    newItemType.Properties.Add(newProperty);
                }
                //Finally, add the item type.
                site.ItemTypes.Add(newItemType);
            }
            //Let's go over the page properties and stuff.
            //Determine the id of the new page.
            foreach (var mockPageModel in updateModel.Pages.Where( page => page.Id == 0))
            {
                var idOfNewPage = site.Pages.Any() ? site.Pages.Max(page => page.Id) + 1 : 1;
                var newPage = new MockPage(idOfNewPage);
                newPage.Html = mockPageModel.Html;
                newPage.Name = mockPageModel.Name;
                site.Pages.Add(newPage);
            }
            //This section for the values that we are going to update.
            foreach( var itemTypeModel in updateModel.ItemTypes.Where(itemType => itemType.Id > 0))
            {
                var itemTypeBeingModified = site.ItemTypes.SingleOrDefault(itemType => itemType.Id == itemTypeModel.Id);
                itemTypeBeingModified.Name = itemTypeModel.Name;
                //Find the newly created properties on the item type.
                foreach( var itemPropertyModel in updateModel.ItemTypes.Where(prop => prop.Id == 0))
                {
                    var newPropertyId = itemTypeBeingModified.Properties.Any()
                        ? itemTypeBeingModified.Properties.Max(propKvp => propKvp.Value.Id) + 1
                        : 1;
                    var newProperty = new KeyValuePair<string, ItemProperty>(itemPropertyModel.Name, new ItemProperty(newPropertyId));
                    itemTypeBeingModified.Properties.Add(newProperty);
                }
                foreach( var itemPropertyModel in updateModel.ItemTypes.Where(prop => prop.Id > 0))
                {

                }
            }
            foreach (var pageModel in updateModel.Pages.Where(page => page.Id > 0))
            {
                var pageBeingModified = site.Pages.SingleOrDefault(page => page.Id == pageModel.Id);
                pageBeingModified.Name = pageModel.Name;
            }
            //Tell the Repository to commit the changes
            repository.Update(site);
            var response = Request.CreateResponse(HttpStatusCode.OK);
            return response;
        }
Esempio n. 5
0
 public void CanChangeItemTypeName()
 {
     //Arrange
     repository.Create(testSite);
     var siteToBeModifed = repository.Get().First();
     var itemType = new ItemType(1);
     itemType.Name = "New Item Type";
     siteToBeModifed.ItemTypes.Add(itemType);
     var itemTypeNewValues = new UpdateSiteModel {Id = siteToBeModifed.Id};
     var newItemTypeName = "Changed Name";
     itemTypeNewValues.ItemTypes.Add(new ItemTypeEditModel{ Id = itemType.Id, Name = newItemTypeName});
     //Act
     var response = controller.Post(itemTypeNewValues);
     //Assert
     Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
     Assert.AreEqual( newItemTypeName, itemType.Name);
 }
Esempio n. 6
0
 public void CanChangeSiteName()
 {
     //Arrange
     repository.Create(testSite);
     var siteToBeModified = repository.Get().First();
     var originalSiteName = siteToBeModified.Name;
     var modifiedSiteName = "Modified Site Name";
     var modifiedSiteValues = new UpdateSiteModel {Id = siteToBeModified.Id, Name = modifiedSiteName};
     //Act
     var response = controller.Post(modifiedSiteValues);
     //Assert
     Assert.AreEqual(HttpStatusCode.OK,response.StatusCode );
     Assert.AreEqual(modifiedSiteName, siteToBeModified.Name);
 }
Esempio n. 7
0
 public void CanChangePageName()
 {
     //Arrange
     repository.Create(testSite);
     var siteToBeModified = repository.Get().First();
     var page = new MockPage(1);
     page.Name = "Unchanged Name";
     var newName = "Changed Name";
     siteToBeModified.Pages.Add(page);
     var newPageValues = new UpdateSiteModel {Id = siteToBeModified.Id};
     newPageValues.Pages.Add(new MockPageEditModel { Id = page.Id, Name = newName});
     //Act
     var response = controller.Post(newPageValues);
     //Assert
     Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
     Assert.AreEqual(newName, page.Name);
 }