Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6898199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:15:56+00:00 2026-05-27T07:15:56+00:00

I am trying to upload an image to a cloud and i want to

  • 0

I am trying to upload an image to a cloud and i want to be able to test this,
here is what i have tried already, I dont really understand fully what im doing, so if somebody could tell me what to do, I would appreciate it.

I have included the main method for this and the test of that method so far.

public static String UploadToCloud(string fileName)
    {
        try
        {
            SetUpConnection();
            #region Upload a File from local storage to the Cloud
            // Get a reference to the blob.
            blob = blobContainer.GetBlobReference("Images/" + fileName.Substring(fileName.LastIndexOf('\\')));
            blob.UploadFile(fileName);
            return blob.Uri.ToString();
            #endregion
        }
        catch (StorageClientException e)
        {
            Console.WriteLine("Storage client error encountered: " + e.Message);
            return "Upload failed";
        }
    }

/// <summary>
    ///A test for UploadToCloud
    ///</summary>
    [TestMethod()]
    public void UploadToCloudTest()
    {
        string fileName = "https://kevin.blob.core.windows.net/cp300/Images//skin-mole.jpg";
        Image expected = Image.FromFile(@"C:\Users\Public\Pictures\Sample Pictures\skin-mole.jpg");
        string actual;
        actual = CloudConnection.UploadToCloud(fileName);

        //Compares to images and checks they are exactly the same
        MemoryStream ms = new MemoryStream();
        expected.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
        String expectedBitmap = Convert.ToBase64String(ms.ToArray());
        ms.Position = 0;
        actual.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
        String actualBitmap = Convert.ToBase64String(ms.ToArray());

        Assert.AreEqual(expectedBitmap, actualBitmap); 

        //Assert.AreEqual(expected, actual);
        //Assert.Inconclusive("Verify the correctness of this test method.");
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:15:57+00:00Added an answer on May 27, 2026 at 7:15 am

    I’d say that this isn’t really a unit test — you’re trying to upload something to an external service that you have no control over and can’t guarantee that the results are going to be the same from run to run.

    What you’ve written is an integration test, which is a test of how two or more software components work together. In this case, the two components are

    • Your code
    • The cloud upload API

    There’s nothing wrong with integration tests, but they tend to be slower (in this case, due to uploading a file to the cloud), and they tend to be more brittle. Your integration test, for example, would break if the cloud service wasn’t available. Nothing changed in your code, nothing changed in your test, but the test’s results were different.

    If you wanted to unit test your UploadToCloud method, I’d recommend that you start by wrapping your “cloud uploading” functionality in a class that implements an interface, e.g. ICloudUploader. Then you can mock out the pieces that actually communicate with your cloud service, and ensure that the functionality of your code is correct under all of the situations you want to test (successful upload, service is unavailable, upload fails due to file being too big, whatever).

    For mocking out a class, you can either roll your own (write a class that implements your interface, for example public class FakeCloudUploader : ICloudUploader, or look into a mocking framework like Moq or RhinoMocks.

    As for the test method you provided, it’s not really testing the output of the method. It should validate that the string you get back from UploadToCloud is the value you expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this Form I am trying to upload my image but every time
Im struggling here for a lot, Im trying to upload an image from iphone
I am trying to upload an image hosted on a third party server. Here
I have been trying to upload an image using CodeIgniter's File Upload class. The
Hi i'm trying to upload an image using a php script. And whats really
I am trying to upload an image on facebook. Using this code private void
I am trying to upload an image,create thumbnail but i get an error. Here
I'm trying to upload an image using this script: $photoName = $uploadedPhoto[name]; $photoType =
I am trying to upload an image to ftp server. I am able to
I was trying to upload an image, but I got this message: finfo_open() [function.finfo-open]:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.