public void TestAddObjectByReference1()
        {
            var reference = new ByReferenceClass(9001);
            var value     = new FieldObjectStruct
            {
                Value = reference
            };

            var    subject     = new Mock <IVoidMethodObjectParameter>();
            object actualValue = null;

            subject.Setup(x => x.AddListener(It.IsAny <object>()))
            .Callback((object x) => actualValue = x);

            const ulong servantId = 25;

            _server.CreateServant(servantId, subject.Object);
            var proxy = _client.CreateProxy <IVoidMethodObjectParameter>(servantId);

            proxy.AddListener(value);
            actualValue.Should().NotBeNull();
            actualValue.Should().BeOfType <FieldObjectStruct>();
            (((FieldObjectStruct)actualValue).Value is IByReferenceType).Should().BeTrue();
            object actualReference = ((FieldObjectStruct)actualValue).Value;

            proxy.AddListener(value);
            ((FieldObjectStruct)actualValue).Value.Should()
            .BeSameAs(actualReference,
                      "Because [ByReference] types should adhere to referential equality after deserialization");

            // This line exists to FORCE the GC to NOT collect the subject, which
            // in turn would unregister the servant from the server, thus making the test
            // fail sporadically.
            GC.KeepAlive(subject);
        }
Exemple #2
0
        public void TestFieldObjectStructWithNull()
        {
            var value = new FieldObjectStruct {
                Value = null
            };

            _serializer.ShouldRoundtrip(value);
        }
Exemple #3
0
        public void TestFieldObjectStructWithString()
        {
            var value = new FieldObjectStruct {
                Value = "I'm your father, Luke"
            };

            _serializer.ShouldRoundtrip(value);
        }
Exemple #4
0
        public void TestFieldObjectStructWithDouble()
        {
            var value = new FieldObjectStruct {
                Value = Math.PI
            };

            _serializer.ShouldRoundtrip(value);
        }
Exemple #5
0
        public void TestWriteObjectFieldWithString()
        {
            var value = new FieldObjectStruct {
                Value = "I'm your father, Luke"
            };

            _serializer.WriteObject(_writer, value, null);
            _data.Position = 0;

            _reader.ReadString().Should().Be(typeof(FieldObjectStruct).AssemblyQualifiedName);
            _reader.ReadString().Should().Be(typeof(string).AssemblyQualifiedName);
            _reader.ReadString().Should().Be("I'm your father, Luke");

            _data.Position.Should().Be(_data.Length);
        }