M
M
Maxim2019-08-16 16:21:33
.NET
Maxim, 2019-08-16 16:21:33

How to test a method that uses an Assembly?

I have developed a method that creates a ResourseManager based on an Assembly. I want to test.
Tried to make a simple mock for Assembly

mock
var expected = new String[] { };
var mock = new Mock<Assembly>();
mock.Setup(a => a.GetManifestResourceNames()).Returns(expected);

var asm = mock.Object;
var rm = new ResourceManager("", asm); // asm isn't runtime assembley

But there was a problem, ResourseManager requires RealtimeAssembley
constructor

public ResourceManager(String baseName, Assembly assembly)
        {
            if (null==baseName)
                throw new ArgumentNullException("baseName");
 
            if (null==assembly)
                throw new ArgumentNullException("assembly");
            Contract.EndContractBlock();
 
            if (!(assembly is RuntimeAssembly))
                throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"));
 //....

How to test the method?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander +, 2019-08-16
@AlexanderMi

Try on
var mock = new Mock<_Assembly>();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question