Exemplo n.º 1
0
        public async Task CreateOrUpdateRegistration()
        {
            var expectedUri  = string.Format("{0}{1}/{2}", DefaultServiceUri, RegistrationsPath, DefaultRegistrationId);
            var registration = this.pushTestUtility.GetNewNativeRegistration(DefaultChannelUri, new[] { "foo", "bar" });

            registration.RegistrationId = DefaultRegistrationId;
            string jsonRegistration = JsonConvert.SerializeObject(registration);

            // The entire test is performed within the TestHttpHandler.
            // We verify that the request content is correct and that the method is correct.
            var hijack = CreateTestHttpHandler(expectedUri, HttpMethod.Put, null, HttpStatusCode.NoContent, expectedRequestContent: jsonRegistration);

            MobileServiceClient mobileClient = new MobileServiceClient(DefaultServiceUri, null, hijack);
            var pushHttpClient = new PushHttpClient(mobileClient);

            await pushHttpClient.CreateOrUpdateRegistrationAsync(registration);
        }
Exemplo n.º 2
0
        public async Task CreateOrUpdateRegistration_Error()
        {
            var expectedUri  = string.Format("{0}{1}/{2}", DefaultServiceUri, RegistrationsPath, DefaultRegistrationId);
            var registration = this.pushTestUtility.GetNewNativeRegistration(DefaultChannelUri, new[] { "foo", "bar" });

            registration.RegistrationId = DefaultRegistrationId;

            string jsonRegistration = JsonConvert.SerializeObject(registration);
            var    hijack           = CreateTestHttpHandler(expectedUri, HttpMethod.Put, "\"Server threw 500\"", HttpStatusCode.InternalServerError, expectedRequestContent: jsonRegistration);

            MobileServiceClient mobileClient = new MobileServiceClient(DefaultServiceUri, null, hijack);
            var pushHttpClient = new PushHttpClient(mobileClient);

            var exception = await AssertEx.Throws <MobileServiceInvalidOperationException>(() => pushHttpClient.CreateOrUpdateRegistrationAsync(registration));

            Assert.AreEqual(exception.Message, "Server threw 500");
        }
        public async Task CreateOrUpdateRegistration_Error()
        {
            var expectedUri = string.Format("{0}{1}/{2}", DefaultServiceUri, RegistrationsPath, DefaultRegistrationId);
            var registration = this.pushTestUtility.GetNewNativeRegistration(DefaultChannelUri, new[] { "foo", "bar" });
            registration.RegistrationId = DefaultRegistrationId;

            string jsonRegistration = JsonConvert.SerializeObject(registration);
            var hijack = CreateTestHttpHandler(expectedUri, HttpMethod.Put, "\"Server threw 500\"", HttpStatusCode.InternalServerError, expectedRequestContent: jsonRegistration);

            MobileServiceClient mobileClient = new MobileServiceClient(DefaultServiceUri, null, hijack);
            var pushHttpClient = new PushHttpClient(mobileClient);

            var exception = await AssertEx.Throws<MobileServiceInvalidOperationException>(() => pushHttpClient.CreateOrUpdateRegistrationAsync(registration));
            Assert.AreEqual(exception.Message, "Server threw 500");
        }
        public async Task CreateOrUpdateRegistration()
        {
            var expectedUri = string.Format("{0}{1}/{2}", DefaultServiceUri, RegistrationsPath, DefaultRegistrationId);
            var registration = this.pushTestUtility.GetNewNativeRegistration(DefaultChannelUri, new[] { "foo", "bar" });
            registration.RegistrationId = DefaultRegistrationId;
            string jsonRegistration = JsonConvert.SerializeObject(registration);

            // The entire test is performed within the TestHttpHandler.
            // We verify that the request content is correct and that the method is correct.
            var hijack = CreateTestHttpHandler(expectedUri, HttpMethod.Put, null, HttpStatusCode.NoContent, expectedRequestContent: jsonRegistration);

            MobileServiceClient mobileClient = new MobileServiceClient(DefaultServiceUri, null, hijack);
            var pushHttpClient = new PushHttpClient(mobileClient);

            await pushHttpClient.CreateOrUpdateRegistrationAsync(registration);
        }