public void InstallFromSkippedFile()
        {
            var dataStoreManager = new TestFixtureDataStoreManager();

            var firstPage = Models.CreateDocumentationPage();

            _documentationPageRepository.Create(firstPage);

            // Generate content file.
            var contentFileName = Path.GetTempFileName();

            dataStoreManager.ExportContent(contentFileName);


            // Change content and recreate installation file.
            var deletedPage   = Models.CreateDocumentationPage();
            var recreatedPage = Models.CreateDocumentationPage();
            var lastPage      = Models.CreateDocumentationPage();

            _documentationPageRepository.Create(deletedPage);
            _documentationPageRepository.Create(recreatedPage);
            _documentationPageRepository.Create(lastPage);
            _documentationPageRepository.Delete(recreatedPage.Id);
            _documentationPageRepository.Create(recreatedPage);
            _documentationPageRepository.Delete(deletedPage.Id);

            // Regenerate content file.
            dataStoreManager.ExportContent(contentFileName);

            // Reset data store and exercise startup file.
            dataStoreManager.DeleteDataStore();
            dataStoreManager.CreateDataStore();
            dataStoreManager.ImportContent(contentFileName);

            // Validate model ids.
            var newFirstPage      = _documentationPageRepository.Read(firstPage.Id);
            var deletedPageResult = _documentationPageRepository.Read(deletedPage.Id);

            Assert.That(deletedPageResult, Is.Null, "The data layer should return null for non-existant pages.");

            var newRecreatedPage = _documentationPageRepository.Read(recreatedPage.Id);
            var newLastPage      = _documentationPageRepository.Read(lastPage.Id);

            Assert.That(newFirstPage, Is.Not.Null, "First page should still exist.");
            Assert.That(newFirstPage.Title, Is.EqualTo(firstPage.Title), "Old first page title should match new page with its id.");
            Assert.That(newRecreatedPage, Is.Not.Null, "Recreated page should still exist.");
            Assert.That(newRecreatedPage.Title, Is.EqualTo(recreatedPage.Title), "Old recreated page title should match new recreated page title.");
            Assert.That(newLastPage, Is.Not.Null, "Last page should still exist.");
            Assert.That(newLastPage.Title, Is.EqualTo(lastPage.Title), "Old last page title should match new last page title.");
        }
        public ResponseState Process(string data)
        {
            var serializer = new JavaScriptSerializer();
            var clientPage = serializer.Deserialize <DocumentationPage>(data);

            if (clientPage.Id > 0)
            {
                // Validate that the parent and order are not changing on updates.
                var dataStorePage = _documentationPageRepository.Read(clientPage.Id);
                if (!(dataStorePage.Order == clientPage.Order && dataStorePage.ParentPageId == clientPage.ParentPageId))
                {
                    throw new InvalidOperationException("Changing page order and parent id not supported by SavePage. Use MovePage instead.");
                }

                _documentationPageRepository.Update(clientPage);
            }
            else
            {
                // Push siblings after the starting at the new page's order up by one.
                var siblings = _documentationPageRepository.ReadByParentId(clientPage.ParentPageId);
                for (int i = clientPage.Order; i < siblings.Count; i++)
                {
                    siblings[i].Order++;
                    _documentationPageRepository.Update(siblings[i]);
                }

                // Create after siblings have been read so that the new page doesn't have its order increased.
                _documentationPageRepository.Create(clientPage);
            }

            var pageJson = serializer.Serialize(clientPage);

            return(new ResponseState
            {
                Content = pageJson,
                ContentType = ContentTypes.Json,
            });
        }