Beispiel #1
0
 public MobilePhoneWithTreadingTasksForm()
 {
     InitializeComponent();
     SimCorpMobileThreadTask = InitSimCorpMobileThreadTask();
     MsgStorage = SimCorpMobileThreadTask.MessageStorage;
     InitSMSNumberComboBox(MsgStorage);
     InitDateTimePickers();
     MsgStorage.MessageAdded   += ShowAddedMessage;
     MsgStorage.MessageDeleted += ShowDeletedMessages;
     //Start background worker
     ChargeBackgroundWorker.RunWorkerAsync();
     //Start charging
     //ChargerThread = new ChargerThread(SimCorpMobile.Battery);
     //ChargerThread.Start();
     ChargerTask = new ChargerTask(SimCorpMobileThreadTask.Battery);
     ChargerTask.Start();
     IsCharging        = true;
     ChargeButton.Text = "Stop charging";
     //Start discharging
     //DischargerThread = new DischargerThread(SimCorpMobile.Battery);
     //DischargerThread.Start();
     DischargerTask = new DischargerTask(SimCorpMobileThreadTask.Battery);
     DischargerTask.Start();
     //Start sending SMS by Thread or by Task
     SimCorpMobileThreadTask.StartGenerateSMS();
 }
        public void ChargeLevelDecreasingByTaskTest()
        {
            //Arrange
            LiPoBattery    battery        = new LiPoBattery(5000, 3.7, 10);
            int            expectedResult = 0;
            DischargerTask dischargerTask = new DischargerTask(battery);

            //Act
            dischargerTask.Start();
            Thread.Sleep(10);
            int actualResult = battery.ChargeLevel;

            //Assert
            Assert.AreEqual(expectedResult, actualResult);
        }