Пример #1
0
        public void TestTimeSink03_ChangeTwice()
        {
            /* 创建观察者和被观察者对象 */
            MockTimeSource mockTimeSource = new MockTimeSource();
            MockTimeSink   mockTimeSink   = new MockTimeSink(mockTimeSource);
            MockTimeSink   mockTimeSink1  = new MockTimeSink(mockTimeSource);

            /* 设定观察者对象 */
            mockTimeSource.RegisterObserver(mockTimeSink);
            mockTimeSource.RegisterObserver(mockTimeSink1);

            /* Refresh the souce */
            mockTimeSource.SetTime(1, 3, 5);

            Assert.AreEqual(1, mockTimeSink.GetHour());
            Assert.AreEqual(3, mockTimeSink.GetMinite());
            Assert.AreEqual(5, mockTimeSink.GetSecond());
            Assert.AreEqual(1, mockTimeSink1.GetHour());
            Assert.AreEqual(3, mockTimeSink1.GetMinite());
            Assert.AreEqual(5, mockTimeSink1.GetSecond());

            /* Refresh the souce */
            mockTimeSource.SetTime(2, 4, 6);

            Assert.AreEqual(2, mockTimeSink1.GetHour());
            Assert.AreEqual(4, mockTimeSink1.GetMinite());
            Assert.AreEqual(6, mockTimeSink1.GetSecond());
        }
        public void TestMultipleSinks()
        {
            MockTimeSink sink2 = new MockTimeSink();

            this.source.RegisterObserver(sink2);
            this.source.SetTime(12, 13, 14);
            AssertSinkEquals(sink2, 12, 13, 14);
        }
 private void AssertSinkEquals(MockTimeSink sink,
                               int hours,
                               int mins,
                               int secs)
 {
     Assert.AreEqual(hours, sink.GetHours());
     Assert.AreEqual(mins, sink.GetMinutes());
     Assert.AreEqual(secs, sink.GetSeconds());
 }
        public void TestTimeChange()
        {
            MockTimeSource source = new MockTimeSource();
            MockTimeSink   sink   = new MockTimeSink();

            source.RegisterObserver(sink);

            source.SetTime(3, 4, 5);
            AssertSinkEquals(sink, 3, 4, 5);

            source.SetTime(7, 8, 9);
            AssertSinkEquals(sink, 7, 8, 9);
        }
Пример #5
0
        public static void Test()
        {
            var source = new MockTimeSource();
            var sink   = new MockTimeSink(source);

            source.RegisterObserver(sink);

            // changes in object - source
            source.SetTime(3, 4, 5);
            // affects in object - sink
            AssertSinkEquals(sink, 3, 4, 5);
            Console.WriteLine();
            source.SetTime(7, 8, 9);
            AssertSinkEquals(sink, 7, 8, 9);
        }
Пример #6
0
        public void SetUp()
        {
            tsource = new MockTimeSource();
            var mockSink = new MockTimeSink();

            handle = new TimeHandle(tsource, mockSink);
            mockSink.TimeHandle = handle;
            tester = new ThreadSyncTester();

            sourceThread   = tester.ObtainThread("source");
            sinkThread     = tester.ObtainThread("sink");
            externalThread = tester.ObtainThread("external");

            interval = TimeInterval.FromTicks(1000);

            SetSourceSideActiveOnExternal(true);
        }
        public void TestTimeChanged()
        {
            var source = new MockTimeSource() ;
            var sink = new MockTimeSink();
            source.RegisterObserver(sink);

            int hours = 1;
            int minutes = 2;
            int seconds = 3;
            source.SetTime(hours,minutes,seconds);
            AsserrEquals(sink, hours, minutes, seconds);

            hours = 4;
            minutes = 5;
            seconds = 6;
            source.SetTime(hours, minutes, seconds);
            AsserrEquals(sink, hours, minutes, seconds);
        }
        public void TestTimeChanged()
        {
            var source = new MockTimeSource();
            var sink   = new MockTimeSink();

            source.RegisterObserver(sink);

            int hours   = 1;
            int minutes = 2;
            int seconds = 3;

            source.SetTime(hours, minutes, seconds);
            AsserrEquals(sink, hours, minutes, seconds);

            hours   = 4;
            minutes = 5;
            seconds = 6;
            source.SetTime(hours, minutes, seconds);
            AsserrEquals(sink, hours, minutes, seconds);
        }
 private void AsserrEquals(MockTimeSink sink, int hours, int minutes, int seconds)
 {
     Assert.AreEqual(hours, sink.Hours);
     Assert.AreEqual(minutes, sink.Minutes);
     Assert.AreEqual(seconds, sink.Seconds);
 }
 private void AsserrEquals(MockTimeSink sink, int hours, int minutes, int seconds)
 {
     Assert.AreEqual(hours, sink.Hours);
     Assert.AreEqual(minutes, sink.Minutes);
     Assert.AreEqual(seconds, sink.Seconds);
 }
 public void SetUp()
 {
     this.source = new MockTimeSource();
     this.sink   = new MockTimeSink();
     this.source.RegisterObserver(this.sink);
 }
Пример #12
0
 private static void AssertSinkEquals(MockTimeSink sink, int hours, int mins, int secs)
 {
     Console.WriteLine("Hours equal {0}", hours.Equals(sink.GetHours()).ToString());
     Console.WriteLine("Minutes equal {0}", mins.Equals(sink.GetMinutes()).ToString());
     Console.WriteLine("Seconds equal {0}", secs.Equals(sink.GetSeconds()).ToString());
 }