Ejemplo n.º 1
0
        protected override bool Process(IInteraction parameters)
        {
            TestContextInteraction testContext = null;
            IncomingTestData       testInput   = null;
            OutgoingTestableData   testOutput  = null;
            IInteraction           testBundle;
            bool success;

            testBundle = testContext = new TestContextInteraction(this.Name, this.AvailableContext);

            if (HasIngoingData)
            {
                testBundle = testInput = new IncomingTestData(this.IngoingDataFile, testBundle, this.SourceName, this.IngoingContentType);
            }

            if (HasOutgoingDataViewer)
            {
                testBundle = testOutput = new OutgoingTestableData(testBundle);
            }

            success = this.TestSubject.TryProcess(testBundle);

            if (HasIngoingData)
            {
                testInput.Dispose();
            }

            if (HasOutgoingDataViewer)
            {
                // obscure name of the year award goes to
                IInteraction incomingInteractionWithOutgoingData;
                incomingInteractionWithOutgoingData = new SimpleIncomingInteraction(testOutput.GetProduct(), parameters, "test-case-output", this.IngoingContentType);

                success &= this.OutgoingDataViewer.TryProcess(incomingInteractionWithOutgoingData);

                testOutput.Dispose();
            }

            foreach (ProbeResultInteraction result in testContext.ProbeResults)
            {
                if (result.IsMatch)
                {
                    success &= this.MatchingProbeResultViewer.TryProcess(result);
                }
                else
                {
                    success &= this.MismatchingProbeResultViewer.TryProcess(result);
                }
            }

            return(success);
        }
Ejemplo n.º 2
0
        protected override bool Process(IInteraction parameters)
        {
            bool successful = true;

            IInteraction httpInteractionCandidate;

            if (successful = parameters.TryGetClosest(typeof(IHttpInteraction), out httpInteractionCandidate))
            {
                IHttpInteraction httpInteraction = (IHttpInteraction)httpInteractionCandidate;

                if (httpInteraction.ContentType.StartsWith(MimeTypePrefix))
                {
                    string headerBoundary = httpInteraction.ContentType.Substring(MimeTypePrefix.Length);

                    SimpleInteraction mappedValues = new SimpleInteraction(parameters);

                    StreamingMultipartFormDataParser parser = new StreamingMultipartFormDataParser(
                        httpInteraction.IncomingBody,
                        headerBoundary,
                        httpInteraction.Encoding,
                        this.BufferSize
                        );

                    parser.ParameterHandler += delegate(ParameterPart part) {
                        if (this.StringFieldWhiteList.Contains(part.Name))
                        {
                            mappedValues[part.Name] = part.Data;

                            successful &= this.Branches.Get(part.Name, Stub).TryProcess(
                                new WwwInputInteraction(part.Name, part.Data, parameters)
                                );
                        }
                    };

                    parser.FileHandler += delegate(
                        string name,
                        string fileName,
                        string contentType,
                        string contentDisposition,
                        byte[] buffer,
                        int bytes
                        ) {
                        if (this.StringFieldWhiteList.Contains(name))
                        {
                            MemoryStream stream = new MemoryStream(buffer, 0, bytes);

                            SimpleIncomingInteraction incoming = new SimpleIncomingInteraction(
                                stream,
                                mappedValues,
                                contentDisposition,
                                contentType
                                );

                            incoming ["mimetype"] = contentType;

                            incoming ["filename"] = fileName;

                            successful &= this.Branches.Get(name, Stub).TryProcess(incoming);

                            stream.Dispose();
                        }
                    };

                    parser.Run();

                    successful &= this.Mapped.TryProcess(mappedValues);
                }
                else
                {
                    Secretary.Report(5, "Require boundary content type for multipart forms");
                    successful &= Failure.TryProcess(parameters);
                }
            }
            else
            {
                Secretary.Report(5, "Require HttpInteraction for multipart forms");
                successful &= Failure.TryProcess(parameters);
            }

            return(successful);
        }