public async Task InvokeTest() { var mr = new MockRepository(MockBehavior.Strict); var next = mr.Create<OwinMiddleware>(MockBehavior.Strict, (OwinMiddleware)null); var ctx = mr.Create<IOwinContext>(); var cidStore = mr.Create<ICorrelationIdStore>(); var response = mr.Create<IOwinResponse>(); var hDict = new HeaderDictionary(new Dictionary<string, string[]>()); var correlationId = new CorrelationId(); next.Setup(x => x.Invoke(ctx.Object)).Returns(Task.CompletedTask).Verifiable(); ctx.SetupGet(x => x.Response).Returns(response.Object).Verifiable(); response.SetupGet(x => x.Headers).Returns(hDict).Verifiable(); cidStore.Setup(x => x.Read()).Returns(correlationId).Verifiable(); Assert.AreEqual(0, hDict.Count); var midleware = new SetCorrelationIdHeaderMiddleware(next.Object, cidStore.Object); await midleware.Invoke(ctx.Object); Assert.AreEqual(1, hDict.Count); var actual = hDict["X-CORRELATIONID"]; Assert.AreEqual(correlationId.ToString(), actual); mr.VerifyAll(); }
public void Constructor_HaveBrowserLanguageAndSettingIsEnabledCase2_LanguageSetFromHeader() { // Assign _settings.SetupGet(x => x.AcceptBrowserLanguage).Returns(true); var header = new HeaderDictionary(new Dictionary<string, string[]>()); header.Append("Accept-Language", "ru-RU;q=0.5"); _context.SetupGet(x => x.Request.Headers).Returns(header); // Act _languageManager = new LanguageManager(_settings.Object, _context.Object); // Assert Assert.AreEqual("ru", _languageManager.Language); }
public void Constructor_HaveBrowserLanguageAndCookieLanguage_LanguageSetFromCookie() { // Assign var cookies = new Dictionary<string, string> { { LanguageManager.CookieLanguageFieldName, "fr" } }; _context.SetupGet(x => x.Request.Cookies).Returns(new RequestCookieCollection(cookies)); _settings.SetupGet(x => x.AcceptBrowserLanguage).Returns(true); var header = new HeaderDictionary(new Dictionary<string, string[]>()); header.Append("Accept-Language", "ru-RU"); _context.SetupGet(x => x.Request.Headers).Returns(header); // Act _languageManager = new LanguageManager(_settings.Object, _context.Object); // Assert Assert.AreEqual("fr", _languageManager.Language); }
protected override void Push(IOwinRequest request, PushFunc pushPromise, string pushReference) { request.Set(CommonOwinKeys.AdditionalInfo, pushReference); // Copy the headers var headers = new HeaderDictionary( new Dictionary<string, string[]>(request.Headers, StringComparer.OrdinalIgnoreCase)); // Populate special HTTP2 headers headers[CommonHeaders.Method] = request.Method; // TODO: Not all methods are allowed for push. Don't push, or change to GET? headers[CommonHeaders.Scheme] = request.Scheme; headers.Remove("Host"); headers[CommonHeaders.Authority] = request.Headers["Host"]; headers[CommonHeaders.Path] = BingRequestProcessor.GetTileQuadFromSoapUrl(pushReference); headers.Remove(CommonHeaders.ContentLength); // Push promises cannot emulate requests with bodies. // TODO: What about cache headers? If-Match, If-None-Match, If-Modified-Since, If-Unmodified-Since. // If-Match & If-None-Match are multi-value so the client could send e-tags for the primary resource and referenced resources. // If-Modified-Since and If-Unmodified-Since are single value, so it may not make sense to apply them for secondary resources. pushPromise(headers); }
public void Constructor_NoBrowserLanguage_DefaultLanguageSet() { // Assign _settings.SetupGet(x => x.AcceptBrowserLanguage).Returns(true); var header = new HeaderDictionary(new Dictionary<string, string[]>()); _context.SetupGet(x => x.Request.Headers).Returns(header); // Act _languageManager = new LanguageManager(_settings.Object, _context.Object); // Assert Assert.AreEqual("en", _languageManager.Language); }