I am trying to write a unit test for a class that internally calls the static function Assembly.ReflectionOnlyLoadFrom(string). I would like to Arrange that call to return a Mock Assembly.
Is this even possible?
Below are my two approaches thus far, both ended with my arrangement being bypassed and the internal function being executed:
Is this even possible?
Below are my two approaches thus far, both ended with my arrangement being bypassed and the internal function being executed:
Mock.SetupStatic<Assembly>();
Mock.Arrange(() => Assembly.ReflectionOnlyLoadFrom(Arg.AnyString)).Returns(Mock.Create<Assembly>());
var test = Assembly.ReflectionOnlyLoadFrom(
"Some Assembly"
);
//this will throw an exception instead of returning the mock Assembly
Mock.Partial<Assembly>().For<
string
>((s) => Assembly.ReflectionOnlyLoadFrom(s));
Mock.Arrange(() => Assembly.ReflectionOnlyLoadFrom(Arg.AnyString)).Returns(Mock.Create<Assembly>());
var test = Assembly.ReflectionOnlyLoadFrom(
"Some Assembly"
);
//this will throw an exception instead of returning the mock Assembly