public void TestPreferenceAppliedOnHttpWebRequest() { SimpleUnitTestHttpExtension httpExtension = new SimpleUnitTestHttpExtension(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("{}") }); httpExtension.InlineAssertation = (httpRequestMessage) => { Assert.IsTrue(httpRequestMessage.Headers.Contains("Prefer")); IEnumerable <string> value; Assert.IsTrue(httpRequestMessage.Headers.TryGetValues("Prefer", out value)); foreach (string s in value) { Assert.AreEqual("IdType=\"ImmutableId\"", s); } }; ExchangeService exchangeService = new ExchangeService( "bearer", "*****@*****.**"); exchangeService.HttpExtension = httpExtension; exchangeService.Preferences.Add(new Preference("IdType=\"ImmutableId\"")); exchangeService.GetItem(new MessageId("abc", exchangeService.MailboxId)); }
/// <summary> /// Run mock test case. /// </summary> /// <param name="testCase">Test case to run.</param> /// <param name="mailboxId">Mailbox Id.</param> /// <param name="mockHttpResponseMessage">Mock response message.</param> /// <param name="inlineAssertation">Inline assertation.</param> /// <param name="restEnvironment">Rest environment - Default BETA.</param> internal static void RunTestCase( Action <ExchangeService> testCase, string mailboxId, HttpResponseMessage mockHttpResponseMessage, Action <HttpRequestMessage> inlineAssertation, Environment restEnvironment = Environment.Beta) { ExchangeService exchangeService = restEnvironment == Environment.Beta ? MockTestRunner.GetExchangeServiceBeta(mailboxId) : MockTestRunner.GetExchangeServiceProd(mailboxId); SimpleUnitTestHttpExtension simpleUnitTestHttpExtension = new SimpleUnitTestHttpExtension(mockHttpResponseMessage); simpleUnitTestHttpExtension.InlineAssertation = inlineAssertation; exchangeService.HttpExtension = simpleUnitTestHttpExtension; testCase(exchangeService); }