Exemplo n.º 1
0
 /// <summary>
 /// Uploads a posted image to the candidate photo repository for the current candidate.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">An <see cref="EventArgs"/> object that contains the event data.</param>
 protected void UploadPhoto(object sender, EventArgs e)
 {
     if (Page.IsValid && this.IsPostBack)
     {
         // upload image
         try
         {
             if (_photoUpload.HasFile)
             {
                 try
                 {
                     using (Image i = Image.FromStream(_photoUpload.FileContent, true, true))
                     {
                         if (_photoUpload.FileContent.Length <= MaxPhotoFileSizeMB * BytesPerMegabyte)
                         {
                             string photoPath = ProfilePhotoHandler.GetPhotoFilePath(CPProfile.Cid);
                             if (File.Exists(photoPath) && !string.IsNullOrEmpty(CPProfile.Cid))
                             {
                                 File.Delete(photoPath);
                             }
                             if ((i.Height > MaxPhotoHeight) || (i.Width > MaxPhotoWidth))
                             {
                                 using (Image t = MakeThumbnailFrom(i))
                                 {
                                     t.Save(photoPath);
                                 }
                             }
                             else
                             {
                                 i.Save(photoPath);
                             }
                             i.Dispose();
                             ShowGreeting();
                         }
                         else
                         {
                             // when file is too big
                             SetError(string.Format("The file provided exceeds the maximum acceptable image size of {0} MB. Please try uploading a smaller file.", MaxPhotoFileSizeMB));
                         }
                     }
                 }
                 catch (ArgumentException)
                 {
                     // when file is valid but not an image
                     SetError("The file provided is not a supported image. Please try uploading a BMP, GIF, JPG, TIF, or PNG file.");
                 }
             }
             else
             {
                 // when no file was supplied
                 SetError("Please first browse to an image for uploading.");
             }
         }
         catch (ArgumentException)
         {
             // when an invalid path was supplied
             SetError("The file specified could not be found. Please try browsing to the file again.");
         }
     }
 }
Exemplo n.º 2
0
        public void ProcessRequestTest()
        {
            ProfilePhotoHandler target  = new ProfilePhotoHandler(); // TODO: Initialize to an appropriate value
            HttpContext         context = null;                      // TODO: Initialize to an appropriate value

            target.ProcessRequest(context);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
Exemplo n.º 3
0
        public void IsReusableTest()
        {
            ProfilePhotoHandler target = new ProfilePhotoHandler();             // TODO: Initialize to an appropriate value
            bool actual;

            actual = target.IsReusable;
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Exemplo n.º 4
0
 /// <summary>
 /// Handles the <see cref="Control.Load"/> event.
 /// </summary>
 /// <param name="e">An <see cref="EventArgs"/> object that contains the event data.</param>
 protected override void OnLoad(EventArgs e)
 {
     base.OnLoad(e);
     _candidatePhotoPanel.Visible = _change.Visible = _delete.Visible = ProfilePhotoHandler.CustomPhotoExists(CPProfile.Cid);
     _photoUpload.Attributes.Add("size", "28"); // width of file inputs can only be set via size attribute
     // disable upload button upon first click
     _upload.OnClientClick = "this.disabled=true;" + Page.ClientScript.GetPostBackEventReference(_upload, string.Empty);
     ShowGreeting();
 }
Exemplo n.º 5
0
        public void GetPhotoRepositoryPathTest()
        {
            string expected = string.Empty;             // TODO: Initialize to an appropriate value
            string actual;

            actual = ProfilePhotoHandler.GetPhotoRepositoryPath();
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Exemplo n.º 6
0
        public void CustomPhotoExistsTest()
        {
            string cid      = string.Empty;    // TODO: Initialize to an appropriate value
            bool   expected = false;           // TODO: Initialize to an appropriate value
            bool   actual;

            actual = ProfilePhotoHandler.CustomPhotoExists(cid);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Exemplo n.º 7
0
        /// <summary>
        /// Deletes the current user-supplied photo on file for the candidate, if available.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">An <see cref="EventArgs"/> object that contains the event data.</param>
        protected void DeletePhoto(object sender, EventArgs e)
        {
            string photoPath = ProfilePhotoHandler.GetPhotoFilePath(CPProfile.Cid);

            if (File.Exists(photoPath))
            {
                File.Delete(photoPath);
            }
            ShowGreeting();
            _updatePanel.Update();
        }
Exemplo n.º 8
0
        public void ProfilePhotoHandlerConstructorTest()
        {
            ProfilePhotoHandler target = new ProfilePhotoHandler();

            Assert.Inconclusive("TODO: Implement code to verify target");
        }