コード例 #1
0
        internal static async Task <TResponse> SendReceiveAsync <TRequest, TResponse>(LightweightMethodStub methodStub, TRequest request, IRpcSerializer serializer)
            where TRequest : class
            where TResponse : class
        {
            TResponse response;

            var context      = new LightweightCallContext(new TestRpcEndPoint(), null, ImmutableArray <KeyValuePair <string, ImmutableArray <byte> > > .Empty, CancellationToken.None);
            var requestPipe  = new Pipe();
            var responsePipe = new Pipe();
            var duplexPipe   = new DirectDuplexPipe(requestPipe.Reader, responsePipe.Writer);

            await using (var pipeline = new TestPipeline(duplexPipe))
            {
                var payload = new ReadOnlySequence <byte>(serializer.Serialize(request));

                var frame = new LightweightRpcFrame(RpcFrameType.UnaryRequest, null, 1, methodStub.OperationName, RpcOperationFlags.None, 0, payload, null);

                await methodStub.HandleMessage(pipeline, frame, null, context);

                var readResult = await responsePipe.Reader.ReadAsync();

                var  buffer           = readResult.Buffer;
                bool hasResponseFrame = LightweightRpcFrame.TryRead(ref buffer, 65536, out var responseFrame) == RpcFrameState.Full;
                Assert.IsTrue(hasResponseFrame);

                response = (TResponse)serializer.Deserialize(responseFrame.Payload, typeof(TResponse));

                return(response);
            }
        }
コード例 #2
0
        public void Should_Fail_If_Exception_Occured(bool errorOnRead, bool errorOnTransform, bool errorOnWrite)
        {
            var    pipeline = new TestPipeline(errorOnRead, errorOnTransform, errorOnWrite);
            Action process  = () => pipeline.Process();

            process.Should().Throw <PipelineException>().WithInnerException <ExpectedException>();
        }
コード例 #3
0
        public void SetNotExistColumnToUnique()
        {
            var exception = Assert.Throws <SpiderException>(() =>
            {
                var entityMetadata    = EntitySpider.ParseEntityMetaData(typeof(Entity3).GetTypeInfo());
                TestPipeline pipeline = new TestPipeline();
                pipeline.InitiEntity(entityMetadata);
            });

            Assert.Equal("Columns set as unique is not a property of your entity.", exception.Message);
        }
コード例 #4
0
        private PipelinePhase GetPipelineAndPhase(
            string pipelineName,
            Phase phase,
            IPipelineCollection pipelines,
            ConcurrentDictionary <string, ImmutableArray <IDocument> > documentCollection,
            IDocument[] documents,
            params PipelinePhase[] dependencies)
        {
            TestPipeline  pipeline      = new TestPipeline();
            PipelinePhase pipelinePhase = new PipelinePhase(pipeline, pipelineName, phase, Array.Empty <IModule>(), NullLogger.Instance, dependencies);

            pipelines.Add(pipelineName, pipeline);
            documentCollection.AddOrUpdate(pipelineName, documents.ToImmutableArray(), (_, __) => documents.ToImmutableArray());
            return(pipelinePhase);
        }
コード例 #5
0
        private PipelinePhase GetPipelineAndPhase(
            string pipelineName,
            Phase phase,
            IPipelineCollection pipelines,
            ConcurrentDictionary <string, PhaseResult[]> phaseResults,
            IDocument[] outputs,
            params PipelinePhase[] dependencies)
        {
            TestPipeline  pipeline      = new TestPipeline();
            PipelinePhase pipelinePhase = new PipelinePhase(pipeline, pipelineName, phase, Array.Empty <IModule>(), NullLogger.Instance, dependencies);

            pipelines.Add(pipelineName, pipeline);
            PhaseResult[] results = new PhaseResult[4];
            results[(int)Phase.Process] = new PhaseResult(pipelineName, Phase.Process, outputs.ToImmutableArray(), 0);
            phaseResults.TryAdd(pipelineName, results);
            return(pipelinePhase);
        }
コード例 #6
0
        private PipelinePhase GetPipelineAndPhase(
            string pipelineName,
            Phase currentPhase,
            IPipelineCollection pipelines,
            ConcurrentDictionary <string, PhaseResult[]> phaseResults,
            IDocument[] outputs,
            Phase phaseForOutputs,
            params PipelinePhase[] dependencies)
        {
            TestPipeline  pipeline      = new TestPipeline();
            PipelinePhase pipelinePhase = new PipelinePhase(pipeline, pipelineName, currentPhase, Array.Empty <IModule>(), NullLogger.Instance, dependencies);

            pipelines.Add(pipelineName, pipeline);
            PhaseResult[] results = new PhaseResult[4];
            if (outputs != null)
            {
                results[(int)phaseForOutputs] = new PhaseResult(pipelineName, phaseForOutputs, outputs.ToImmutableArray(), default, 0);
コード例 #7
0
        public void ShareUsageElement_SessionIdAndSequence_Existing()
        {
            // Arrange
            CreateShareUsage(1, 1, 1, new List <string>(), new List <string>(), new List <KeyValuePair <string, string> >());

            Dictionary <string, object> evidenceData = new Dictionary <string, object>()
            {
                { Core.Constants.EVIDENCE_CLIENTIP_KEY, "1.2.3.4" },
                { Constants.EVIDENCE_SESSIONID, "abcdefg-hijklmn-opqrst-uvwyxz" },
                { Constants.EVIDENCE_SEQUENCE, "2" },
            };

            var pipeline = new TestPipeline(_pipeline.Object);
            var data     = new TestFlowData(new Logger <TestFlowData>(new LoggerFactory()), pipeline, new Evidence(new Logger <Evidence>(new LoggerFactory())));

            data.AddEvidence(evidenceData);

            // Act
            _sequenceElement.Process(data);
            _shareUsageElement.Process(data);
            // Wait for the consumer task to finish.
            Assert.IsNotNull(_shareUsageElement.SendDataTask);
            _shareUsageElement.SendDataTask.Wait();

            // Assert
            // Check that one and only one HTTP message was sent
            _httpHandler.Verify(h => h.Send(It.IsAny <HttpRequestMessage>()), Times.Once);
            Assert.AreEqual(1, _xmlContent.Count);

            // Validate that the XML is well formed by passing it through a reader
            using (XmlReader xr = XmlReader.Create(new StringReader(_xmlContent[0])))
            {
                while (xr.Read())
                {
                }
            }

            // Check that the expected values are populated.
            Assert.IsTrue(_xmlContent[0].Contains("<SessionId>abcdefg-hijklmn-opqrst-uvwyxz</SessionId>"));
            Assert.IsTrue(_xmlContent[0].Contains("<Sequence>3</Sequence>"));
            Assert.IsTrue(data.GetEvidence().AsDictionary().ContainsKey(Constants.EVIDENCE_SESSIONID));
            Assert.IsTrue(data.GetEvidence().AsDictionary().ContainsKey(Constants.EVIDENCE_SEQUENCE));
        }
コード例 #8
0
 public NamedPipelineBaseFixture()
 {
     this.pipeline = new TestPipeline();
 }