public async Task GetValueAsync_JObject_Throws_WhenErrorResponse()
        {
            // Arrange
            var parameter = MobileAppTestHelper.GetInputParameter <JObject>();
            Mock <IMobileServiceTable>  mockTable;
            Mock <IMobileServiceClient> mockClient;
            IValueBinder binder = CreateJObjectBinder(parameter, out mockClient, out mockTable);

            mockTable
            .Setup(m => m.LookupAsync("abc123"))
            .Throws(new MobileServiceInvalidOperationException(string.Empty, null, new HttpResponseMessage(HttpStatusCode.ServiceUnavailable)));

            // Act
            var ex = await Assert.ThrowsAsync <MobileServiceInvalidOperationException>(() => binder.GetValueAsync());

            // Assert
            Assert.Equal(HttpStatusCode.ServiceUnavailable, ex.Response.StatusCode);
        }
        public async Task GetValueAsync_Poco_DoesNotThrow_WhenResponseIsNotFound()
        {
            // Arrange
            var parameter = MobileAppTestHelper.GetInputParameter <TodoItem>();
            Mock <IMobileServiceTable <TodoItem> > mockTable;
            Mock <IMobileServiceClient>            mockClient;
            IValueBinder binder = CreatePocoBinder(parameter, out mockClient, out mockTable);

            mockTable
            .Setup(m => m.LookupAsync("abc123"))
            .ThrowsAsync(new MobileServiceInvalidOperationException(string.Empty, null, new HttpResponseMessage(HttpStatusCode.NotFound)));

            // Act
            var value = await binder.GetValueAsync();

            // Assert
            Assert.Null(value);
            mockTable.VerifyAll();
            mockClient.VerifyAll();
        }
        public async Task GetValueAsync_Poco_QueriesItem()
        {
            // Arrange
            var parameter = MobileAppTestHelper.GetInputParameter <TodoItem>();
            Mock <IMobileServiceTable <TodoItem> > mockTable;
            Mock <IMobileServiceClient>            mockClient;
            IValueBinder binder   = CreatePocoBinder(parameter, out mockClient, out mockTable);
            var          response = new TodoItem();

            mockTable
            .Setup(m => m.LookupAsync("abc123"))
            .Returns(Task.FromResult(response));

            // Act
            var value = await binder.GetValueAsync();

            // Assert
            Assert.Same(response, value);
            mockTable.VerifyAll();
            mockClient.VerifyAll();
        }
Example #4
0
        public void GetValue_JObject_QueriesItem()
        {
            // Arrange
            var parameter = MobileAppTestHelper.GetInputParameter <JObject>();
            Mock <IMobileServiceTable>  mockTable;
            Mock <IMobileServiceClient> mockClient;
            IValueBinder binder   = CreateJObjectBinder(parameter, out mockClient, out mockTable);
            JToken       response = new JObject() as JToken;

            mockTable
            .Setup(m => m.LookupAsync("abc123"))
            .Returns(Task.FromResult(response));

            // Act
            var value = binder.GetValue();

            // Assert
            Assert.Same(response, value);
            mockTable.VerifyAll();
            mockClient.VerifyAll();
        }