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();
        }
Esempio n. 2
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);
        }
 public static void RaiseOnDeserializing(object deserializedObject, StreamingContext context)
 {
     ArgumentUtility.CheckNotNull("deserializedObject", deserializedObject);
     s_serializationEventRaiser.InvokeAttributedMethod(deserializedObject, typeof(OnDeserializingAttribute), context);
 }