public void NegativeDeviceCodeTest() { MockHttpMessageHandler mockMessageHandler = new MockHttpMessageHandler(TestConstants.DefaultAuthorityHomeTenant) { Method = HttpMethod.Get, Url = TestConstants.DefaultAuthorityHomeTenant + "oauth2/devicecode", ResponseMessage = MockHelpers.CreateDeviceCodeErrorResponse() }; HttpMessageHandlerFactory.AddMockHandler(mockMessageHandler); TokenCache cache = new TokenCache(); AuthenticationContext ctx = new AuthenticationContext(TestConstants.DefaultAuthorityHomeTenant, cache); DeviceCodeResult dcr; AdalServiceException ex = AssertException.TaskThrows <AdalServiceException>(async() => dcr = await ctx.AcquireDeviceCodeAsync("some-resource", "some-client").ConfigureAwait(false)); Assert.IsTrue(ex.Message.Contains("some error message")); }