or
[TestMethod()] public void FooSubmitTest() { Mock.SetupStatic<Foo>(); Foo.Submit(); Mock.Assert(() => Foo.Submit()); }public class Foo { public static void Submit() { throw new NotImplementedException(); } throw new NotImplementedException();
public class ClassToMock { public int Member { get; set; } public ClassToMock(int member) { // Performs some checks if (member <= 0) throw new ArgumentException("Member must be positive"); Member = member; } public ClassToMock() { } } public class ClassToMock2 { public int Member { get; set; } public ClassToMock2() { } public ClassToMock2(int member) { // Performs some checks if (member <= 0) throw new ArgumentException("Member must be positive"); Member = member; } }[TestMethod] public void TestMethod1() { var classToMock = Mock.Create<ClassToMock>(); => Throws ArgumentException Assert.IsNotNull(classToMock); } [TestMethod] public void TestMethod2() { var classToMock2 = Mock.Create<ClassToMock2>(); Assert.IsNotNull(classToMock2); }Thanks for your help.
I am just starting with JustMock and have a question related to your example in documentation on this page:
http://www.telerik.com/help/justmock/basic-usage-mock-internal-types-via-proxy.html
I have classes similar to this sample ( internal is not important here it could be public ):
internal class FooInternal { internal FooInternal() { builder = new StringBuilder(); } public StringBuilder Builder { get { return builder; } } private StringBuilder builder; } What I would like to do is to get my class (FooInternal in this case) to instanciate a Mock of another class (StringBuilder here)...
The only way I can see this possible is by mocking the (FooInternal) constructor itself. Is this possible ?
Thanks !
public interface I1 { }public interface I2 : I1{ void Test();}[TestMethod()]public void MyClassConstructorTest(){ this.Test<I2>();}public void Test<T>() where T : I1{ T t = Mock.Create<T>(); bool called = false; Mock.NonPublic.Arrange(t, "Test").DoInstead(() => called = true);}MethodInfo method = t.GetType().GetMethod("Test");