示例#1
0
        public void TranslatorShouldFailOnUnrecognizedFunctionCall()
        {
            var    node      = new SingleValueFunctionCallNode("fake", new[] { Parameter <string>("s"), Constant("foo") }, null);
            Action translate = () => this.testSubject.TranslateNode(node);

            translate.ShouldThrow <DataServiceException>(ErrorStrings.RequestQueryParser_UnknownFunction("fake"));
        }
示例#2
0
        public void OperationCacheContainsShouldThrowIfActionIsNotReadOnly()
        {
            var    equivalentAction = CreateAction(this.actionWithBindingParameter1.Name, ResourceType.GetPrimitiveResourceType(typeof(string)), this.entityType1);
            Action lookup           = () => this.testSubject.Contains(equivalentAction);

            lookup.ShouldThrow <DataServiceException>().WithMessage(Strings.DataServiceProviderWrapper_ServiceOperationNotReadonly(this.actionWithBindingParameter1.Name));
        }
示例#3
0
        public void TranslatorShouldFailOnReplaceIfDisabled()
        {
            var withReplaceDisabled = this.CreateTestSubject(new DataServiceBehavior {
                AcceptReplaceFunctionInQuery = false
            });
            var    node      = new SingleValueFunctionCallNode("replace", new[] { Parameter <string>("s"), Constant("foo"), Constant("bar") }, null);
            Action translate = () => withReplaceDisabled.TranslateNode(node);

            translate.ShouldThrow <DataServiceException>(ErrorStrings.RequestQueryParser_UnknownFunction("fake"));
        }
        public void ActionProviderWrapperShouldFailOnDuplicateOverload()
        {
            var duplicateAction1 = new ServiceAction("Duplicate", ResourceType.GetPrimitiveResourceType(typeof(string)), OperationParameterBindingKind.Sometimes, new[] { new ServiceActionParameter("p1", this.entityType), new ServiceActionParameter("p2", ResourceType.GetPrimitiveResourceType(typeof(string))) }, null);

            duplicateAction1.SetReadOnly();
            var duplicateAction2 = new ServiceAction("Duplicate", ResourceType.GetPrimitiveResourceType(typeof(int)), OperationParameterBindingKind.Sometimes, new[] { new ServiceActionParameter("p1", this.entityType) }, null);

            duplicateAction2.SetReadOnly();
            this.provider.ActionProvider = new TestActionProvider
            {
                GetByBindingTypeCallback = (context, rt) => new[] { duplicateAction1, duplicateAction2 },
            };

            Action getByParameterType = () => this.actionProvider.GetServiceActionsByBindingParameterType(this.entityType);

            getByParameterType.ShouldThrow <DataServiceException>()
            .WithMessage(ErrorStrings.DataServiceActionProviderWrapper_DuplicateAction("Duplicate"))
            .And.StatusCode.Should().Be(500);
        }
示例#5
0
        public void DataServiceProviderWrapperShouldFailOnMultipleServiceOperationsWithSameName()
        {
            ResourceType stringType          = ResourceType.GetPrimitiveResourceType(typeof(string));
            var          duplicateOperation1 = new ServiceOperation("Duplicate", ServiceOperationResultKind.DirectValue, stringType, null, "GET", new[] { new ServiceOperationParameter("p1", stringType) });

            duplicateOperation1.SetReadOnly();
            var duplicateOpration2 = new ServiceOperation("Duplicate", ServiceOperationResultKind.DirectValue, ResourceType.GetPrimitiveResourceType(typeof(int)), null, "GET", new ServiceOperationParameter[0]);

            duplicateOpration2.SetReadOnly();

            var providerWrapper = CreateProviderWrapper(addMetadata: p =>
            {
                p.AddServiceOp(duplicateOperation1);
                p.AddServiceOp(duplicateOpration2);
            });

            Action getVisibleOperations = () => providerWrapper.GetVisibleOperations().ToList();

            getVisibleOperations.ShouldThrow <DataServiceException>()
            .WithMessage(ErrorStrings.DataServiceProviderWrapper_MultipleServiceOperationsWithSameName("Duplicate"))
            .And.StatusCode.Should().Be(500);
        }
示例#6
0
        public void DataServiceProviderWrapperShouldFailOnMultipleActionsWithSameNameAndBindingType()
        {
            var entityType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "Fake.NS", "Type", false)
            {
                CanReflectOnInstanceType = false
            };

            entityType.AddProperty(new ResourceProperty("Id", ResourcePropertyKind.Key | ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(int)))
            {
                CanReflectOnInstanceTypeProperty = false
            });
            entityType.SetReadOnly();

            var resourceSet = new ResourceSet("MyEntitySet", entityType);

            resourceSet.SetReadOnly();

            ResourceType stringType       = ResourceType.GetPrimitiveResourceType(typeof(string));
            var          duplicateAction1 = new ServiceAction("Duplicate", stringType, OperationParameterBindingKind.Always, new[] { new ServiceActionParameter("p1", entityType), new ServiceActionParameter("p2", stringType) }, null);

            duplicateAction1.SetReadOnly();
            var duplicateAction2 = new ServiceAction("Duplicate", ResourceType.GetPrimitiveResourceType(typeof(int)), OperationParameterBindingKind.Sometimes, new[] { new ServiceActionParameter("p1", entityType) }, null);

            duplicateAction2.SetReadOnly();

            var actionProvider = new TestActionProvider
            {
                GetServiceActionsCallback = ctx => new[] { duplicateAction1, duplicateAction2 }
            };

            var providerWrapper = CreateProviderWrapper(actionProvider, p => p.AddResourceSet(resourceSet));

            Action getVisibleOperations = () => providerWrapper.GetVisibleOperations().ToList();

            getVisibleOperations.ShouldThrow <DataServiceException>()
            .WithMessage(ErrorStrings.DataServiceActionProviderWrapper_DuplicateAction("Duplicate"))
            .And.StatusCode.Should().Be(500);
        }
示例#7
0
        public void DataServiceProviderWrapperShouldFailOnMultipleActionsWithSameNameAndNoBindingType()
        {
            ResourceType stringType       = ResourceType.GetPrimitiveResourceType(typeof(string));
            var          duplicateAction1 = new ServiceAction("Duplicate", stringType, OperationParameterBindingKind.Never, new[] { new ServiceActionParameter("p1", stringType) }, null);

            duplicateAction1.SetReadOnly();
            var duplicateAction2 = new ServiceAction("Duplicate", ResourceType.GetPrimitiveResourceType(typeof(int)), OperationParameterBindingKind.Never, new ServiceActionParameter[0], null);

            duplicateAction2.SetReadOnly();

            var actionProvider = new TestActionProvider
            {
                GetServiceActionsCallback = ctx => new[] { duplicateAction1, duplicateAction2 }
            };

            var providerWrapper = CreateProviderWrapper(actionProvider);

            Action getVisibleOperations = () => providerWrapper.GetVisibleOperations().ToList();

            getVisibleOperations.ShouldThrow <DataServiceException>()
            .WithMessage(ErrorStrings.DataServiceActionProviderWrapper_DuplicateAction("Duplicate"))
            .And.StatusCode.Should().Be(500);
        }