I'm trying to make a mocked object ( HttpWebRequest.GetResponse() ) return another mocked object ( HttpWebResponse ). and I'm getting:
TypeMock.TypeMockException:
*** No method GetResponse in type System.Net.HttpWebRequest returns TypeMock.MockObject
at TypeMock.Mock.a(String A_0, Object A_1, Boolean A_2, Boolean A_3, Int32 A_4, Type[] A_5)
at TypeMock.Mock.ExpectAndReturn(String method, Object ret, Int32 timesToRun, Type[] genericTypes)
at TypeMock.Mock.ExpectAndReturn(String method, Object ret, Type[] genericTypes)
at SI.Swiftbit.P2p.Tests.TrackerClientTest.TestNormalGetPeers() in c:Documents and SettingsSpookyETMy DocumentsVisual Studio 2005ProjectsSI.SwiftbitSI.Swiftbit.P2p.TestsTrackerClientTest.cs:line 138
For this code:
#region Using Directives
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Web;
using System.Text;
using NUnit.Framework;
using TypeMock;
using SI.Swiftbit.P2p;
using SI.Swiftbit.P2p.Utilities;
#endregion
namespace SI.Swiftbit.P2p.Tests
{
[TestFixture]
public class TrackerClientTest
{
TrackerClient trackerClient;
Mock httpWebRequest;
Mock httpWebResponse;
byte[] filesKey = Encoding.UTF8.GetBytes("files");
byte[] completeSourcesKey = Encoding.UTF8.GetBytes("complete");
byte[] incompleteSourcesKey = Encoding.UTF8.GetBytes("incomplete");
byte[] downloadedKey = Encoding.UTF8.GetBytes("downloaded");
byte[] nameKey = Encoding.UTF8.GetBytes("name");
[SetUp]
public void Initialize()
{
MockManager.Init();
httpWebRequest = MockManager.Mock(typeof(HttpWebRequest));
httpWebResponse = MockManager.Mock(typeof(HttpWebResponse));
trackerClient = new TrackerClient(
new Uri("http://announce.com:6969/announce"));
}
[TearDown]
public void Dispose()
{
MockManager.Verify();
}
[Test]
public void TestNormalGetPeers()
{
PeersInfo peersInfo;
Peer[] peers;
SortedDictionary<byte[], object> responseData =
new SortedDictionary<byte[], object>(new ByteArrayComparer());
List<SortedDictionary<byte[], object>> peersList =
new List<SortedDictionary<byte[], object>>();
SortedDictionary<byte[], object> peer1 =
new SortedDictionary<byte[], object>(new ByteArrayComparer());
SortedDictionary<byte[], object> peer2 =
new SortedDictionary<byte[], object>(new ByteArrayComparer());
byte[] peerId1 = new byte[20]
{
1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
byte[] peerId2 = new byte[20]
{
4, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
byte[] infoKeyHash = new byte[20]
{
7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
string warningMessage = "This is a tracker warning.";
peer1.Add(Encoding.UTF8.GetBytes("peer id"), peerId1);
peer1.Add(
Encoding.UTF8.GetBytes("ip"),
Encoding.UTF8.GetBytes("1.1.1.1"));
peer1.Add(Encoding.UTF8.GetBytes("port"), 6969);
peer2.Add(Encoding.UTF8.GetBytes("peer id"), peerId2);
peer2.Add(
Encoding.UTF8.GetBytes("ip"),
Encoding.UTF8.GetBytes("2.2.2.2"));
peer2.Add(Encoding.UTF8.GetBytes("port"), 7000);
responseData.Add(Encoding.UTF8.GetBytes("interval"), 5);
responseData.Add(Encoding.UTF8.GetBytes("min interval"), 2);
responseData.Add(Encoding.UTF8.GetBytes("complete"), 10);
responseData.Add(Encoding.UTF8.GetBytes("incomplete"), 20);
responseData.Add(
Encoding.UTF8.GetBytes("warning message"),
warningMessage);
responseData.Add(Encoding.UTF8.GetBytes("peers"), peersList);
httpWebRequest.ExpectAndReturn(
"GetResponse",
httpWebResponse,
null);