I’ve generated unit tests on a private method using Visual Studio’s own “Create Unit Tests…” option.
Great, it works, but if I try to check my code in now I break the build because VS has created a private accessor class in AppData/Local/Temp that is required to build. If I try to put this file in my source tree, it won’t compile as the compiler says it “must define a body”. Really don’t understand this reflection lark…
This is the accessor class:
#region Assembly AgentConfiguration_Accessor.exe, v4.0.30319
// C:\Projects\AgentConfigurationTests\obj\Debug\AgentConfiguration_Accessor.exe
#endregion
using Agent.ConfigurationData;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
namespace Agent.AgentConfiguration
{
[Shadowing("Agent.AgentConfiguration.AgentConfigurationGui")]
public class AgentConfigurationGui_Accessor : BaseShadow
{
protected static PrivateType m_privateType;
[Shadowing(".ctor@0")]
public AgentConfigurationGui_Accessor();
public AgentConfigurationGui_Accessor(PrivateObject value);
[Shadowing("_agentPaths")]
public AgentPaths _agentPaths { get; }
[Shadowing("_agentServiceName")]
public static string _agentServiceName { get; set; }
[Shadowing("UpdateStatus@1")]
public void UpdateStatus(string statusMessage);
}
}
After using the Private Accessors for some time, I had some troubles in getting the code to compile after some branching and merging with our Souce Code Versioning system.
I started researching on the topic and found an article in the Visual Studio Team Test blog. As far as I have understood it, you should not use the Private Accessor classes any more.
There is a blog article in the Generation of Private Accessors (Publicize) and Code Generation for Visual Studio 2010 that states that this feature is not further supported any more:
Of course there are are suggestions about what you could do instead: