コード例 #1
0
        public void FindDeserializationMethodsWithCache_Caching()
        {
            SerializationEventRaiser eventRaiser = new SerializationEventRaiser();
            List <MethodInfo>        methods     = (List <MethodInfo>)PrivateInvoke.InvokeNonPublicMethod(
                eventRaiser, "FindDeserializationMethodsWithCache", typeof(ClassWithDeserializationEvents), typeof(OnDeserializedAttribute));

            Assert.That(methods, Is.Not.Null);
            List <MethodInfo> methods2 = (List <MethodInfo>)PrivateInvoke.InvokeNonPublicMethod(
                eventRaiser, "FindDeserializationMethodsWithCache", typeof(ClassWithDeserializationEvents), typeof(OnDeserializedAttribute));

            Assert.That(methods2, Is.SameAs(methods));
        }
コード例 #2
0
        public void RaiseOnDeserialization()
        {
            SerializationEventRaiser eventRaiser = new SerializationEventRaiser();

            ClassWithDeserializationEvents instance = new ClassWithDeserializationEvents();

            Assert.That(instance.OnBaseDeserializingCalled, Is.False);
            Assert.That(instance.OnBaseDeserializedCalled, Is.False);
            Assert.That(instance.OnDeserializingCalled, Is.False);
            Assert.That(instance.OnDeserializedCalled, Is.False);
            Assert.That(instance.OnDeserializationCalled, Is.False);

            eventRaiser.RaiseDeserializationEvent(instance, null);

            Assert.That(instance.OnBaseDeserializingCalled, Is.False);
            Assert.That(instance.OnBaseDeserializedCalled, Is.False);
            Assert.That(instance.OnDeserializingCalled, Is.False);
            Assert.That(instance.OnDeserializedCalled, Is.False);
            Assert.That(instance.OnDeserializationCalled, Is.True);
        }
コード例 #3
0
        public void InvokeAttributedMethod_OnDeserializing()
        {
            SerializationEventRaiser eventRaiser = new SerializationEventRaiser();

            ClassWithDeserializationEvents instance = new ClassWithDeserializationEvents();

            Assert.That(instance.OnBaseDeserializingCalled, Is.False);
            Assert.That(instance.OnBaseDeserializedCalled, Is.False);
            Assert.That(instance.OnDeserializingCalled, Is.False);
            Assert.That(instance.OnDeserializedCalled, Is.False);
            Assert.That(instance.OnDeserializationCalled, Is.False);

            eventRaiser.InvokeAttributedMethod(instance, typeof(OnDeserializingAttribute), new StreamingContext());

            Assert.That(instance.OnBaseDeserializingCalled, Is.True);
            Assert.That(instance.OnBaseDeserializedCalled, Is.False);
            Assert.That(instance.OnDeserializingCalled, Is.True);
            Assert.That(instance.OnDeserializedCalled, Is.False);
            Assert.That(instance.OnDeserializationCalled, Is.False);
        }
コード例 #4
0
        public void InvokeAttributedMethod_UsesCache()
        {
            ClassWithDeserializationEvents instance = new ClassWithDeserializationEvents();
            StreamingContext context = new StreamingContext();

            MockRepository           repository      = new MockRepository();
            SerializationEventRaiser eventRaiserMock = repository.StrictMock <SerializationEventRaiser>();

            eventRaiserMock.InvokeAttributedMethod(instance, typeof(OnDeserializedAttribute), context);
            LastCall.CallOriginalMethod(OriginalCallOptions.CreateExpectation);

            Expect.Call(PrivateInvoke.InvokeNonPublicMethod(eventRaiserMock, "FindDeserializationMethodsWithCache", typeof(ClassWithDeserializationEvents), typeof(OnDeserializedAttribute)))
            .Return(new List <MethodInfo>());

            repository.ReplayAll();

            eventRaiserMock.InvokeAttributedMethod(instance, typeof(OnDeserializedAttribute), context);

            repository.VerifyAll();
        }