public void TestMultipleCases()
        {
            var filterRequests = new List <FilterRequest>
            {
                new FilterRequest("p1", FilterType.Equals, "p1"),
                new FilterRequest("p3", FilterType.Contains, "p3"),
                new FilterRequest("p4", FilterType.LessThan, "p4"),
                new FilterRequest("p5", FilterType.GreaterThan, "p5"),
                new FilterRequest("p6", FilterType.LessThanOrEqual, "p6"),
                new FilterRequest("p7", FilterType.GreaterThanOrEqual, "p7"),
            };
            var context = new HttpContextStorage();

            foreach (var filterRequest in filterRequests)
            {
                var prefix = FilterByClientRequestInterpreter.FilterTypeMap
                             .Where(p => p.Value == filterRequest.FilterType)
                             .Select(p => p.Key)
                             .First();
                context.SetValue(filterRequest.Property, $"{prefix}{filterRequest.Filter}");
            }

            var interpreter = new FilterByClientRequestInterpreter(
                context, new MockPropertyNameResolver());
            var result = interpreter
                         .ParseRequestQuery(filterRequests.Select(r => r.Property).ToList())
                         .ToList();

            foreach (var filterRequest in filterRequests)
            {
                Assert.Contains(filterRequest, result, new PropertyComparer <FilterRequest>());
            }
        }
コード例 #2
0
 public void Should_SetValue_in_HttpContext()
 {
     using (var simulatedContext = new HttpSimulator())
     {
         var key      = "testKey";
         var expected = "Some Text";
         simulatedContext.SimulateRequest();
         var contextStorage = new HttpContextStorage(MockRepository.GenerateStub <IContextStorage>());
         contextStorage.SetValue(key, expected);
         var actual = HttpContext.Current.Items[key];
         actual.ShouldBe(expected);
     }
 }
コード例 #3
0
        public void Should_Get_Generic_Value_in_HttpContext()
        {
            using (var simulatedContext = new HttpSimulator())
            {
                var key      = "testKey";
                var expected = "Some Text";
                simulatedContext.SimulateRequest();
                var contextStorage = new HttpContextStorage(MockRepository.GenerateStub <IContextStorage>());

                var testObject = new TestObject
                {
                    Text = expected
                };

                contextStorage.SetValue(key, testObject);
                var actual = contextStorage.GetValue <TestObject>(key);
                actual.Text.ShouldBe(expected);
            }
        }