Loading WindowsDevicePortalWrapper/UnitTestProject/MockHttpResponder.cs +2 −0 Original line number Diff line number Diff line Loading @@ -40,6 +40,8 @@ namespace Microsoft.Tools.WindowsDevicePortal.Tests /// <param name="response">The response to return.</param> public void AddMockResponse(string endpoint, HttpResponseMessage response) { Utilities.ModifyEndpointForFilename(ref endpoint); this.mockResponses.Add(endpoint.ToLowerInvariant(), response); } Loading WindowsDevicePortalWrapper/UnitTestProject/Xbox/UserManagementTests.cs +44 −1 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ // </copyright> //---------------------------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Net; using System.Net.Http; Loading Loading @@ -62,7 +63,7 @@ namespace Microsoft.Tools.WindowsDevicePortal.Tests public void UpdateXboxLiveUsersTest() { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.NoContent); TestHelpers.MockHttpResponder.AddMockResponse(DevicePortal.XboxLiveUserApi); TestHelpers.MockHttpResponder.AddMockResponse(DevicePortal.XboxLiveUserApi, response); UserList users = new UserList(); UserInfo user = new UserInfo(); Loading @@ -76,5 +77,47 @@ namespace Microsoft.Tools.WindowsDevicePortal.Tests Assert.AreEqual(TaskStatus.RanToCompletion, updateUsersTask.Status); } /// <summary> /// Tests the failure case of trying to add a sponsored user /// when the maximum number are already on the console. /// </summary> [TestMethod] public void AddSponsoredUserTest_Failure() { HttpResponseMessage response = new HttpResponseMessage((HttpStatusCode)422); HttpContent content = new StringContent( "{\"ErrorCode\":-2136866553,\"ErrorMessage\":\"The maximum number of sponsored users are already signed in.\"}", System.Text.Encoding.UTF8, "application/json"); response.Content = content; TestHelpers.MockHttpResponder.AddMockResponse(DevicePortal.XboxLiveUserApi, response); UserList users = new UserList(); UserInfo user = new UserInfo(); user.SponsoredUser = true; users.Add(user); try { Task updateUsersTask = TestHelpers.Portal.UpdateXboxLiveUsers(users); updateUsersTask.Wait(); Assert.Fail("Expected an exception due to mock responder returning failure HRESULT."); } catch (Exception e) { Assert.IsTrue(e is AggregateException); Assert.IsNotNull(e.InnerException); Assert.IsTrue(e.InnerException is DevicePortalException); DevicePortalException exception = e.InnerException as DevicePortalException; Assert.AreEqual(-2136866553, exception.HResult); Assert.AreEqual("The maximum number of sponsored users are already signed in.", exception.Reason); } } } } WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/Exceptions/DevicePortalException.cs +1 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ namespace Microsoft.Tools.WindowsDevicePortal Exception innerException = null) : this( responseMessage.StatusCode, responseMessage.ReasonPhrase, responseMessage.RequestMessage.RequestUri, responseMessage.RequestMessage != null? responseMessage.RequestMessage.RequestUri : null, message, innerException) { Loading Loading
WindowsDevicePortalWrapper/UnitTestProject/MockHttpResponder.cs +2 −0 Original line number Diff line number Diff line Loading @@ -40,6 +40,8 @@ namespace Microsoft.Tools.WindowsDevicePortal.Tests /// <param name="response">The response to return.</param> public void AddMockResponse(string endpoint, HttpResponseMessage response) { Utilities.ModifyEndpointForFilename(ref endpoint); this.mockResponses.Add(endpoint.ToLowerInvariant(), response); } Loading
WindowsDevicePortalWrapper/UnitTestProject/Xbox/UserManagementTests.cs +44 −1 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ // </copyright> //---------------------------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Net; using System.Net.Http; Loading Loading @@ -62,7 +63,7 @@ namespace Microsoft.Tools.WindowsDevicePortal.Tests public void UpdateXboxLiveUsersTest() { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.NoContent); TestHelpers.MockHttpResponder.AddMockResponse(DevicePortal.XboxLiveUserApi); TestHelpers.MockHttpResponder.AddMockResponse(DevicePortal.XboxLiveUserApi, response); UserList users = new UserList(); UserInfo user = new UserInfo(); Loading @@ -76,5 +77,47 @@ namespace Microsoft.Tools.WindowsDevicePortal.Tests Assert.AreEqual(TaskStatus.RanToCompletion, updateUsersTask.Status); } /// <summary> /// Tests the failure case of trying to add a sponsored user /// when the maximum number are already on the console. /// </summary> [TestMethod] public void AddSponsoredUserTest_Failure() { HttpResponseMessage response = new HttpResponseMessage((HttpStatusCode)422); HttpContent content = new StringContent( "{\"ErrorCode\":-2136866553,\"ErrorMessage\":\"The maximum number of sponsored users are already signed in.\"}", System.Text.Encoding.UTF8, "application/json"); response.Content = content; TestHelpers.MockHttpResponder.AddMockResponse(DevicePortal.XboxLiveUserApi, response); UserList users = new UserList(); UserInfo user = new UserInfo(); user.SponsoredUser = true; users.Add(user); try { Task updateUsersTask = TestHelpers.Portal.UpdateXboxLiveUsers(users); updateUsersTask.Wait(); Assert.Fail("Expected an exception due to mock responder returning failure HRESULT."); } catch (Exception e) { Assert.IsTrue(e is AggregateException); Assert.IsNotNull(e.InnerException); Assert.IsTrue(e.InnerException is DevicePortalException); DevicePortalException exception = e.InnerException as DevicePortalException; Assert.AreEqual(-2136866553, exception.HResult); Assert.AreEqual("The maximum number of sponsored users are already signed in.", exception.Reason); } } } }
WindowsDevicePortalWrapper/WindowsDevicePortalWrapper.Shared/Exceptions/DevicePortalException.cs +1 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,7 @@ namespace Microsoft.Tools.WindowsDevicePortal Exception innerException = null) : this( responseMessage.StatusCode, responseMessage.ReasonPhrase, responseMessage.RequestMessage.RequestUri, responseMessage.RequestMessage != null? responseMessage.RequestMessage.RequestUri : null, message, innerException) { Loading