Ejemplo n.º 1
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();
    }
Ejemplo n.º 2
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();
        }