Problems Future Mocking TfsTeamProjectCollection

6 posts, 1 answers
  1. Joel
    Joel avatar
    19 posts
    Member since:
    Dec 2011

    Posted 09 Jan 2012 Link to this post

    Following the directions here: http://www.telerik.com/help/justmock/advanced-usage-future-mocking.html 

    I was able to successfully Future Mock classes that I created, but I can't seem to get Future Mocking working with TfsTeamProjectCollection.

    Here are two tests that are failing:

    [TestMethod]
    public void TfsTeamProjectCollection_Create_returns_VersionControlServer()
    {
        // Arrange
        var tfsTeamProjectCollection = Mock.Create<TfsTeamProjectCollection>(Constructor.Mocked);
        var versionControlServer = Mock.Create<VersionControlServer>();
     
        Mock.Arrange(() => tfsTeamProjectCollection.GetService<VersionControlServer>())
            .Returns(versionControlServer)
            .IgnoreInstance();
     
        var newTfsTeamProjectCollection = new TfsTeamProjectCollection(new Uri("about:blank"));
     
        // Act
        var result = newTfsTeamProjectCollection.GetService<VersionControlServer>();
     
        // Assert
        Assert.AreEqual(versionControlServer, result);
    }
     
    [TestMethod]
    public void TfsTeamProjectCollection_Create_throws_NotImplementedException()
    {
        // Arrange
        var tfsTeamProjectCollection = Mock.Create<TfsTeamProjectCollection>(Constructor.Mocked);
        var versionControlServer = Mock.Create<VersionControlServer>();
     
        Mock.Arrange(() => tfsTeamProjectCollection.GetService<VersionControlServer>())
            .Throws(new NotImplementedException())
            .IgnoreInstance();
     
        var newTfsTeamProjectCollection = new TfsTeamProjectCollection(new Uri("about:blank"));
     
        try
        {
            // Act
            newTfsTeamProjectCollection.GetService<VersionControlServer>();
     
            // Assert
            Assert.Fail("An Exception was expected.");
        }
        catch (NotImplementedException)
        {
        }

    Here's a link to a sample project: http://dl.dropbox.com/u/1006254/JustMockTestProject5.zip

  2. Answer
    Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 13 Jan 2012 Link to this post

    Hi Joel,
    Thanks again for sending the sample.

    I found that the issue exists and currently it can be fixed by partially mocking the GerService<T> method. Therefore, I modified your test code in the following way:
    // Arrange
    var tfsTeamProjectCollection = new TfsTeamProjectCollection(new Uri("about:blank"));
    var versionControlServer = Mock.Create<VersionControlServer>();
     
    Mock.Arrange(() => tfsTeamProjectCollection.GetService(typeof(VersionControlServer)))
        .Returns(versionControlServer)
        .IgnoreInstance();
     
    var newTfsTeamProjectCollection = new TfsTeamProjectCollection(new Uri("about:blank"));
     
    //// Act
    var result = newTfsTeamProjectCollection.GetService<VersionControlServer>();
     
    // Assert
    Assert.AreEqual(versionControlServer, result);


    This returns the VersionControlServer instance as expected. However, I also created an PITS item to make it work when used with Mock.Create{T}

    You can further follow the task here:
    http://www.telerik.com/support/pits.aspx#/public/justmock/9330

    Kind Regards,
    Mehfuz
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft R3 2016 release webinar banner
  4. Joel
    Joel avatar
    19 posts
    Member since:
    Dec 2011

    Posted 13 Jan 2012 Link to this post

    Interesting.  I didn't know we could partially mock objects.

    The solution you provided is working for us. 

    Thanks!
  5. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 16 Jan 2012 Link to this post

    Hi Joel,
    It's great to hear that the solution is working for you. In addition you can also keep an eye on the PITS entry for the Mock.Create{T} issue.

    http://www.telerik.com/support/pits.aspx#/public/justmock/9330


    Kind Regards,
    Mehfuz
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. Joel
    Joel avatar
    19 posts
    Member since:
    Dec 2011

    Posted 22 Feb 2012 Link to this post

    I did run into an issue with this workaround.  There was an object with no public constructor that I wasn't able to use this feature with.
  7. Ricky
    Admin
    Ricky avatar
    467 posts

    Posted 28 Feb 2012 Link to this post

    Hi Joel,

    Thanks again for reporting the issue. However, the issue described in the following PITS entry is now resolved and it will be available in the release due in a day or two.

    http://www.telerik.com/support/pits.aspx#/public/justmock/9330

    Please let me know if you still having problem mocking TeamProjectCollection.GetService<T> when combined with Mock.Create and Constructor.Mocked.

    Kind Regards,
    Mehfuz
    the Telerik team

    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top
DevCraft R3 2016 release webinar banner