Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GatewayException constructor is marked as internal #20

Open
Mark-Wilkins opened this issue Nov 6, 2019 · 4 comments
Open

GatewayException constructor is marked as internal #20

Mark-Wilkins opened this issue Nov 6, 2019 · 4 comments

Comments

@Mark-Wilkins
Copy link

I am attempting to unit test some code when handling a GatewayException. I wish to mock the AuthorisationBuilder class and Setup Execute to throw a GatewayException. It is not possible as the ResponseCode and ResponseMessage setters are marked as private and the constructor to the class is marked as internal.

The code below will not compile as the constructor is internal.

var mockedAuthBuilder = new Mock<AuthorizationBuilder>();
mockedAuthBuilder.Setup(x => x.Execute(It.IsAny<string>())).Throws(new GatewayException("message", "code", "responseMessage"));

Why would the constructor be marked as internal? Is there something I'm missing here?

@russelleverett
Copy link

russelleverett commented Nov 6, 2019

Thanks for the feedback. It's all about scoping the objects. The constructor to the GatewayException object is marked internal as it's not intended for creation outside of the SDK. In the same vein the ResponseCode and ResponseMessages setters are private as they're only intended to be set by the class constructor.

@Mark-Wilkins
Copy link
Author

What would be your recommended approach for unit testing when a Gateway exception is thrown?

@russelleverett
Copy link

I am not super familiar with Mock and how it works, so apologies in advance if these are poor suggestions. In your above example code it looks like you just want it to throw a GatewayException with a set response code/message whenever you call "Execute()". Seems to me you could create your own GatewayException object (GatewayExceptionEx) and throw that instead?

@Mark-Wilkins
Copy link
Author

Thanks very much for the feedback and suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants