public void TestBinary() { var contentBytes = GenBytes(); var contentType = GenString(); Check(ContentPattern.Binary(contentBytes, contentType), contentBytes, contentType); CheckWithoutContentType(ContentPattern.Binary(contentBytes), contentBytes, contentType); }
public void TestContentPattern() { var contentPattern = ContentPattern.Any(); httpRequestMockBuilder.Content(contentPattern); var httpRequestMock = httpRequestMockBuilder.Build(); httpRequestMock.Content.ShouldBeEquivalentTo(contentPattern); }
public void TestBase64() { var contentBase64 = GenBase64String(); var contentType = GenString(); var rightContentBytes = Encoding.ASCII.GetBytes(contentBase64); Check(ContentPattern.Base64(contentBase64, contentType), rightContentBytes, contentType); CheckWithoutContentType(ContentPattern.Base64(contentBase64), rightContentBytes, contentType); }
internal HttpRequestMockBuilder() { httpRequestMock = new HttpRequestMock { Method = MethodPattern.Any(), Path = PathPattern.Any(), Query = QueryPattern.Any(), Content = ContentPattern.Any(), Headers = HeadersPattern.Any() }; httpResponseMockBuilder = new HttpResponseMockBuilder(200); }
private static HttpRequestMock CreateMock(string method) { return(new HttpRequestMock { Method = MethodPattern.Standart(method), Path = PathPattern.Smart("/"), Query = QueryPattern.Any(), Content = ContentPattern.Any(), Headers = HeadersPattern.Any(), Response = new HttpResponseMock { RepeatCount = 1 } }); }
public void TestIsMatch(string method, string expectedMethod, bool expected) { const string pathPattern = "/"; var httpRequestMock = new HttpRequestMock { Method = MethodPattern.Standart(method), Path = PathPattern.Smart(pathPattern), Query = QueryPattern.Any(), Headers = HeadersPattern.Any(), Content = ContentPattern.Any() }; var httpRequestPattern = new HttpRequestPattern(httpRequestMock); var httpRequestInfo = new HttpRequest { Method = expectedMethod, Path = pathPattern }; httpRequestPattern.IsMatch(httpRequestInfo).ShouldBeEquivalentTo(expected); }
/// <summary> /// Wendet die Fiterbedingung an. /// </summary> /// <param name="entries">Eine Liste von Einträgen.</param> /// <returns>Die gefilterte Liste.</returns> public IEnumerable <ProgramGuideEntry> Filter(IEnumerable <ProgramGuideEntry> entries) { // Only use sources available to the target profile var entrySet = entries .Select(entry => new { e = entry, s = VCRProfiles.FindSource(ProfileName, entry.Source) }) .Where(entry => entry.s != null) .Select(entry => new { e = entry.e, s = (Station)entry.s.Source }); // Name of the station - best filter first if (Source != null) { // One source - no more filters entrySet = entrySet.Where(entry => Source.Equals(entry.e.Source)); } else { // Apply source type filter if (SourceType == GuideSourceFilter.Television) { entrySet = entrySet.Where(entry => entry.s.SourceType == SourceTypes.TV); } else if (SourceType == GuideSourceFilter.Radio) { entrySet = entrySet.Where(entry => entry.s.SourceType == SourceTypes.Radio); } // Apply encryption filter if (SourceEncryption == GuideEncryptionFilter.Free) { entrySet = entrySet.Where(entry => !entry.s.IsEncrypted); } else if (SourceEncryption == GuideEncryptionFilter.Encrypted) { entrySet = entrySet.Where(entry => entry.s.IsEncrypted); } } // Start time if (Start.HasValue) { // Later entrySet = entrySet.Where(entry => entry.e.StartTime >= Start.Value); } else { // Current var now = DateTime.UtcNow; // Still active entrySet = entrySet.Where(entry => entry.e.EndTime > now); } // Matcher on content Func <ProgramGuideEntry, bool> matchTitle = null; Func <ProgramGuideEntry, bool> matchContent = null; // Title if (!string.IsNullOrEmpty(TitlePattern)) { var title = TitlePattern.Substring(1); switch (TitlePattern[0]) { case '=': matchTitle = entry => (entry.Name ?? string.Empty).Equals(title, StringComparison.InvariantCultureIgnoreCase); break; case '*': matchTitle = entry => (entry.Name ?? string.Empty).IndexOf(title, StringComparison.InvariantCultureIgnoreCase) >= 0; break; } } // Both descriptions if (!string.IsNullOrEmpty(ContentPattern)) { var content = ContentPattern.Substring(1); switch (ContentPattern[0]) { case '=': matchContent = entry => (entry.Description ?? string.Empty).Equals(content, StringComparison.InvariantCultureIgnoreCase) || (entry.ShortDescription ?? string.Empty).Equals(content, StringComparison.InvariantCultureIgnoreCase); break; case '*': matchContent = entry => ((entry.Description ?? string.Empty).IndexOf(content, StringComparison.InvariantCultureIgnoreCase) >= 0) || ((entry.ShortDescription ?? string.Empty).IndexOf(content, StringComparison.InvariantCultureIgnoreCase) >= 0); break; } } // Apply content filter if (matchTitle != null) { if (matchContent != null) { entrySet = entrySet.Where(entry => matchTitle(entry.e) || matchContent(entry.e)); } else { entrySet = entrySet.Where(entry => matchTitle(entry.e)); } } else if (matchContent != null) { entrySet = entrySet.Where(entry => matchContent(entry.e)); } // Back mapping entries = entrySet.Select(entry => entry.e); // Caller will get it all if (PageSize < 1) { return(entries); } // Copy local var matches = entries.ToList(); // Sort in list to improve overall performance matches.Sort(Comparer); // Adjust extract - report one more if possible to indicate that there is more available return(matches.Skip(PageIndex * PageSize).Take(PageSize + 1)); }
public static IHttpRequestMock Content(this IHttpRequestMock httpRequestMock, byte[] contentBytes, string contentType = null) { return(httpRequestMock.Content(ContentPattern.Binary(contentBytes, contentType))); }
public void TestAny() { IHttpRequestContentPattern contentPattern = ContentPattern.Any(); contentPattern.IsMatch(GenBytes(), GenString()).ShouldBeEquivalentTo(true); }