Exemple #1
0
        public void TestWithoutSerializableHandler()
        {
            IDataPortal <SerializationRoot> dataPortal = _testDIContext.CreateDataPortal <SerializationRoot>();

            TestResults.Reinitialise();
            UnitTestContext             context = GetContext();
            SerializationRoot           root    = SerializationRoot.NewSerializationRoot(dataPortal);
            nonSerializableEventHandler handler = new nonSerializableEventHandler();

            handler.Reg(root);
            root.Data = "something";
            context.Assert.AreEqual("1", TestResults.GetResult("PropertyChangedFiredCount"));
            root.Data = "something else";
            context.Assert.AreEqual("2", TestResults.GetResult("PropertyChangedFiredCount"));

            //serialize an object with eventhandling objects that are nonserializable
            root      = root.Clone();
            root.Data = "something new";

            //still at 2 even though we changed the property again
            //when the clone method performs serialization, the nonserializable
            //object containing an event handler for the propertyChanged event
            //is lost
            context.Assert.AreEqual("2", TestResults.GetResult("PropertyChangedFiredCount"));
            context.Assert.Success();
        }
Exemple #2
0
    public void Clone()
    {
      Csla.ApplicationContext.GlobalContext.Clear();
      UnitTestContext context = GetContext();
      SerializationRoot root = new SerializationRoot();

      root = (SerializationRoot)root.Clone();

      context.Assert.AreEqual(
        true, 
        Csla.ApplicationContext.GlobalContext["Deserialized"],
        "Deserialized not called");
      context.Assert.Success();
    }
Exemple #3
0
        public void Clone()
        {
            IDataPortal <SerializationRoot> dataPortal = _testDIContext.CreateDataPortal <SerializationRoot>();

            TestResults.Reinitialise();
            UnitTestContext   context = GetContext();
            SerializationRoot root    = dataPortal.Create();

            root = (SerializationRoot)root.Clone();

            context.Assert.AreEqual(
                "true",
                TestResults.GetResult("Deserialized"),
                "Deserialized not called");
            context.Assert.Success();
        }
Exemple #4
0
 public void TestSerializableEventsActionFails()
 {
   var root = new SerializationRoot();
   var nonSerClass = new NonSerializedClass();
   Action<object, PropertyChangedEventArgs> h = (sender, eventArgs) => { nonSerClass.Do(); };
   var method = typeof (Action<object, PropertyChangedEventArgs>).GetMethod("Invoke");
   var delgate = (PropertyChangedEventHandler)(object)method.CreateDelegate(typeof (PropertyChangedEventHandler), h);
   root.PropertyChanged += delgate;
   var b = new BinaryFormatterWrapper();
   try
   {
     b.Serialize(new MemoryStream(), root);
     Assert.Fail("Serialization should have thrown an exception");
   }
   catch (System.Runtime.Serialization.SerializationException)
   {
     // serialization failed as expected
   }
 }
Exemple #5
0
    public void TestWithoutSerializableHandler()
    {
      Csla.ApplicationContext.GlobalContext.Clear();
      UnitTestContext context = GetContext();
      SerializationRoot root = new SerializationRoot();
      nonSerializableEventHandler handler = new nonSerializableEventHandler();
      handler.Reg(root);
      root.Data = "something";
      context.Assert.AreEqual(1, Csla.ApplicationContext.GlobalContext["PropertyChangedFiredCount"]);
      root.Data = "something else";
      context.Assert.AreEqual(2, Csla.ApplicationContext.GlobalContext["PropertyChangedFiredCount"]);

      //serialize an object with eventhandling objects that are nonserializable
      root = root.Clone();
      root.Data = "something new";

      //still at 2 even though we changed the property again 
      //when the clone method performs serialization, the nonserializable 
      //object containing an event handler for the propertyChanged event
      //is lost
      context.Assert.AreEqual(2, Csla.ApplicationContext.GlobalContext["PropertyChangedFiredCount"]);
      context.Assert.Success();
    }
Exemple #6
0
        public void TestSerializableEventsActionFails()
        {
            IDataPortal <SerializationRoot> dataPortal = _testDIContext.CreateDataPortal <SerializationRoot>();

            var root        = SerializationRoot.NewSerializationRoot(dataPortal);
            var nonSerClass = new NonSerializedClass();
            Action <object, PropertyChangedEventArgs> h = (sender, eventArgs) => { nonSerClass.Do(); };
            var method  = typeof(Action <object, PropertyChangedEventArgs>).GetMethod("Invoke");
            var delgate = (PropertyChangedEventHandler)(object)method.CreateDelegate(typeof(PropertyChangedEventHandler), h);

            root.PropertyChanged += delgate;
            // TODO: Should this test target another formatter, or just be deleted?
            //var b = new BinaryFormatterWrapper();
            //try
            //{
            //  b.Serialize(new MemoryStream(), root);
            //  Assert.Fail("Serialization should have thrown an exception");
            //}
            //catch (System.Runtime.Serialization.SerializationException)
            //{
            //  // serialization failed as expected
            //}
        }
Exemple #7
0
    public void SerializableEvents()
    {
      Csla.ApplicationContext.GlobalContext.Clear();
      UnitTestContext context = GetContext();

      SerializationRoot root = new SerializationRoot();
      TestEventSink handler = new TestEventSink();

      root.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler
          (OnIsDirtyChanged);

      root.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler
          (StaticOnIsDirtyChanged);

      root.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler
          (PublicStaticOnIsDirtyChanged);

      root.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler
          (OnIsDirtyChanged);  //will call this method twice since it is assigned twice

      handler.Reg(root);

      root.Data = "abc";

      context.Assert.AreEqual("abc", root.Data, "Data value not set");

      context.Assert.AreEqual(
        "OnIsDirtyChanged",
        Csla.ApplicationContext.GlobalContext["OnIsDirtyChanged"],
        "Didn't call local handler");

      context.Assert.AreEqual(
        "StaticOnIsDirtyChanged",
        Csla.ApplicationContext.GlobalContext["StaticOnIsDirtyChanged"],
        "Didn't call static handler");

      Assert.AreEqual(
        "PublicStaticOnIsDirtyChanged",
        Csla.ApplicationContext.GlobalContext["PublicStaticOnIsDirtyChanged"],
        "Didn't call public static handler");

      Assert.AreEqual(
        "Test.OnIsDirtyChanged",
        Csla.ApplicationContext.GlobalContext["Test.OnIsDirtyChanged"],
        "Didn't call serializable handler");

      Assert.AreEqual(
        "Test.PrivateOnIsDirtyChanged",
        Csla.ApplicationContext.GlobalContext["Test.PrivateOnIsDirtyChanged"],
        "Didn't call serializable private handler");

      root = (SerializationRoot)root.Clone();

      Csla.ApplicationContext.GlobalContext.Clear();

      root.Data = "xyz";

      context.Assert.AreEqual("xyz", root.Data, "Data value not set");

      context.Assert.AreEqual(null, Csla.ApplicationContext.GlobalContext["OnIsDirtyChanged"],
          "Called local handler after clone");

      context.Assert.AreEqual(null, Csla.ApplicationContext.GlobalContext["StaticOnIsDirtyChanged"],
          "Called static handler after clone");

      context.Assert.AreEqual(
        "PublicStaticOnIsDirtyChanged",
        Csla.ApplicationContext.GlobalContext["PublicStaticOnIsDirtyChanged"],
        "Didn't call public static handler after clone");

      context.Assert.AreEqual(
        "Test.OnIsDirtyChanged",
        Csla.ApplicationContext.GlobalContext["Test.OnIsDirtyChanged"],
        "Didn't call serializable handler after clone");

      context.Assert.AreEqual(null, Csla.ApplicationContext.GlobalContext["Test.PrivateOnIsDirtyChanged"],
          "Called serializable private handler after clone");

      context.Assert.Success();
    }
Exemple #8
0
        public void SerializableEvents()
        {
            IDataPortal <SerializationRoot> dataPortal = _testDIContext.CreateDataPortal <SerializationRoot>();

            TestResults.Reinitialise();
            UnitTestContext context = GetContext();

            SerializationRoot root    = SerializationRoot.NewSerializationRoot(dataPortal);
            TestEventSink     handler = new TestEventSink();

            root.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler
                                        (OnIsDirtyChanged);

            root.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler
                                        (StaticOnIsDirtyChanged);

            root.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler
                                        (PublicStaticOnIsDirtyChanged);

            root.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler
                                        (OnIsDirtyChanged); //will call this method twice since it is assigned twice

            handler.Reg(root);

            root.Data = "abc";

            context.Assert.AreEqual("abc", root.Data, "Data value not set");

            context.Assert.AreEqual(
                "OnIsDirtyChanged",
                TestResults.GetResult("OnIsDirtyChanged"),
                "Didn't call local handler");

            context.Assert.AreEqual(
                "StaticOnIsDirtyChanged",
                TestResults.GetResult("StaticOnIsDirtyChanged"),
                "Didn't call static handler");

            Assert.AreEqual(
                "PublicStaticOnIsDirtyChanged",
                TestResults.GetResult("PublicStaticOnIsDirtyChanged"),
                "Didn't call public static handler");

            Assert.AreEqual(
                "Test.OnIsDirtyChanged",
                TestResults.GetResult("Test.OnIsDirtyChanged"),
                "Didn't call serializable handler");

            Assert.AreEqual(
                "Test.PrivateOnIsDirtyChanged",
                TestResults.GetResult("Test.PrivateOnIsDirtyChanged"),
                "Didn't call serializable private handler");

            root = (SerializationRoot)root.Clone();

            TestResults.Reinitialise();

            root.Data = "xyz";

            context.Assert.AreEqual("xyz", root.Data, "Data value not set");

            context.Assert.AreEqual("", TestResults.GetResult("OnIsDirtyChanged"),
                                    "Called local handler after clone");

            context.Assert.AreEqual("", TestResults.GetResult("StaticOnIsDirtyChanged"),
                                    "Called static handler after clone");

            context.Assert.AreEqual(
                "PublicStaticOnIsDirtyChanged",
                TestResults.GetResult("PublicStaticOnIsDirtyChanged"),
                "Didn't call public static handler after clone");

            context.Assert.AreEqual(
                "Test.OnIsDirtyChanged",
                TestResults.GetResult("Test.OnIsDirtyChanged"),
                "Didn't call serializable handler after clone");

            context.Assert.AreEqual("", TestResults.GetResult("Test.PrivateOnIsDirtyChanged"),
                                    "Called serializable private handler after clone");

            context.Assert.Success();
        }