Exemplo n.º 1
0
 public void TestDeviceImplementation()
 {
     var xmlString = File.ReadAllText(@"xml_loader_prefix.xml");
     const int packetLenght = 34;
     const int packetCount = 0x100;
     var buffer = new Byte[packetLenght * packetCount + xmlString.Length + 1];
     Array.Copy(Encoding.ASCII.GetBytes(xmlString), buffer, xmlString.Length);
     buffer[xmlString.Length] = 0x00;
     var memoryStream = new MemoryStream(buffer);
     var protocol = new FakeProtocol();
     var timer = new FakeTimer();
     var device = new TimerDeviceImpl(protocol, timer) {PacketLenght = packetLenght};
     _errorString = "";
     _finished = false;
     device.FinishedHandler += device_FinishedHandler;
     device.ErrorHandler += device_ErrorHandler;
     device.ProcessHandler += device_ProcessHandler;
     device.PacketHandler += device_PacketHandler;
     Assert.IsTrue(device.StartFlashing(memoryStream));
     for (var i = 0; i < 100; ++i)
         timer.Advance(3500);
     var iterCount = 0;
     while (!_finished) {
         protocol.Process();
         iterCount++;
         if (iterCount == 100)
             timer.Advance(1001);
     }
     Assert.AreEqual("", _errorString);
     Assert.AreEqual(packetCount + 1 + 100, protocol.PacketCount);
 }
Exemplo n.º 2
0
 public void TestFakeTimer()
 {
     var t = new FakeTimer();
     _count = 0;
     t.Elapsed += OnElapsed;
     t.Start(100.0);
     t.Advance(1001.0);
     Assert.AreEqual(10, _count);
 }