public BlogPostAsset(CreateAsset asset) { if(asset.Asset.Type != AssetTypes.BlogPostAsset) throw new InvalidOperationException("Expected " + AssetTypes.BlogPostAsset + " but got " + asset.Asset.Type); this.Asset = asset.Asset; this.Header = asset.Header; }
public void testCreateBlogPost() { CreateAsset asset = new CreateAsset(); asset.Asset.Type = AssetTypes.BlogPostAsset; BlogPostAsset o = new BlogPostAsset(asset); Assert.IsNotNull(o); }
public void testProps() { CreateAsset asset = new CreateAsset(); asset.Asset.Type = AssetTypes.BlogPostAsset; BlogPostAsset o = new BlogPostAsset(asset); o.AuthorName = "nate"; Assert.AreEqual("nate",o.AuthorName); o.DisplayTitle = "unit test"; Assert.AreEqual("unit test",o.DisplayTitle); o.PostBody = "blah"; Assert.AreEqual("blah",o.PostBody); Assert.AreEqual(asset.Asset, o.Asset); Assert.AreEqual(asset.Header, o.Header); }
/// <summary> /// Creates the asset. /// </summary> /// <param name='asset'> /// Asset. /// </param> /// <exception cref='InvalidOperationException'> /// Is thrown when an operation cannot be performed. /// </exception> public void CreateAsset(CreateAsset asset ) { if(asset == null) throw new InvalidOperationException("Asset is required"); string url = BuildRequestURL(EXPORT_URI + CREATE_ASSET_URI); HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.Accept = "application/json"; request.ContentType = "application/json"; request.Credentials = GetCredential(url); request.Method = "POST"; byte[] byteData = UTF8Encoding.UTF8.GetBytes(asset.ToString()); // Set the content length in the request headers request.ContentLength = byteData.Length; // Write data using (Stream postStream = request.GetRequestStream()) { postStream.Write(byteData, 0, byteData.Length); } // Get response using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { if(response.StatusCode != HttpStatusCode.OK) throw new Exception(response.StatusCode.ToString()); // Get the response stream StreamReader reader = new StreamReader(response.GetResponseStream()); // Console application output Console.WriteLine(reader.ReadToEnd()); } }