Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,

I am writing unit test cases for repositories using Microsoft fakes,in which one of the repository have unityresolver which throws errors.

Below is mu code for Unity Resolver.
public static TUnityType Create<TUnityType>()
{
return UnityContainer.Resolve<TUnityType>();
}


private static void CreateUnityContainer()
{
UnityContainer container = new UnityContainer();
container.AddNewExtension<interception>();

UnityConfigurationSection unitySection = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
//unitySection.Containers["containerOne"].Configure(container);
unitySection.Configure(container, "containerOne");

string unityPiabInterceptions = ConfigurationManager.AppSettings["UnityPIABInterceptions"];
if (!String.IsNullOrEmpty(unityPiabInterceptions))
{
String[] unityPiabInterceptionsArray = unityPiabInterceptions.Split(';');
foreach (String typeName in unityPiabInterceptionsArray)
{
container.Configure<interception>().SetInterceptorFor(Type.GetType(typeName), new TransparentProxyInterceptor());
}
}

IConfigurationSource configurationSource = ConfigurationSourceFactory.Create();
PolicyInjectionSettings settings = (PolicyInjectionSettings)configurationSource.GetSection(PolicyInjectionSettings.SectionName);
if (null != settings)
{
settings.ConfigureContainer(container, configurationSource);
}

m_InvoiceUnityContainer = container;
}


At this line it throws error UnityConfigurationSection unitySection = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");

Error : unitysection null.

I have all web.config settings because it is working fine normally.



Please help me as i got stucked.

Thanks
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900