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

Problems Future Mocking TfsTeamProjectCollection

5 Answers 80 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Joel
Top achievements
Rank 1
Joel asked on 10 Jan 2012, 03:48 AM
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

5 Answers, 1 is accepted

Sort by
0
Accepted
Ricky
Telerik team
answered on 13 Jan 2012, 12:44 PM
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 >>

0
Joel
Top achievements
Rank 1
answered on 13 Jan 2012, 08:54 PM
Interesting.  I didn't know we could partially mock objects.

The solution you provided is working for us. 

Thanks!
0
Ricky
Telerik team
answered on 16 Jan 2012, 10:37 AM
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 >>

0
Joel
Top achievements
Rank 1
answered on 23 Feb 2012, 12:59 AM
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.
0
Ricky
Telerik team
answered on 29 Feb 2012, 05:55 AM
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 >>
Tags
General Discussions
Asked by
Joel
Top achievements
Rank 1
Answers by
Ricky
Telerik team
Joel
Top achievements
Rank 1
Share this question
or