コード例 #1
0
ファイル: NotificationTest.cs プロジェクト: guidgets/XamlGrid
        public void NameAccessors()
        {
            // Create a new Notification and use accessors to set the note name
               			INotification note = new Notification(1);

               			// test assertions
            Assert.IsTrue(note.Code == 1, "Expecting note.Name == 'TestNote'");
        }
コード例 #2
0
ファイル: NotificationTest.cs プロジェクト: guidgets/XamlGrid
        public void TestToString()
        {
            // Create a new Notification and use accessors to set the note name
               			INotification note = new Notification(1, "1,3,5", "TestType");
               			string ts = "Notification Name: 1\nBody:1,3,5\nType:TestType";

               			// test assertions
            Assert.IsTrue(note.ToString() == ts, "Expecting note.testToString() == '" + ts + "'");
        }
コード例 #3
0
ファイル: NotificationTest.cs プロジェクト: guidgets/XamlGrid
        public void BodyAccessors()
        {
            // Create a new Notification and use accessors to set the body
               			INotification note = new Notification(-1);
               			note.Body = 5;

               			// test assertions
            Assert.IsTrue((int) note.Body == 5, "Expecting (int) note.Body == 5");
        }
コード例 #4
0
ファイル: NotificationTest.cs プロジェクト: guidgets/XamlGrid
        public void TestConstructor()
        {
            // Create a new Notification using the Constructor to set the note name and body
               			INotification note = new Notification(1, 5, "TestNoteType");

               			// test assertions
            Assert.IsTrue(note.Code == 1, "Expecting note.Name == 'TestNote'");
            Assert.IsTrue((int) note.Body == 5, "Expecting (int) note.Body == 5");
               			Assert.IsTrue(note.Type == "TestNoteType", "Expecting note.Type == 'TestNoteType'");
        }
コード例 #5
0
        public void SimpleCommandExecute()
        {
            // Create the VO
              			SimpleCommandTestVO vo = new SimpleCommandTestVO(5);

              			// Create the Notification (note)
              			INotification note = new Notification(1, vo);

            // Create the SimpleCommand
            ICommand command = new SimpleCommandTestCommand();

               			// Execute the SimpleCommand
               			command.Execute(note);

               			// test assertions
            Assert.IsTrue(vo.result == 10, "Expecting vo.result == 10");
        }
コード例 #6
0
ファイル: ObserverTest.cs プロジェクト: guidgets/XamlGrid
        public void ObserverAccessors()
        {
            // Create observer with null args, then
               			// use accessors to set notification method and context
            IObserver observer = new Observer(null, null);
            observer.NotifyContext = this;
               			observer.NotifyMethod = this.observerTestMethod;

               			// create a test event, setting a payload value and notify
               			// the observer with it. since the observer is this class
               			// and the notification method is observerTestMethod,
               			// successful notification will result in our local
               			// observerTestVar being set to the value we pass in
               			// on the note body.
               			INotification note = new Notification(1, 10);
            observer.NotifyObserver(note);

            // test assertions
               			Assert.IsTrue(observerTestVar == 10, "Expecting observerTestVar = 10");
        }
コード例 #7
0
ファイル: MainCommandTest.cs プロジェクト: guidgets/XamlGrid
        public void ReregisterAndExecuteCommand()
        {
            // Fetch the MainCommand, register the MainCommandTestCommand2 to handle 'MainCommandTest2' notes
            IMainCommand mainCommand = MainCommand.Instance;
            int name = int.MinValue + Thread.CurrentThread.ManagedThreadId;
            mainCommand.RegisterCommand(name, typeof(MainCommandTestCommand2));

            // Remove the Command from the MainCommand
            mainCommand.RemoveCommand(name);

            // Re-register the Command with the MainCommand
            mainCommand.RegisterCommand(name, typeof(MainCommandTestCommand2));

            // Create a 'MainCommandTest2' note
            MainCommandTestVO vo = new MainCommandTestVO(12);
            Notification note = new Notification(name, vo);

            // retrieve a reference to the MainController.
            IMainController mainController = MainController.Instance;

            // send the Notification
            mainController.NotifyObservers(note);

            // test assertions
            // if the command is executed once the value will be 24
            Assert.IsTrue(vo.result == 24, "Expecting vo.result == 24");

            // Prove that accumulation works in the VO by sending the notification again
            mainController.NotifyObservers(note);

            // if the command is executed twice the value will be 48
            Assert.IsTrue(vo.result == 48, "Expecting vo.result == 48");
        }
コード例 #8
0
ファイル: MainCommandTest.cs プロジェクト: guidgets/XamlGrid
        public void RegisterAndRemoveCommand()
        {
            // Create the MainCommand, register the MainCommandTestCommand to handle 'MainCommandTest' notes
            IMainCommand mainCommand = MainCommand.Instance;
            int name = int.MinValue + Thread.CurrentThread.ManagedThreadId;
            mainCommand.RegisterCommand(name, typeof(MainCommandTestCommand));

            // Create a 'MainCommandTest' note
            MainCommandTestVO vo = new MainCommandTestVO(12);
            INotification note = new Notification(name, vo);

            // Tell the MainCommand to execute the Command associated with the note
            // the MainCommandTestCommand invoked will multiply the vo.input value
            // by 2 and set the result on vo.result
            mainCommand.ExecuteCommand(note);

            // test assertions
            Assert.IsTrue(vo.result == 24, "Expecting vo.result == 24");

            // Reset result
            vo.result = 0;

            // Remove the Command from the MainCommand
            mainCommand.RemoveCommand(name);

            // Tell the MainCommand to execute the Command associated with the
            // note. This time, it should not be registered, and our vo result
            // will not change
            mainCommand.ExecuteCommand(note);

            // test assertions
            Assert.IsTrue(vo.result == 0, "Expecting vo.result == 0");
        }
コード例 #9
0
ファイル: ObserverTest.cs プロジェクト: guidgets/XamlGrid
        public void ObserverConstructor()
        {
            // Create observer passing in notification method and context
            IObserver observer = new Observer(this.observerTestMethod, this);

               			// create a test note, setting a body value and notify
               			// the observer with it. since the observer is this class
               			// and the notification method is observerTestMethod,
               			// successful notification will result in our local
               			// observerTestVar being set to the value we pass in
               			// on the note body.
               			INotification note = new Notification(1, 5);
            observer.NotifyObserver(note);

            // test assertions
               			Assert.IsTrue(observerTestVar == 5, "Expecting observerTestVar = 5");
        }