Visual studio 2010 Premium MSTest bug?

The following is the test code.

namespace ConsoleApplication2
    class MyClass {}
    class Program
        static void Main(string[] args) { }

        List<MyClass> Test() { return new List<MyClass>(); }

Then using Visual studio create a union test for method Test().

    public void TestTest()
        Program_Accessor target = new Program_Accessor(); // TODO: Initialize to an appropriate value
        List<MyClass_Accessor> actual;
        actual = target.Test();
        Assert.IsTrue(actual != null);

It will get the following exception when running the test. How to workaround the issue?

Test method TestProject1.ProgramTest.TestTest threw exception:  
System.InvalidCastException: Unable to cast object of type 'System.Collections.Generic.List`1[ConsoleApplication2.MyClass]' to type 'System.Collections.Generic.List`1[ConsoleApplication2.MyClass_Accessor]'.

I tried the following method and it doesn't work too.

IEnumerable<MyClass> Test1() { return new List<MyClass>(); }


Your program and your method are not public so MSTest and any other code cannot call it. MS Test built wrapper Program_Accessor to use your code through reflection.

Change your code to use public access modifier and regenerate the test. It is the easiest way to learn unit-testing.

public class Program
   public class MyClass{}

   static void Main(string[] args) { }

   public List<MyClass> Test() { return new List<MyClass>(); }

You may use InternalsVisibleToAttribute if you do not want to make MyClass public.

Friend Assemblies in MSDN

Need Your Help

Dojo DataGrid height resize not working

javascript dojo dojox.grid.datagrid

I'm trying a simple "resize" behavior with a Dojo DataGrid object. The "width" is working fine as expected. However "height" is not working, and the Grid is displayed only with the initial rendering

regular expression: replace match with its index

regex string replace

How can I transform the string "a b a c d a a" into the string "1 b 2 c d 3 4" with a regular expression?