Calling mocked property over datacontext fails

4 posts, 0 answers
  1. Florian
    Florian avatar
    10 posts
    Member since:
    Apr 2011

    Posted 11 Mar 2013 Link to this post

    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?

  2. Kaloyan
    Admin
    Kaloyan avatar
    872 posts

    Posted 12 Mar 2013 Link to this post

    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.
  3. DevCraft R3 2016 release webinar banner
  4. Florian
    Florian avatar
    10 posts
    Member since:
    Apr 2011

    Posted 18 Mar 2013 Link to this post

    Hi,

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

    Thanks,
    Florian
  5. Kaloyan
    Admin
    Kaloyan avatar
    872 posts

    Posted 18 Mar 2013 Link to this post

    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.
Back to Top