This is a migrated thread and some comments may be shown as answers.

Calling mocked property over datacontext fails

3 Answers 72 Views
JustMock Free Edition
This is a migrated thread and some comments may be shown as answers.
Florian
Top achievements
Rank 1
Florian asked on 11 Mar 2013, 03:23 PM
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?

3 Answers, 1 is accepted

Sort by
0
Kaloyan
Telerik team
answered on 12 Mar 2013, 02:40 PM
Hi Florian,

It is unfortunate to hear that you are experiencing issues with JustMock.

However, please note us if it is possible to send us an example project, reproducing the matter in order to assist you further.

Thank you in advance.

All the best,
Kaloyan
the Telerik team
Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
0
Florian
Top achievements
Rank 1
answered on 18 Mar 2013, 12:05 PM
Hi,

I have a project ready which reproduces the problem.
How can I send it to you?

Thanks,
Florian
0
Kaloyan
Telerik team
answered on 18 Mar 2013, 12:09 PM
Hi again Florian,

Opening a support ticket and attaching the project in it, is the most appropriate way.

Kind regards,
Kaloyan
the Telerik team
Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
Tags
JustMock Free Edition
Asked by
Florian
Top achievements
Rank 1
Answers by
Kaloyan
Telerik team
Florian
Top achievements
Rank 1
Share this question
or