public void BaseLineMultiInstanceTest()
 {
     var start = DateTime.Now;
     for (int i = 0; i < _iterations; i++)
     {
         var t = new MockObject1();
     }
     var end = DateTime.Now;
     Console.WriteLine(string.Format("{0} MultiInstance, Total milliseconds elapsed: {1}", "Base Line", (end - start).TotalMilliseconds));
 }
Ejemplo n.º 2
0
        public void ShouldCancelPropertyChanged()
        {
            var          m1           = new MockObject1();
            const string initialValue = "InitialValue";

            m1.Text1 = initialValue;

            string propertyName = null;

            var notifier = new PropertyChangeNotifier(m1)
            {
                SynchronizationContext = new SynchronizationContextForTests()
            };

            notifier.PropertyChanging += (sender, args) =>
            {
                propertyName = args.PropertyName;
                var cancelArgs = (PropertyChangingEventArgs <string>)args;
                cancelArgs.Cancel();
            };

            bool changedEventRaised = false;

            notifier.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == nameof(MockObject1.Text1))
                {
                    changedEventRaised = true;
                }
            };

            const string p1 = "p1";

            notifier.Set(nameof(MockObject1.Text1), ref m1.text1Field, p1);

            Assert.AreEqual(nameof(MockObject1.Text1), propertyName);
            Assert.AreEqual(initialValue, m1.Text1);
            Assert.IsFalse(changedEventRaised,
                           "Changed event should not be raised when change was cancelled.");
        }
Ejemplo n.º 3
0
        public void ShouldRaisePropertyChangingUsingPropertyName()
        {
            var m1 = new MockObject1();

            string propertyName = null;

            var notifier = new PropertyChangeNotifier(m1)
            {
                SynchronizationContext = new SynchronizationContextForTests()
            };

            notifier.PropertyChanging += (sender, args) =>
            {
                propertyName = args.PropertyName;
            };

            const string p1 = "p1";

            notifier.Set(nameof(MockObject1.Text1), ref m1.text1Field, p1);

            Assert.AreEqual(nameof(MockObject1.Text1), propertyName);
            Assert.AreEqual(p1, m1.Text1);
        }