public async Task ListRegistrations_Native() { // Ensure Uri and method are correct for request and specify body to return for registrations list with only 1 native registration var expectedUri = this.GetExpectedListUri(); var hijack = CreateTestHttpHandler(expectedUri, HttpMethod.Get, this.pushTestUtility.GetListNativeRegistrationResponse()); MobileServiceClient mobileClient = new MobileServiceClient(DefaultServiceUri, null, hijack); var pushHttpClient = new PushHttpClient(mobileClient); var registrations = await pushHttpClient.ListRegistrationsAsync(DefaultChannelUri); Assert.AreEqual(registrations.Count(), 1, "Expected 1 registration."); var firstRegistration = registrations.First(); var nativeReg = this.pushUtility.GetNewNativeRegistration(); Assert.AreEqual(nativeReg.GetType(), firstRegistration.GetType(), "The type of the registration returned from ListRegistrationsAsync is not of the correct type."); Assert.AreEqual(firstRegistration.RegistrationId, DefaultRegistrationId, "The registrationId returned from ListRegistrationsAsync is not correct."); var tags = firstRegistration.Tags.ToList(); Assert.AreEqual(tags[0], "fooWns", "tag[0] on the registration is not correct."); Assert.AreEqual(tags[1], "barWns", "tag[1] on the registration is not correct."); Assert.AreEqual(tags[2], "4de2605e-fd09-4875-a897-c8c4c0a51682", "tag[2] on the registration is not correct."); Assert.AreEqual(firstRegistration.PushHandle, DefaultChannelUri, "The DeviceId on the registration is not correct."); }
public async Task ListRegistrations_Template() { var expectedUri = this.GetExpectedListUri(); var hijack = CreateTestHttpHandler(expectedUri, HttpMethod.Get, this.pushTestUtility.GetListTemplateRegistrationResponse()); MobileServiceClient mobileClient = new MobileServiceClient(DefaultServiceUri, null, hijack); var pushHttpClient = new PushHttpClient(mobileClient); var registrations = await pushHttpClient.ListRegistrationsAsync(DefaultChannelUri); Assert.AreEqual(registrations.Count(), 1, "Expected 1 registration."); var firstRegistration = registrations.First(); var templateReg = this.pushUtility.GetNewTemplateRegistration(); Assert.AreEqual(templateReg.GetType(), firstRegistration.GetType(), "The type of the registration returned from ListRegistrationsAsync is not of the correct type."); Assert.AreEqual(firstRegistration.RegistrationId, DefaultRegistrationId, "The registrationId returned from ListRegistrationsAsync is not correct."); var tags = firstRegistration.Tags.ToList(); Assert.AreEqual(tags[0], "fooWns", "tag[0] on the registration is not correct."); Assert.AreEqual(tags[1], "barWns", "tag[1] on the registration is not correct."); Assert.AreEqual(tags[2], "4de2605e-fd09-4875-a897-c8c4c0a51682", "tag[2] on the registration is not correct."); Assert.AreEqual(firstRegistration.PushHandle, DefaultChannelUri, "The DeviceId on the registration is not correct."); }
public async Task ListRegistrations_Empty() { // Ensure Uri and method are correct for request and specify body to return for empty registrations list var expectedUri = this.GetExpectedListUri(); var hijack = CreateTestHttpHandler(expectedUri, HttpMethod.Get, "[]"); MobileServiceClient mobileClient = new MobileServiceClient(DefaultServiceUri, null, hijack); var pushHttpClient = new PushHttpClient(mobileClient); var registrations = await pushHttpClient.ListRegistrationsAsync(DefaultChannelUri); Assert.AreEqual(registrations.Count(), 0, "Expected empty list to return an empty list of registrations."); }
public async Task ListRegistrations_Error_WithError() { var expectedUri = this.GetExpectedListUri(); var hijack = CreateTestHttpHandler(expectedUri, HttpMethod.Get, "{\"error\":\"Server threw 500\"}", HttpStatusCode.InternalServerError); MobileServiceClient mobileClient = new MobileServiceClient(DefaultServiceUri, null, hijack); var pushHttpClient = new PushHttpClient(mobileClient); var exception = await AssertEx.Throws <MobileServiceInvalidOperationException> (() => pushHttpClient.ListRegistrationsAsync(DefaultChannelUri)); Assert.AreEqual(exception.Message, "Server threw 500"); }
public async Task ListRegistrations_Error_WithError() { var expectedUri = this.GetExpectedListUri(); var hijack = CreateTestHttpHandler(expectedUri, HttpMethod.Get, "{\"error\":\"Server threw 500\"}", HttpStatusCode.InternalServerError); MobileServiceClient mobileClient = new MobileServiceClient(DefaultServiceUri, null, hijack); var pushHttpClient = new PushHttpClient(mobileClient); var exception = await AssertEx.Throws<MobileServiceInvalidOperationException> (() => pushHttpClient.ListRegistrationsAsync(DefaultChannelUri)); Assert.AreEqual(exception.Message, "Server threw 500"); }
public async Task ListRegistrations_NativeAndTemplate() { var expectedUri = this.GetExpectedListUri(); var hijack = CreateTestHttpHandler(expectedUri, HttpMethod.Get, this.pushTestUtility.GetListMixedRegistrationResponse()); MobileServiceClient mobileClient = new MobileServiceClient(DefaultServiceUri, null, hijack); var pushHttpClient = new PushHttpClient(mobileClient); var registrations = await pushHttpClient.ListRegistrationsAsync(DefaultChannelUri); var registrationsArray = registrations.ToArray(); Assert.AreEqual(registrationsArray.Length, 2, "Expected 2 registrations."); var firstRegistration = registrationsArray[0]; var nativeReg = this.pushUtility.GetNewNativeRegistration(); Assert.AreEqual(nativeReg.GetType(), firstRegistration.GetType(), "The type of the native registration returned from ListRegistrationsAsync is not of the correct type."); Assert.AreEqual(firstRegistration.RegistrationId, DefaultRegistrationId, "The native registrationId returned from ListRegistrationsAsync is not correct."); var nativeTags = firstRegistration.Tags.ToList(); Assert.AreEqual(nativeTags[0], "fooWns", "nativeTags[0] on the registration is not correct."); Assert.AreEqual(nativeTags[1], "barWns", "nativeTags[1] on the registration is not correct."); Assert.AreEqual(nativeTags[2], "4de2605e-fd09-4875-a897-c8c4c0a51682", "nativeTags[2] on the registration is not correct."); Assert.AreEqual(firstRegistration.PushHandle, DefaultChannelUri, "The DeviceId on the native registration is not correct."); var secondRegistration = registrationsArray[1]; var templateReg = this.pushUtility.GetNewTemplateRegistration(); Assert.AreEqual(templateReg.GetType(), secondRegistration.GetType(), "The type of the template registration returned from ListRegistrationsAsync is not of the correct type."); Assert.AreEqual(secondRegistration.RegistrationId, DefaultRegistrationId, "The template registrationId returned from ListRegistrationsAsync is not correct."); var templateTags = secondRegistration.Tags.ToList(); Assert.AreEqual(templateTags[0], "fooWns", "templateTags[0] on the registration is not correct."); Assert.AreEqual(templateTags[1], "barWns", "templateTags[1] on the registration is not correct."); Assert.AreEqual(templateTags[2], "4de2605e-fd09-4875-a897-c8c4c0a51682", "templateTags[2] on the registration is not correct."); Assert.AreEqual(secondRegistration.PushHandle, DefaultChannelUri, "The DeviceId on the template registration is not correct."); }