Exemple #1
0
        //TODO: Validate the property type data
        private bool ValidateData(ContentItemSave postedItem, ContentItemDto realItem, HttpActionContext actionContext)
        {
            foreach (var p in realItem.Properties)
            {
                var editor = PropertyEditorResolver.Current.GetById(p.DataType.ControlId);
                if (editor == null)
                {
                    var message = string.Format("The property editor with id: {0} was not found for property with id {1}", p.DataType.ControlId, p.Id);
                    actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.NotFound, message);
                    return(false);
                }

                //get the posted value for this property
                var postedValue = postedItem.Properties.Single(x => x.Id == p.Id).Value;

                //get the pre-values for this property
                var preValues = TestContentService.GetPreValue(p.DataType.Id);

                //TODO: when we figure out how to 'override' certain pre-value properties we'll either need to:
                // * Combine the preValues with the overridden values stored with the document type property (but how to combine?)
                // * Or, pass in the overridden values stored with the doc type property separately

                foreach (var v in editor.ValueEditor.Validators)
                {
                    foreach (var result in v.Validate(postedValue, preValues, editor))
                    {
                        //if there are no member names supplied then we assume that the validation message is for the overall property
                        // not a sub field on the property editor
                        if (!result.MemberNames.Any())
                        {
                            //add a model state error for the entire property
                            actionContext.ModelState.AddModelError(p.Alias, result.ErrorMessage);
                        }
                        else
                        {
                            //there's assigned field names so we'll combine the field name with the property name
                            // so that we can try to match it up to a real sub field of this editor
                            foreach (var field in result.MemberNames)
                            {
                                actionContext.ModelState.AddModelError(string.Format("{0}.{1}", p.Alias, field), result.ErrorMessage);
                            }
                        }
                    }
                }
            }

            //create the response if there any errors
            if (!actionContext.ModelState.IsValid)
            {
                actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.Forbidden, actionContext.ModelState);
            }

            return(actionContext.ModelState.IsValid);
        }
Exemple #2
0
        public void ContentService()
        {
            var provider = new TestContentService();

            WebServiceLocator.RegisterService(provider, VirtualPathUtility.GetDirectory(testContentPath));
            var result = HtmlServices.LoadContent(testContentPath);

            Assert.AreEqual(result.Content, testContent, "测试内容提供程序失败");

            Assert.AreEqual(result.Provider, provider, "内容结果中的提供程序错误");
            Assert.AreEqual(result.VirtualPath, testContentPath, "内容结果中的虚拟路径错误");
        }
Exemple #3
0
 /// <summary>
 /// Ensure the content exists
 /// </summary>
 /// <param name="postedItem"></param>
 /// <param name="actionContext"></param>
 /// <param name="found"></param>
 /// <returns></returns>
 private bool ValidateExistingContent(ContentItemSave postedItem, HttpActionContext actionContext, out ContentItemDto found)
 {
     //TODO: We need to of course change this to the real umbraco api
     found = TestContentService.GetContentItem(postedItem.Id);
     if (found == null)
     {
         var message = string.Format("content with id: {0} was not found", postedItem.Id);
         actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.NotFound, message);
         return(false);
     }
     return(true);
 }
Exemple #4
0
    public void ContentService()
    {

      var provider = new TestContentService();

      WebServiceLocator.RegisterService( provider, VirtualPathUtility.GetDirectory( testContentPath ) );
      var result = HtmlServices.LoadContent( testContentPath );

      Assert.AreEqual( result.Content, testContent, "测试内容提供程序失败" );

      Assert.AreEqual( result.Provider, provider, "内容结果中的提供程序错误" );
      Assert.AreEqual( result.VirtualPath, testContentPath, "内容结果中的虚拟路径错误" );

    }
        /// <summary>
        /// Gets the content json for the content id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public object GetContent(int id)
        {
            var foundContent = TestContentService.GetContentItemForDisplay(id);

            if (foundContent == null)
            {
                ModelState.AddModelError("id", string.Format("content with id: {0} was not found", id));

                var errorResponse = Request.CreateErrorResponse(
                    HttpStatusCode.NotFound,
                    ModelState);
                throw new HttpResponseException(errorResponse);
            }
            return(foundContent);
        }
			public TestDataService()
			{
				ContentService = new TestContentService();
				LogService = new TestLogService();
				MediaService = new TestMediaService();
			}
Exemple #7
0
 public TestDataService()
 {
     ContentService = new TestContentService();
     LogService     = new TestLogService();
     MediaService   = new TestMediaService();
 }