Telerik Forums
JustMock Forum
2 answers
1.2K+ views
I've set up a mocked object with a couple of arranged methods. How do I pass in parameters to exercise the arranged methods?
When i call target.GetValue with 5/Aug/2012, the GetData method receives the value of 1/Jan/1983 in its startDate parameter. What do i need to do in order for the arranged methods to receive the required parameter value?

------- set up mocking ------------
            var dataAccess = Mock.Create<IDataAccess>();
            Mock.Arrange(() => dataAccess.DataExists(Arg.IsAny<SiteLocation>(), Arg.Matches<DateTime>(d => d >= startDate), Arg.Matches<DateTime>(d => d <= endDate))).Returns(true);
            Mock.Arrange(() => dataAccess.RetrieveData(Arg.IsAny<SiteLocation>(), Arg.Matches<DateTime>(d => d >= startDate), Arg.Matches<DateTime>(d => d <= endDate))).Returns(data);
            DataLoader target = new DataLoader(dataAccess);

            // act
            int actual;
            actual = target.GetValue(location, date)[0];

-------------------- called method on non-mocked object ---------------
        public List<int> GetValue(SiteLocation location, DateTime date)
        {
            var data = new List<int>();

            var temp = GetData(location, date, DateTime.Now);
            if (temp.Count > 0)
            {
                // todo: if there are gaps in the data fill with -999
                data = temp.Select(t => t.Value).ToList();
            }
            else { }

            return data;
        }

------------------------ called method on mocked object ------------------
        public List<DataRecord> GetData(SiteLocation location, DateTime startDate, DateTime endDate)
        {
            var data = new List<DataRecord>();

            if (dataAccess.DataExists(location, startDate, endDate))
            {
                data = dataAccess.RetrieveData(location, startDate, endDate);
            }else{}

            return data;
        }
Simon
Top achievements
Rank 1
 answered on 27 Jun 2013
6 answers
237 views
VS 2012 +Update 2
.NET 4.5 C# Project
JustMock 2013 Q2
NCrunch
ReSharper

With both NUnit and MSpec unit tests I am constantly receiving a "System.BadImageFormatException : Index not found."

Simple profiled mock:
var config = Mock.Create<ApplicationConfigurationBase>();
Mock.Arrange(() => config.CompositionContainer).Returns(
new CompositionContainer());

It doesn't matter if I use NCrunch or ReSharper's test runner. Both display the exception. I followed the documentation given for NCrunch integration. I've also tried the JustMock_2013.2.624_Dev internal build which led to even worse results and erratic behavior.

Any ideas on how to solve this issue would be much appreciated.

Thanks!
Kaloyan
Telerik team
 answered on 27 Jun 2013
3 answers
115 views
What is the status for VS2012 CodeCoverage and JustMock?

Some of my smaller projects work as expected, but my larger projects still throw errors when I try to mock/assert something.
Kaloyan
Telerik team
 answered on 25 Jun 2013
13 answers
169 views
Hi

I'm evaluating JustMock and notice it doesn't play well with NCrunch when using elevated mode. Given that NCrunch is a great tool, I was wondering if there is anything you could do to help. The following link highlights the problem the developers are having:
http://forum.ncrunch.net/yaf_postsm2596_Using-NCrunch-with-JustMock.aspx?find=unread#post2596 

Thanks
Russell Mason
Kaloyan
Telerik team
 answered on 14 Jun 2013
1 answer
69 views
Why the only JustMock setup requires to quit SQL Server Management Studio?
Kaloyan
Telerik team
 answered on 13 Jun 2013
1 answer
204 views
Couldn't figure out why this is happening.

System.TypeLoadException was unhandled by user code
  HResult=-2146233054
  Message=Method 'InternalToString' on type 'HttpEntityExceptionProxy+644d129a7a854c8c9d115708bc631cd4' from assembly 'Telerik.JustMock.Dynamic, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is overriding a method that is not visible from that assembly.
  Source=mscorlib
  TypeName=HttpEntityExceptionProxy+644d129a7a854c8c9d115708bc631cd4
  StackTrace:
       at System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule module, Int32 tk, ObjectHandleOnStack type)
       at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
       at System.Reflection.Emit.TypeBuilder.CreateType()
       at    .   .   ()
       at Telerik.JustMock.DynamicProxy.Proxy.   ()
       at Telerik.JustMock.DynamicProxy.ProxyFactory.Create()
       at Telerik.JustMock.DynamicProxy.Fluent.FluentProxy.NewInstance()
       at Telerik.JustMock.DynamicProxy.Proxy.Create(Type type, Action`1 action)
       at    .   .   (Type   ,      )
       at    .   .   (     )
       at    .   .   (Behavior    , Boolean    )
       at    .   .   ()
       at Telerik.JustMock.FluentMock.Create()
       at Telerik.JustMock.Mock.Create(Type target, Action`1 settings)
       at Telerik.JustMock.Mock.Create(Type targetType, Constructor constructor, Behavior behavior)
       at Telerik.JustMock.Mock.Create[T](Constructor constructor)
       at Tests.HttpEntityExceptionExtensions_GetExceptionMessage_with_null_Response_returns_null() in c:\HttpEntityExceptionExtensionsTests.cs:line 34

// works fine.
var test = Mock.Create<HttpRequestException>(Constructor.Mocked);
 
// throws exception
var exception = Mock.Create<HttpEntityException>(Constructor.Mocked);
 
// HttpRequestException is from NuGet Package Microsoft.Net.Http.2.1.10
public 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; }
}

Currently have JustMock_2013.2.603_Dev.msi installed.

Kaloyan
Telerik team
 answered on 11 Jun 2013
8 answers
227 views
Hello, I started to get this message, I guess since I installed a test version of JustMock. But the project which throws the error does not use JustMock for anything, and does not have any references to it

Could not load file or assembly 'Telerik.CodeWeaver.Api, Version=1.0.0.0, Culture=neutral, PublicKeyToken=87210992829a189d' or one of its dependencies.....
Kaloyan
Telerik team
 answered on 11 Jun 2013
16 answers
196 views
In the following code unable to mock the static class- Thanks in advance for kind act
[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() { }
   }
Kaloyan
Telerik team
 answered on 10 Jun 2013
1 answer
159 views
var content = Mock.Create<HttpContent>();

throws:

System.TypeLoadException was unhandled by user code
  HResult=-2146233054
  Message=Method 'TryComputeLength' in type 'HttpContentProxy+8f0c5d24e08246c69d913c472013ba3d' from assembly 'Telerik.JustMock.DynamicStrong, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8b221631f7271365' does not have an implementation.
  Source=mscorlib
  TypeName=HttpContentProxy+8f0c5d24e08246c69d913c472013ba3d
  StackTrace:
       at System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule module, Int32 tk, ObjectHandleOnStack type)
       at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
       at System.Reflection.Emit.TypeBuilder.CreateType()
       at    .   .   ()
       at Telerik.JustMock.DynamicProxy.Proxy.   ()
       at Telerik.JustMock.DynamicProxy.ProxyFactory.Create()
       at Telerik.JustMock.DynamicProxy.Fluent.FluentProxy.NewInstance()
       at Telerik.JustMock.DynamicProxy.Proxy.Create(Type type, Action`1 action)
       at    .   .   (Type   ,      )
       at    .   .   (     )
       at    .   .   (Behavior    , Boolean    )
       at    .   .   ()
       at Telerik.JustMock.Mock.Create(Type target, Behavior behavior, Object[] args)
       at Telerik.JustMock.Mock.Create(Type target, Object[] args)
       at Telerik.JustMock.Mock.Create[T]()
       at TEST() in c:\xxx.cs:line 61
  InnerException: 

Kaloyan
Telerik team
 answered on 10 Jun 2013
3 answers
94 views
I cannot find a way to actually have my mock work.

Given code like this:

[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]);
}


What am I missing? (using NUnit 2.6.2 with the Resharper test runner).
Kaloyan
Telerik team
 answered on 07 Jun 2013
Narrow your results
Selected tags
Tags
+? more
Top users last month
Ambisoft
Top achievements
Rank 2
Iron
Pascal
Top achievements
Rank 2
Iron
Matthew
Top achievements
Rank 1
Sergii
Top achievements
Rank 1
Iron
Iron
Andrey
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Ambisoft
Top achievements
Rank 2
Iron
Pascal
Top achievements
Rank 2
Iron
Matthew
Top achievements
Rank 1
Sergii
Top achievements
Rank 1
Iron
Iron
Andrey
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?