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 ChargerTaskDischargeTest() { var battery = new Battery(); Assert.AreEqual(100, battery.Charge); var charger = new ChargerTask(battery); Thread.Sleep(2000); Assert.IsTrue(100 > battery.Charge); charger.FinalyzeCharge(); }
public void ChargeLevelIncreasingByTaskTest() { //Arrange LiPoBattery battery = new LiPoBattery(5000, 3.7, 95); int expectedResult = 100; ChargerTask chargerTask = new ChargerTask(battery); //Act chargerTask.Start(); Thread.Sleep(10); int actualResult = battery.ChargeLevel; chargerTask.Stop(); //Assert Assert.AreEqual(expectedResult, actualResult); }