Hi Guys,
I am testing out the cloud service but running into problems trying to write a few unit / integration tests. Error is: "Object reference not set to an instance of an object". Below is my code, any ideas what needs to be set in HttpContextBase for the request to work? And why doesn't the cloud API have a method where you can only send in the user agent string like the stand-alone API does? Would make it a lot easier to write tests...
[TestMethod]
public void TestGalaxyTab()
{
string ua = "Mozilla/5.0 (Linux; U; Android 4.1.2; nb-no; GT-N8000 Build/JZO54K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30";
var context = FakeHttpContext(ua);
var config = new DefaultCloudClientConfig
{
ApiKey = "xxxxxx:.........."
};
var manager = new CloudClientManager(config);
var info = manager.GetDeviceInfo(context);
...
}
public static HttpContextBase FakeHttpContext(string userAgent)
{
var context = new Mock<HttpContextBase>();
var request = new Mock<HttpRequestBase>();
var response = new Mock<HttpResponseBase>();
var session = new Mock<HttpSessionStateBase>();
var server = new Mock<HttpServerUtilityBase>();
var cookies = new HttpCookieCollection();
var items = new ListDictionary();
request.Setup(r => r.Cookies).Returns(cookies);
response.Setup(r => r.Cookies).Returns(cookies);
context.Setup(ctx => ctx.Items).Returns(items);
context.SetupGet(ctx => ctx.Request).Returns(request.Object);
context.SetupGet(ctx => ctx.Response).Returns(response.Object);
context.SetupGet(ctx => ctx.Session).Returns(session.Object);
context.SetupGet(ctx => ctx.Server).Returns(server.Object);
request.Setup(r => r.UserAgent).Returns(userAgent);
return context.Object;
}
Thanks,
Frank
Unable to test with mock HttpContextBase in .Net
-
- Posts: 294
- Joined: Mon Jun 20, 2011 5:04 pm
Re: Unable to test with mock HttpContextBase in .Net
Hi there, as luck has it, we are planning an improvement of the .NET Cloud Clients in this area. Do you have an email we can reach you at? is the one with which you registered to the forum a valid email address?
you can also contact as at wurfldb#scientiamobile.com
Thanks
you can also contact as at wurfldb#scientiamobile.com
Thanks
-
- Posts: 294
- Joined: Mon Jun 20, 2011 5:04 pm
Re: Unable to test with mock HttpContextBase in .Net
Hi, we emailed you a newer pre-release of the .NET Cloud Client. Can you please confirm that you have received it?
Thanks
Thanks
Re: Unable to test with mock HttpContextBase in .Net
I'm very happy to report back that a new API which I believe is soon to be released includes an option to query by user agent string instead of the full HttpContext. This also allows the cloud service to be easily tested without having to mock up a lot of things
Example code with new API:
var userAgent = "Mozilla/5.0 (Linux; U; Android 4.1.2;...";
var info = manager.GetDeviceInfo(userAgent, new string[] { "is_tablet", "is_wireless_device" });
Example code with new API:
var userAgent = "Mozilla/5.0 (Linux; U; Android 4.1.2;...";
var info = manager.GetDeviceInfo(userAgent, new string[] { "is_tablet", "is_wireless_device" });
-
- Posts: 294
- Joined: Mon Jun 20, 2011 5:04 pm
Re: Unable to test with mock HttpContextBase in .Net
Excellent. We are planning an improvement to the Cloud Clients that will include this (for .NET) and the ability to set a proxy for the .NET, Java and PHP
Thanks
Thanks
Re: Unable to test with mock HttpContextBase in .Net
Is this version shipped? Means can I use?
var userAgent = "Mozilla/5.0 (Linux; U; Android 4.1.2;...";
var info = manager.GetDeviceInfo(userAgent, new string[] { "is_tablet", "is_wireless_device" });
var userAgent = "Mozilla/5.0 (Linux; U; Android 4.1.2;...";
var info = manager.GetDeviceInfo(userAgent, new string[] { "is_tablet", "is_wireless_device" });
Re: Unable to test with mock HttpContextBase in .Net
Are you able to post the User-Agent that you are having trouble detecting? Are you having any other issues using those capabilities at the moment?
Thank you,
Elliot
Thank you,
Elliot
Who is online
Users browsing this forum: No registered users and 63 guests