コード例 #1
0
        public void Test_SuppressWorkflow(bool endpointSuppressWorkflows)
        {
            Mock <IReaderToEntityAdapterProvider> m1 = new Mock <IReaderToEntityAdapterProvider>(MockBehavior.Strict);
            Mock <IResourceResolverProvider>      m2 = new Mock <IResourceResolverProvider>(MockBehavior.Loose);
            Mock <IResourceUriGenerator>          m3 = new Mock <IResourceUriGenerator>(MockBehavior.Loose);

            ApiResourceMapping mapping = new ApiResourceMapping();

            long typeId = Factory.ScriptNameResolver.GetTypeByName("AA_Drink");

            if (typeId == 0)
            {
                mapping.MappedType = null;
            }
            else
            {
                mapping.MappedType = Entity.Get(typeId).As <EntityType>( );
            }

            mapping.MappingSuppressWorkflows = endpointSuppressWorkflows;
            mapping.Save();

            ApiResourceEndpoint apiResourceEndpoint = new ApiResourceEndpoint();

            apiResourceEndpoint.EndpointResourceMapping = mapping;
            apiResourceEndpoint.EndpointCanCreate       = true;
            apiResourceEndpoint.ApiEndpointEnabled      = true;
            apiResourceEndpoint.Save();

            ResourceEndpoint re = new ResourceEndpoint(m1.Object, m2.Object, m3.Object);

            ConnectorRequest request = new ConnectorRequest();

            request.Verb = ConnectorVerb.Post;

            m1.Setup <IReaderToEntityAdapter>(m => m.GetAdapter(It.IsAny <long>(), It.IsAny <ReaderToEntityAdapterSettings>())).Returns(
                () =>
            {
                Assert.That(WorkflowRunContext.Current.DisableTriggers, Is.EqualTo(endpointSuppressWorkflows));
                return(null);
            }
                );

            // We don't care what happens .. as long as the callback was called with the correct context setting
            try
            {
                re.HandleRequest(request, apiResourceEndpoint);
            }
            catch { }

            m1.VerifyAll();
        }
コード例 #2
0
        /// <summary>
        /// Main entry point.
        /// </summary>
        public ConnectorResponse HandleRequest(ConnectorRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            ApiEndpoint            endpoint;
            ApiResourceEndpoint    resourceEndpoint;
            ApiSpreadsheetEndpoint spreadsheetEndpoint = null;

            using (new SecurityBypassContext( ))
            {
                endpoint = GetEndpoint(request);
                if (endpoint == null)
                {
                    return(new ConnectorResponse(HttpStatusCode.NotFound));
                }

                // Check type of endpoint
                resourceEndpoint = endpoint.As <ApiResourceEndpoint>( );

                if (resourceEndpoint == null)
                {
                    spreadsheetEndpoint = endpoint.As <ApiSpreadsheetEndpoint>( );
                }
            }

            if (resourceEndpoint != null)
            {
                ResourceEndpoint resourceEndpointService = _componentContext.Resolve <ResourceEndpoint>( );
                return(resourceEndpointService.HandleRequest(request, resourceEndpoint));
            }
            if (spreadsheetEndpoint != null)
            {
                SpreadsheetEndpoint spreadsheetEndpointService = _componentContext.Resolve <SpreadsheetEndpoint>( );
                return(spreadsheetEndpointService.HandleRequest(request, spreadsheetEndpoint));
            }
            throw new NotImplementedException("Unknown ApiEndpoint type");
        }