Question

I am trying to wrap my head around starting to implement unit tests in a C# project which makes use of AWS S3 buckets.

Despite only really looking into it briefly, I understand that almost anything that is external to the project must be mocked as to "guarantee" predictable results.

In short I am trying to pass a static class (which is both abstract and sealed) as an argument which restricts the parameter to an interface I have defined (at the moment only consisting of AWSClientFactory.CreateAmazonS3Client(string, string, RegionEndpoint).

However, I cannot figure out how to get this class passed by reference (AWSClientFactory), and through extensive research, I don't see any way of doing so.

As I am going to need to pass through cloud another provider (which will imitate the S3 API) through this same method, I would have thought this would have been an acceptable solution, to both this and passing mock classes implemented through the interface.

What would be the best way to implement this with the same sort of structure, whereby identical methods are called from different static classes?

Was it helpful?

Solution

You can't obtain an instance of static class. Thus, you can't get a reference to it, because there's nothing to get reference to. That's why you shouldn't misuse static classes, if you're planning to write unit tests later.

To achieve what you want, you can make your own interface, and make some implementations of this interface. One of this implementation will wrap AWSClientFactory.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top