FAQ Database Discussion Community


How to shim XmlAttribute using Microsoft Fakes in VS 2013

c#,unit-testing,microsoft-fakes
I have the below code I am testing. public Loader(XmlAttributeCollection attributes) { if (attributes == (XmlAttributeCollection)null) throw new ArgumentNullException("attributes"); foreach (XmlAttribute attribute in attributes) { if (attribute.Name.Equals("name", StringComparison.OrdinalIgnoreCase)) { name = attribute.Value; } else if (attribute.Name.Equals("type", StringComparison.OrdinalIgnoreCase)) { loaderType = attribute.Value; } else { loaderAttributes.Add(attribute.Name, attribute.Value); } } } Is...

How can I fake Assembly.LoadFile and Assembly.GetTypes?

c#,unit-testing,visual-studio-2013,microsoft-fakes
I'm struggling to fake these two lines of code: Assembly asm = Assembly.LoadFile(fileName); Type[] asmTypes = loggerAssembly.GetTypes(); When I type System.Reflection.ShimAssembly there is no such type as ShimAssembly like for example in the case of System.IO.ShimFile but only a StubAssembly. I could refactor the code and do it with a...

How to throw an exception from the method with return type as void using Microsoft Fakes on VS 2013

c#,stub,microsoft-fakes,shim
I have the following code I am unit testing. public static MyConfiguration GetConfig(string sectionName) { if (!Initialized) { try { InitializeEnv(); // Method is present but no implementation yet. } finally { Initialized = true; if (configurationReader == null) { configurationReader = ConfigurationValueReader.ConfigurationReader(); } } } return (MyConfiguration)configurationReader.ReadSection(sectionName, new MyConfigurationHandler());...

How I can stub IDBconnection

unit-testing,mstest,stub,microsoft-fakes,shim
I am writting Unit Test for my database connection. I have following class Public class A { public IDbConnection _dbConnection; public A() { _dbConnection = new SqlConnection(connectionStringName); } public int ExecuteNoneQuery(CommandDefination command) { return _dbConnection.Execute(command); } } I want to test this class, how I can test with Microsoft Stub/Shim...

How to unit test an abstract class using Microsft Fakes framework

c#,unit-testing,microsoft-fakes,pex
I have the following abstract class for which I want to write a unit test. I am new to Microsoft Fakes and so far I have only used it for testing public classes. public abstract class ProvideBase { private string tag = string.Empty; public string Tag { get { return...

Convert the Pex TestMethods of VS 2010 to the VS2013 with Microsoft Fakes

c#,unit-testing,microsoft-fakes,pex
I am trying to convert the below pex testmethod to a normal unit test. Though I am planning to use Microsoft Fakes where it is required , I want to understand few things first. [TestMethod] [PexGeneratedBy(typeof(ErrorLogTest))] public void Initialize139() { ErrorLog errorLog; NameValueCollection nameValueCollection; errorLog = new ErrorLog(); errorLog.MyProperty =...

valid use of Shim in a Test Method in VS 2013 for c# code

c#,unit-testing,microsoft-fakes
I have the below test method code : [TestMethod] public void TestWithNotNull() { using (ShimsContext.Create()) { ShimMyConfiguration.Constructor = @this => new ShimMyConfiguration() { return; }; ShimMyConfiguration.AllInstances.LoadValuesFromConfigXmlNode = (a,b) => { return; }; var _MyConfigurationHandler = new MyConfigurationHandler(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml("<Common.Mys><Mys><add name=\"LoggingErrorMessage\"/><remove...