public void Create(DocumentationPage page)
        {
            using (var connection = SqlConnectionFactory.GetConnection())
            using (var command = connection.CreateCommand())
            {
                command.CommandType = CommandType.Text;
                command.CommandText = SqlScripts.DocumentationPage_Create;
                AddParameters(page, command);

                connection.Open();
                page.Id = (int)command.ExecuteScalar();
            }
        }
        public void Import(DocumentationPage page)
        {
            using (var connection = SqlConnectionFactory.GetConnection())
            using (var command = connection.CreateCommand())
            {
                command.CommandType = CommandType.Text;
                command.CommandText = SqlScripts.DocumentationPage_Import;
                AddParameters(page, command);
                command.Parameters.Add(new SqlParameter("@id", page.Id));

                connection.Open();
                command.ExecuteNonQuery();
            }
        }
Example #3
0
        public DocumentationPage CreateDocumentationPage(
            int id = 0,
            int? parentPageId = null,
            string title = null,
            int order = 1,
            bool isHidden = false)
        {
            title = title ?? string.Format("Unit Test Help {0}", _documentationPageCount.ToString("00#"));

            var result = new DocumentationPage
            {
                Id = id,
                Content = "Test content for documentation page.",
                Order = order,
                ParentPageId = parentPageId,
                Title = title,
                IsHidden = isHidden,
            };

            _documentationPageCount++;

            return result;
        }
        public void Process_ExistingPage()
        {
            // Arrange
            var dataStorePage = Models.CreateDocumentationPage(id: 84926);

            var clientPage = new DocumentationPage
            {
                Id = dataStorePage.Id,			// Same id as data store page because this is an existing page.
                Title = dataStorePage.Title,
                Content = dataStorePage.Content,
                Order = dataStorePage.Order,
                ParentPageId = dataStorePage.ParentPageId,
            };

            var documentationPageRepository = Mocks.Create<IDocumentationPageRepository>();
            documentationPageRepository.Setup(r => r.Read(clientPage.Id)).Returns(dataStorePage);
            documentationPageRepository.Setup(r => r.Update(It.Is<DocumentationPage>(p => p.Id == clientPage.Id)));

            var serializer = new JavaScriptSerializer();
            var requestData = serializer.Serialize(clientPage);
            var processor = new SaveDocumentationPageRequestProcessor(documentationPageRepository.Object);

            // Act
            var result = processor.Process(requestData);

            // Assert
            Assert.That(result, Is.Not.Null, "A response state instance should be returned.");
            Assert.That(result.ContentType, Is.EqualTo(ContentTypes.Json), "The response content should contain JSON.");
            var resultPage = serializer.Deserialize<DocumentationPage>(result.Content);
            Assert.That(resultPage.Id, Is.EqualTo(clientPage.Id), "The page id should not change.");
            Mocks.VerifyAll();
        }
        private IEnumerable<DocumentationPage> HydratePages(SqlDataReader reader)
        {
            var idOrdinal = reader.GetOrdinal("Id");
            var parentPageIdOrdinal = reader.GetOrdinal("ParentPageId");
            var orderOrdinal = reader.GetOrdinal("Order");
            var titleOrdinal = reader.GetOrdinal("Title");
            var contentOrdinal = reader.GetOrdinal("Content");
            var isHiddenOrdinal = reader.GetOrdinal("IsHidden");

            while (reader.Read())
            {
                var result = new DocumentationPage
                {
                    Id = reader.GetInt32(idOrdinal),
                    ParentPageId = reader.IsDBNull(parentPageIdOrdinal) ? (int?)null : reader.GetInt32(parentPageIdOrdinal),
                    Order = reader.GetInt32(orderOrdinal),
                    Title = reader.GetString(titleOrdinal),
                    Content = reader.GetString(contentOrdinal),
                    IsHidden = reader.GetBoolean(isHiddenOrdinal)
                };

                yield return result;
            }
        }
 private static void AddParameters(DocumentationPage page, SqlCommand command)
 {
     command.Parameters.AddRange(new SqlParameter[] {
         new SqlParameter("@parentPageId", (object)page.ParentPageId ?? DBNull.Value),
         new SqlParameter("@order", (object)page.Order ?? DBNull.Value),
         new SqlParameter("@title", page.Title),
         new SqlParameter("@content", page.Content),
         new SqlParameter("@isHidden", page.IsHidden),
     });
 }