or
var config = Mock.Create<ApplicationConfigurationBase>();
Mock.Arrange(() => config.CompositionContainer).Returns(new CompositionContainer());



// works fine.var test = Mock.Create<HttpRequestException>(Constructor.Mocked);// throws exceptionvar exception = Mock.Create<HttpEntityException>(Constructor.Mocked);// HttpRequestException is from NuGet Package Microsoft.Net.Http.2.1.10public class HttpEntityException : HttpRequestException{ public HttpEntityException(HttpResponseMessage response) : base(response.ReasonPhrase) { this.Response = response; } public HttpStatusCode StatusCode { get { return this.Response.StatusCode; } } public HttpResponseMessage Response { get; private set; }}

[TestClass] public class FooTest { [TestMethod] public void Test_MockStaticClass() {
//By no means able to Mock the below static class Mock.SetupStatic(typeof(Foo), Behavior.Loose, StaticConstructor.Mocked);//gives error of constraint } } public static class Foo { static Foo() { } public static List<T> AllFoos<T>() where T : Base, ICloneable { return new List<T>(); } } [Serializable] [DataContract] public abstract class Base { public Base() { } }

[Test]public void DirectoryTest(){ Mock.SetupStatic(typeof (Directory), Behavior.CallOriginal, StaticConstructor.Mocked); Mock.Initialize(typeof (Directory)); // w/ or w/o this line - same behavior Mock.Arrange(() => Directory.GetDirectories(Arg.AnyString, Arg.AnyString, Arg.IsAny<SearchOption>())) .IgnoreArguments() // w/ or w/o this line - same behavior .IgnoreInstance() // w/ or w/o this line - same behavior .Returns(() => new[] {"somedummydirectory"}); // throws ArgumentNullException here var test = Directory.GetDirectories(null, "*", SearchOption.TopDirectoryOnly).ToList(); Assert.IsNotNull(test); Assert.AreEqual(1, test.Count); Assert.AreEqual("somedummydirectory", test[0]);}