forked from linguanostra/GoogleMapsAPI.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientAPIMockUtils.cs
More file actions
69 lines (54 loc) · 2.19 KB
/
Copy pathClientAPIMockUtils.cs
File metadata and controls
69 lines (54 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System.IO;
using System.Net;
using GoogleMapsAPI.NET.Tests.API.Utils.MockConfig;
using GoogleMapsAPI.NET.Tests.API.Utils.MockConfig.Images;
using Rhino.Mocks;
namespace GoogleMapsAPI.NET.Tests.API.Utils
{
/// <summary>
/// Client API mock utils
/// </summary>
public class ClientAPIMockUtils
{
#region Static methods
/// <summary>
/// Mock result web response
/// </summary>
/// <param name="mockResultConfig">Mock result config</param>
/// <returns>Mocked instance</returns>
public static HttpWebResponse MockResultWebResponse(MockResultWebResponseConfig mockResultConfig)
{
// Generate mock
var webResponse = MockRepository.GenerateMock<HttpWebResponse>();
// Define stubs
webResponse.Stub(x => x.StatusCode).Return(mockResultConfig.StatusCode);
webResponse.Stub(x => x.ContentType).Return(mockResultConfig.ContentType);
webResponse.Stub(x => x.GetResponseStream()).WhenCalled(invocation =>
{
invocation.ReturnValue = new MemoryStream(mockResultConfig.GetContentBytes());
}).Return(null).Repeat.Any();
// Return result
return webResponse;
}
/// <summary>
/// Mock image web response
/// </summary>
/// <param name="mockImageConfig">Mock image config</param>
/// <returns>Mocked instance</returns>
public static HttpWebResponse MockImageWebResponse(MockImageWebResponseConfig mockImageConfig)
{
// Generate mock
var webResponse = MockRepository.GenerateMock<HttpWebResponse>();
// Define stubs
webResponse.Stub(x => x.StatusCode).Return(mockImageConfig.StatusCode);
webResponse.Stub(x => x.ContentType).Return(mockImageConfig.ContentType);
webResponse.Stub(x => x.GetResponseStream()).WhenCalled(invocation =>
{
invocation.ReturnValue = new MemoryStream(mockImageConfig.GetImageBytes());
}).Return(null).Repeat.Any();
// Return result
return webResponse;
}
#endregion
}
}