Пример #1
0
        public void SingleOrDefault_IQueryableOfT_ZeroElementsInSequence_ReturnsNull()
        {
            IQueryable <Customer> queryable        = Enumerable.Empty <Customer>().AsQueryable();
            HttpActionDescriptor  actionDescriptor = new Mock <HttpActionDescriptor>().Object;

            var result = QueryableAttribute.SingleOrDefault(queryable, actionDescriptor);

            Assert.Null(result);
        }
Пример #2
0
        public void SingleOrDefault_IQueryableOfT_OneElementInSequence_ReturnsElement()
        {
            Customer customer = new Customer();
            IQueryable <Customer> queryable = new[] { customer }.AsQueryable();
            HttpActionDescriptor  actionDescriptor = new Mock <HttpActionDescriptor>().Object;

            var result = QueryableAttribute.SingleOrDefault(queryable, actionDescriptor);

            Assert.Same(customer, result);
        }
Пример #3
0
        public void SingleOrDefault_IQueryableOfT_MoreThaneOneElementInSequence_Throws()
        {
            IQueryable <Customer>         queryable = new[] { new Customer(), new Customer() }.AsQueryable();
            ReflectedHttpActionDescriptor actionDescriptor = new ReflectedHttpActionDescriptor
            {
                Configuration        = new HttpConfiguration(),
                MethodInfo           = GetType().GetMethod("SomeAction", BindingFlags.Instance | BindingFlags.NonPublic),
                ControllerDescriptor = new HttpControllerDescriptor {
                    ControllerName = "SomeName"
                }
            };

            Assert.Throws <InvalidOperationException>(
                () => QueryableAttribute.SingleOrDefault(queryable, actionDescriptor),
                "The action 'SomeAction' on controller 'SomeName' returned a SingleResult containing more than one element. " +
                "SingleResult must have zero or one elements.");
        }