Пример #1
0
        public override bool Equals(object obj)
        {
            // Check for null values and compare run-time types.
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            GeneratedSerializableObject foo = (GeneratedSerializableObject)obj;

            return
                (
                (b == foo.b) &&
                (
                    (
                        (a == null) &&
                        (foo.a == null)
                    ) ||
                    (
                        (a != null) &&
                        a.Equals(foo.a)
                    )
                )
                );
        }
Пример #2
0
        // Complexity is an abstract measure that corresponds to general
        // fuzziness of a message:  attributes per element, children per
        // element, depth of child-element nesting, etc..
        public GeneratedSerializableObject(int complexity, long size)
        {
            Size       = ((size > 0) ? size : 0);
            Complexity = ((complexity > 0) ? complexity : 1);

            GeneratedSerializableObject pointer = this;

            long dataSizeLong = size / complexity;
            int  dataSize     = ((dataSizeLong > int.MaxValue) ? int.MaxValue : ((int)dataSizeLong));

            a = (complexity < 2) ? null : new GeneratedSerializableObject(complexity - 1, dataSize * (complexity - 1));
            b = MessageTestUtilities.GenerateData(dataSize);
        }
Пример #3
0
        // create a message as specified in parameters
        // Note that certain types ignore certain other parameters.
        // E.g., empty message ignores body size/complexity,
        public Message CreateMessage()
        {
            Message       message;
            Message       model;
            MessageBuffer b;
            object        bodyObject;

            if (body == null)
            {
                switch (type)
                {
                case MessageType.Empty:
                    message = Message.CreateMessage(version, action);
                    break;

                case MessageType.Streamed:
                    model = new CustomGeneratedMessage(this);
                    StringWriter s1 = new StringWriter();
                    model.WriteMessage(new XmlTextWriter(s1));
                    message = Message.CreateMessage(new XmlTextReader(new StringReader(s1.ToString())), int.MaxValue, version);
                    break;

                case MessageType.XmlFormatterObject:
                    bodyObject = new GeneratedSerializableObject(bodyComplexity, bodyContentSize);
                    message    = Message.CreateMessage(version, action, bodyObject);
                    break;

                case MessageType.BodyWriter:
                    message = Message.CreateMessage(version, action, new CustomGeneratedBodyWriter(this));
                    break;

                case MessageType.DefaultBuffered:
                    model   = new CustomGeneratedMessage(this);
                    b       = model.CreateBufferedCopy(int.MaxValue);
                    message = b.CreateMessage();
                    break;

                case MessageType.BufferedBodyBuffered:
                    bodyObject = new GeneratedSerializableObject(bodyComplexity, bodyContentSize);
                    model      = Message.CreateMessage(version, action, bodyObject);
                    b          = model.CreateBufferedCopy(int.MaxValue);
                    message    = b.CreateMessage();
                    break;

                case MessageType.BufferedBuffered:
                    model = new CustomGeneratedMessage(this);
                    MessageEncoder e = (new TextMessageEncodingBindingElement(model.Version, Encoding.UTF8)).CreateMessageEncoderFactory().Encoder;
                    model   = e.ReadMessage(e.WriteMessage(model, int.MaxValue, new SimpleBufferManager(), 0), new SimpleBufferManager());
                    b       = model.CreateBufferedCopy(int.MaxValue);
                    message = b.CreateMessage();
                    break;

                case MessageType.Custom:
                    message = new CustomGeneratedMessage(this);
                    break;

                case MessageType.Fault:
                    MessageFault fault;

                    if (bodyComplexity > 1)
                    {
                        var translations = new Collection <FaultReasonText>
                        {
                            new FaultReasonText("Reason: auto-generated fault for testing.", "en-US"),
                            new FaultReasonText("Raison: auto-generat error pour examiner.", "fr")
                        };
                        var    reason       = new FaultReason(translations);
                        object detailObject = new GeneratedSerializableObject(bodyComplexity, bodyContentSize);
                        fault = MessageFault.CreateFault(new FaultCode("SomeFaultSubCode"), reason, detailObject, new DataContractSerializer(typeof(GeneratedSerializableObject)), "", "");
                    }
                    else
                    {
                        FaultReason reason = new FaultReason("Reason: auto-generated fault for testing.");
                        fault = MessageFault.CreateFault(new FaultCode("SomeFaultSubCode"), reason, "", new DataContractSerializer(typeof(string)), "", "");
                    }

                    message = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, fault, "http://www.w3.org/2005/08/addressing/fault");
                    break;

                default:
                    throw new NotSupportedException();
                }
            }
            else
            {
                switch (type)
                {
                case MessageType.Custom:
                    message = new CustomStringMessage(this);
                    break;

                case MessageType.Streamed:
                    model = new CustomStringMessage(this);
                    StringWriter s1 = new StringWriter();
                    model.WriteMessage(new XmlTextWriter(s1));
                    message = Message.CreateMessage(new XmlTextReader(new StringReader(s1.ToString())), int.MaxValue, version);
                    break;

                case MessageType.DefaultBuffered:
                    model   = new CustomStringMessage(this);
                    b       = model.CreateBufferedCopy(int.MaxValue);
                    message = b.CreateMessage();
                    break;

                case MessageType.BufferedBuffered:
                    model = new CustomStringMessage(this);
                    MessageEncoder e = (new TextMessageEncodingBindingElement(model.Version, Encoding.UTF8)).CreateMessageEncoderFactory().Encoder;
                    model   = e.ReadMessage(e.WriteMessage(model, int.MaxValue, new SimpleBufferManager(), 0), new SimpleBufferManager());
                    b       = model.CreateBufferedCopy(int.MaxValue);
                    message = b.CreateMessage();
                    break;

                default:
                    throw new NotSupportedException();
                }
            }

            for (int i = 0; i < headers; i++)
            {
                message.Headers.Add(new CustomGeneratedHeader(i, headerComplexity));
            }

            return(message);
        }