public BlogImageTest() { mImage = new TransitImage(); mImage.Data = Encoding.Default.GetBytes(Guid.NewGuid().ToString()); mImage.Name = Guid.NewGuid().ToString(); mImage.Description = Guid.NewGuid().ToString(); mImage.Path = Guid.NewGuid().ToString(); mImage.Preferred = false; mImage.Thumbnail = Encoding.Default.GetBytes(Guid.NewGuid().ToString()); }
public void CreatePostWithImageAndCommentTest() { // post TransitPost t_post = new TransitPost(); t_post.Body = Guid.NewGuid().ToString(); t_post.Title = Guid.NewGuid().ToString(); t_post.Publish = true; t_post.Id = Blog.CreateOrUpdatePost(Ticket, t_post); Assert.Greater(t_post.Id, 0); // image TransitImage t_image = new TransitImage(); t_image.Name = Guid.NewGuid().ToString(); Bitmap b = new Bitmap(480, 480); Graphics g = Graphics.FromImage(b); g.FillEllipse(Brushes.Red, 0, 0, 480, 480); ThumbnailBitmap tb = new ThumbnailBitmap(b); t_image.Data = tb.Bitmap; t_image.Thumbnail = tb.Thumbnail; t_image.Id = Blog.CreateOrUpdatePostImage(Ticket, t_post.Id, t_image); Assert.Greater(t_image.Id, 0); // comment TransitComment t_comment = new TransitComment(); t_comment.IpAddress = "127.0.0.1"; t_comment.LoginId = Blog.GetLogin(Ticket).Id; t_comment.Text = Guid.NewGuid().ToString(); t_comment.Id = Blog.CreateOrUpdateImageComment(Ticket, t_image.Id, t_comment); Assert.Greater(t_comment.Id, 0); Blog.DeleteImage(Ticket, t_image.Id); Blog.DeletePost(Ticket, t_post.Id); }
public void CreatePostWithImageTest() { TransitPost t_post = new TransitPost(); t_post.Body = Guid.NewGuid().ToString(); t_post.Title = Guid.NewGuid().ToString(); t_post.Publish = true; t_post.Id = Blog.CreateOrUpdatePost(Ticket, t_post); Assert.Greater(t_post.Id, 0); TransitImage t_image = new TransitImage(); t_image.Name = Guid.NewGuid().ToString(); Bitmap b = new Bitmap(480, 480); Graphics g = Graphics.FromImage(b); g.FillEllipse(Brushes.Red, 0, 0, 480, 480); ThumbnailBitmap tb = new ThumbnailBitmap(b); t_image.Data = tb.Bitmap; t_image.Thumbnail = tb.Thumbnail; t_image.Id = Blog.CreateOrUpdatePostImage(Ticket, t_post.Id, t_image); Assert.Greater(t_image.Id, 0); Blog.DeletePost(Ticket, t_post.Id); }
/// <remarks/> public void CreateOrUpdatePostImageAsync(string ticket, int post_id, TransitImage t_image) { this.CreateOrUpdatePostImageAsync(ticket, post_id, t_image, null); }
/// <remarks/> public void CreateOrUpdatePostImageAsync(string ticket, int post_id, TransitImage t_image, object userState) { if ((this.CreateOrUpdatePostImageOperationCompleted == null)) { this.CreateOrUpdatePostImageOperationCompleted = new System.Threading.SendOrPostCallback(this.OnCreateOrUpdatePostImageOperationCompleted); } this.InvokeAsync("CreateOrUpdatePostImage", new object[] { ticket, post_id, t_image}, this.CreateOrUpdatePostImageOperationCompleted, userState); }
public int CreateOrUpdatePostImage(string ticket, int post_id, TransitImage t_image) { object[] results = this.Invoke("CreateOrUpdatePostImage", new object[] { ticket, post_id, t_image}); return ((int)(results[0])); }
/// <remarks/> public void CreateOrUpdateImageAttributesAsync(string ticket, TransitImage t_image) { this.CreateOrUpdateImageAttributesAsync(ticket, t_image, null); }
public int CreateOrUpdateImageAttributes(string ticket, TransitImage t_image) { object[] results = this.Invoke("CreateOrUpdateImageAttributes", new object[] { ticket, t_image}); return ((int)(results[0])); }
public void AtomUpdateImageTest() { // create image TransitImage t_image = new TransitImage(); t_image.Data = ThumbnailBitmap.GetBitmapDataFromText("x", 72, 100, 150); t_image.Name = Guid.NewGuid().ToString(); t_image.Id = Blog.CreateOrUpdateImage(Ticket, t_image); // update image HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create( string.Format("http://localhost/DBlog/AtomImage.aspx?id={0}", t_image.Id)); request.Method = "PUT"; request.ContentType = "image/jpg"; string usernamePassword = string.Format("Administrator:"); string basicAuthorization = string.Format("Basic {0}", Convert.ToBase64String( Encoding.ASCII.GetBytes(usernamePassword))); request.Headers.Add("Authorization", basicAuthorization); request.ContentLength = t_image.Data.Length; request.GetRequestStream().Write(t_image.Data, 0, t_image.Data.Length); request.GetRequestStream().Close(); HttpWebResponse response = (HttpWebResponse) request.GetResponse(); Assert.IsTrue(response.StatusCode == HttpStatusCode.OK, string.Format("Response code was {0}", response.StatusCode)); Blog.DeleteImage(Ticket, t_image.Id); }
public void CreateSecurePostTest() { TransitPost t_post = new TransitPost(); t_post.Body = Guid.NewGuid().ToString(); t_post.Title = Guid.NewGuid().ToString(); t_post.Id = Blog.CreateOrUpdatePost(Ticket, t_post); Assert.Greater(t_post.Id, 0); TransitImage t_image = new TransitImage(); t_image.Name = Guid.NewGuid().ToString(); Bitmap b = new Bitmap(480, 480); Graphics g = Graphics.FromImage(b); g.FillEllipse(Brushes.Red, 0, 0, 480, 480); ThumbnailBitmap tb = new ThumbnailBitmap(b); t_image.Data = tb.Bitmap; t_image.Thumbnail = tb.Thumbnail; t_image.Id = Blog.CreateOrUpdatePostImage(Ticket, t_post.Id, t_image); Assert.Greater(t_image.Id, 0); TransitLogin t_login = new TransitLogin(); t_login.Username = Guid.NewGuid().ToString(); t_login.Password = Guid.NewGuid().ToString(); t_login.Role = TransitLoginRole.Guest; t_login.Id = Blog.CreateOrUpdateLogin(Ticket, t_login); Assert.Greater(t_login.Id, 0); TransitComment t_comment = new TransitComment(); t_comment.IpAddress = "127.0.0.1"; t_comment.Text = Guid.NewGuid().ToString(); t_comment.LoginId = t_login.Id; t_comment.Id = Blog.CreateOrUpdatePostComment(Ticket, t_post.Id, t_comment); Assert.Greater(t_comment.Id, 0); int t_postlogin_id = Blog.CreateOrUpdatePostLogin(Ticket, t_post.Id, t_login); Assert.Greater(t_postlogin_id, 0); string authticket = Blog.Login(t_login.Username, t_login.Password); // check access to posts TransitPost t_post_unauthorized = Blog.GetPostById(null, t_post.Id); Assert.IsTrue(string.IsNullOrEmpty(t_post_unauthorized.Body), "Unathorized post body wasn't stripped."); TransitPost t_post_authorized = Blog.GetPostById(authticket, t_post.Id); Assert.IsFalse(string.IsNullOrEmpty(t_post_authorized.Body), "Authorized post was stripped."); // check access to images TransitImage t_image_unauthorized = Blog.GetImageWithBitmapById(null, t_image.Id); Assert.IsTrue(t_image_unauthorized.Data == null, "Unathorized image returned data."); TransitImage t_image_authorized = Blog.GetImageWithBitmapById(authticket, t_image.Id); Assert.IsTrue(t_image_authorized.Data != null, "Authorized image didn't return data."); // check access to comments TransitComment t_comment_unauthorized = Blog.GetCommentById(null, t_comment.Id); Assert.IsTrue(string.IsNullOrEmpty(t_comment_unauthorized.Text), "Unathorized comment returned data."); TransitComment t_comment_authorized = Blog.GetCommentById(authticket, t_comment.Id); Assert.IsFalse(string.IsNullOrEmpty(t_comment_authorized.Text), "Authorized comment didn't return data."); Blog.DeletePost(Ticket, t_post.Id); }