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 9120549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:39:09+00:00 2026-06-17T05:39:09+00:00

I have a fairly simple class that I’m trying to unit test. I’m very

  • 0

I have a fairly simple class that I’m trying to unit test. I’m very new to unit testing in general, and I’m not sure what I should be testing here.

The only test case that I can figure out how to code is a null argument of stream. Besides that, I’m not sure how to test the results of a PutObjectRequest or what else. If I should be using mocks here, how?

public class AmazonS3Service : IAmazonS3Service
{
    private readonly Uri baseImageUrl;
    private readonly Uri s3BaseUrl;
    private readonly string imageBucket;

    public AmazonS3Service()
    {
        imageBucket = ConfigurationManager.AppSettings["S3.Buckets.Images"];

        s3BaseUrl = new Uri(ConfigurationManager.AppSettings["S3.BaseAddress"]);
        baseImageUrl = new Uri(s3BaseUrl, imageBucket);
    }

    public Image UploadImage(Stream stream)
    {
        if (stream == null) throw new ArgumentNullException("stream");
        var key = string.Format("{0}.jpg", Guid.NewGuid());

        var request = new PutObjectRequest
        {
            CannedACL = S3CannedACL.PublicRead,
            Timeout = -1,
            ReadWriteTimeout = 600000, // 10 minutes * 60 seconds * 1000 milliseconds
            InputStream = stream,
            BucketName = imageBucket,
            Key = key
        };

        using (var client = new AmazonS3Client())
        {
            using (client.PutObject(request))
            {
            }
        }

        return new Image
        {
            UriString = Path.Combine(baseImageUrl.AbsoluteUri, key)
        };
    }
}
  • 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-06-17T05:39:10+00:00Added an answer on June 17, 2026 at 5:39 am

    Things I would look at:

    • Mock your configuration manager to return invalid data for the bucket and the URL. (null, invalid urls, invalid buckets)

    • Does S3 support https ? If so mock it, if not, mock it and verify you get a valid error.

    • Pass different kinds of streams in (Memory, File, other types).

    • Pass in streams in different states (Empty streams, streams that have been read to the
      end, …)

    • I would allow the timeouts to be set as parameters, so you can test with really low
      timeouts and see what errors you get back.

    • I would also test with duplicate keys, just to verify the error message. Even though you are using guids, you are storing to an amazon server where someone else could use the S3 API to store documents and could theoretically create a file that appears to be a guid, but could create a conflict down the road (unlikely, but possible)

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

Sidebar

Related Questions

I have a fairly simple class that I want to save to SQL Server
Fairly simple question: I have an init method on my class that has the
Lets say I have a class A that is fairly simple like this -
I have a fairly simple question about grails domain classes. I am not sure
What I'm trying to do is fairly simple. I have two classes: public class
I have a fairly simple class that looks like this: class Person { public:
I have a fairly simple python loop that calls a few functions, and writes
I have been developing a fairly simple app for iOS and Android that parses
We have a fairly simple program that's used for creating backups. I'm attempting to
I have a fairly simple app that takes the input from a user and

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.