Telerik Forums
JustMock Forum
3 answers
105 views
Hi,
We are currently evaluating JustMock against Moq.

For a silverlight project I want to test the view generation. For this I have a viewmodel interface
public interface IViewModel
{
        string DisplayName { get; }
        Brush BackgroundBrush { get; }
}

And a UserControl as xamlx:
<UserControl x:Class="View" [...]>
    <Grid x:Name="LayoutRoot" Background="{Binding Path=BackgroundBrush}">
        <Border BorderBrush="Black" BorderThickness="1">
            <TextBlock Text="{Binding Path=DisplayName}" />
        </Border>
    </Grid>
</UserControl>
 
The test looks like this:
[TestMethod]
[Asynchronous]
public void BindingTest_BackgroundBrushIsSet()
{
    var target = new View();
    var datacontextMock = Mock.Create<IViewModel>();
    var expectedBackground = new SolidColorBrush(Colors.Purple);
    target.DataContext = datacontextMock;
    Mock.Arrange(() => datacontextMock.BackgroundBrush).Returns(expectedBackground);
    Mock.Arrange(() => datacontextMock.DisplayName).Returns(string.Empty);
 
    AsyncWaitForFrameworkElementLoaded(target);
    AssertCallback
        (() =>
        {
            var layoutRoot = target.FindName<Grid>("LayoutRoot");
            Assert.AreEqual(expectedBackground, layoutRoot.Background);
        });
}

The test creates a View and waits for it to be loaded. Then the backgroundcolor is checked. It fails using JustMock (layoutRoot.Background is null), while it passes using Moq.
Looking at the Debug Output it tells that the Property BackgroundBrush could not be found on IViewModelProxy\+a45306a40f1f4947a9984002599ac998. Checking by hand the watch window gives me the proper type which only contains the mock framework properties. The same is true for a test checking DisplayName.

Is there anything I'm missing using JustMock?

Kaloyan
Telerik team
 answered on 18 Mar 2013
1 answer
31 views
Greetings,

I know that JustMock doesn't work directly with WP7 from reading this post, yet the proposed solution doesn't apply to WP8, as a Silverlight project won't allow me to add a WP8 assembly to it...

Is there any workaround to use JustMock with WP8 assemblies?

Thanks,

Pedro Lamas
Kaloyan
Telerik team
 answered on 18 Mar 2013
1 answer
88 views
I'm trying to get JustMock setup on our TFS server and I'm having an issue. I installed JustMock on our build server and then followed these steps http://www.telerik.com/help/justmock/integration-code-activity-workflow.html. Once that was finished I checked everything in and ran the build. I came back as failed with the following message,

TF215097: An error occurred while initializing a build for build definition \TOCO\BuildDefinitionTest: Cannot create unknown type '{http://schemas.microsoft.com/netfx/2009/xaml/activities}Variable({clr-namespace:Telerik.JustMock.Build.Workflow;assembly=Telerik.JustMock.Build.Workflow}ReturnCodes)'.

I made sure the Workflow library is in the directory that is referenced in the Version Control path to custom assemblies. 

Any ideas on why this is happening? 
Kaloyan
Telerik team
 answered on 12 Mar 2013
2 answers
93 views
I grabbed Alpha 3 this morning from NuGet and I seem to be unable to mock EF6 the way I would normally mock OpenAccess. When I try a simple:

var test = Mock.Create<DemoEntities>();

I get a TypeLoadException:

Method 'CallValidateEntity' on type 'DemoEntitiesProxy+53c69f86fe444525a693c487adc77799' 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.

Any thoughts?
Kaloyan
Telerik team
 answered on 11 Mar 2013
14 answers
1.1K+ views
I am using JustMock in ~140 tests, and am experiencing some strange issues with a group of test failing when the entire set of test is run, but passing when run independently.  Currently it takes 3 test runs for all test to pass, with no changes to the code between runs.

They seem to be failing because mocks are not correctly intercepting method/property calls.

Are there any known issue with the mocks interfering with each other when used in multiple tests?  Due to legacy library use there is a lot of Final and Static mocking in the tests, could this have something to do with it?
Kaloyan
Telerik team
 answered on 08 Mar 2013
1 answer
284 views
I would like to stop the JustMock Expired dialog from popping up everytime I start Visual Studio. How do I do this?
Kaloyan
Telerik team
 answered on 05 Mar 2013
0 answers
186 views
Since JustMock Q1 2013 release we marked Mock.DoNotUseProfiler() method as an obsolete method. This can break your test project build.

We recommend updating your unit tests and avoid using it as it is considered bad practice. In case you have to call  Mock.DoNotUseProfiler() method you can vote here http://feedback.telerik.com/Project/105/Feedback/Details/42251-make-mock-donotuseprofiler-method-non-obsolete
Mihail
Top achievements
Rank 1
 asked on 28 Feb 2013
3 answers
128 views
I have generated code, with this constructor:

internal Priority(Int32 priorityId, String name, Int32 rank, Int32 expirationBuffer, Boolean isLiveMicrophone, Boolean isEmergency, Boolean isRepeated, Int32 repeatBuffer, Single levelAdjustment, Boolean isInterruptible, Int32 percentAvailable)

When I mock the GetAll() method of the class (that calls the above constructor), it throws the "JIT Compiler encountered an internal limitation." error:

Mock.Arrange(() => Dvams.Priority.GetAll()).Returns(new Dvams.PriorityList());
var p = Dvams.Priority.GetAll();

JustMock version 2012.2.813.9.
If I modify the generated code to use only 8 parameters, it works fine. (I cant really modify the generated code in production)
Ran on another developers computer, same JustMock version, it works fine. (WHY?)

Any ideas as to how and/or why this is happening?  I would think JustMock would bypass the internals of GetAll(), ignoring the constructor, but it doesnt seem to be the case (at least on my computer).

Thanks,
Brian
Brian Pratt
Top achievements
Rank 1
 answered on 28 Feb 2013
4 answers
134 views
So, I am able to fake out static properties like DateTime.Now from the examples, but I'm having issues faking out the FileInfo objects if I create a new instance of the class in my libraries.  Can anyone help fix the code below?

// MyLibraryClass.cs
public class MyLibraryClass
{
        public void FileInfoDeleteMember(string filename)
        {
            var fi = new FileInfo(filename);
            fi.Delete();
        }
}



// FileInfoTests   
    [TestClass]
    public class FileInfoTests
    {
        static FileInfoTests()
        {
            Mock.Replace<FileInfo>(x => x.Delete()).In<MyLibraryClass>(c => c.FileInfoDeleteMember(Arg.AnyString));            
        }

        [TestMethod]
        public void ShouldNotDeleteFileWhenCalled()
        {
            var called = false;            
            var mlc = new MyLibraryClass();

            Mock.Arrange(() => new FileInfo(Arg.AnyString).Delete()).DoInstead(() => called = true);
                                   
            mlc.FileInfoDeleteMember(@"C:\test.txt");            
            Assert.AreEqual(called, true);            
        }
    }




Kaloyan
Telerik team
 answered on 25 Feb 2013
2 answers
158 views
Hello,

I have installed the commercial version of JustMock. When I run a NUnit-Test using the ReSharper-TestRunner in Visual Studio 2010 the JustMock Profiler is never enabled (Telerik.JustMock.IsProfilerEnabled=false). In the Visual Studio menu 'Telerik -> JustMock -> Enable Profiler' is grayed out (disabling and enabling didn't help ). The Windows EventViewer shows that the profiler has been started:

.NET Runtime version 4.0.30319.296 - The profiler was loaded successfully. Profiler CLSID: '{b7abe522-a68f-44f2-925b-81e7488e9ec0}'. Process ID (decimal): 4288. Message ID: [0x2507].
Any ideas whats going wrong?

Thanks, Tobias

Kaloyan
Telerik team
 answered on 22 Feb 2013
Narrow your results
Selected tags
Tags
+? more
Top users last month
Jay
Top achievements
Rank 3
Bronze
Iron
Iron
yw
Top achievements
Rank 2
Iron
Iron
Stefan
Top achievements
Rank 2
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Bohdan
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Jay
Top achievements
Rank 3
Bronze
Iron
Iron
yw
Top achievements
Rank 2
Iron
Iron
Stefan
Top achievements
Rank 2
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Bohdan
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?