public T Exchange(T mine, int timeout) // throws TimeoutException, InterruptedException { lock (monitor) { T other; ExchangePoint current = exchanger; if ((other = current.pairing(mine)) != null) { exchanger = new ExchangePoint(); Monitor.PulseAll(monitor); return(other); } if (timeout == 0) { current.restart(); throw new TimeoutException(); } do { try { int refTime = Environment.TickCount; Monitor.Wait(monitor); if (current.state == State.DONE) { return(current.second); } timeout = SynchUtils.RemainingTimeout(refTime, timeout); if (timeout == 0) { current.state = State.TIMEOUT; throw new TimeoutException(); } } catch (ThreadInterruptedException e) { if (current.state == State.DONE) { Thread.CurrentThread.Interrupt(); return(current.second); } current.state = State.INTERRUPTED; throw e; } }while (true); } }
/// ТестируемыйКласс_ТестируемыйМетод_Условия_ОжидаемыйРезультат public void ExchangePoint_ExchangeMoney_UseMsFakes_CorrectResult() { // Инициализация // Arrange var rubles = new List <int> { 1, 2, 3, 4 }; bool wasSumCalulating = false; var calculatingMachine = new StubICalculatingMachine // TODO replace to MsFake { CalculateSumDelegate = (arg) => { wasSumCalulating = true; Assert.AreEqual(1, arg[0]); Assert.AreEqual(2, arg[1]); Assert.AreEqual(3, arg[2]); Assert.AreEqual(4, arg[3]); return(100); } }; var currencyConverter = new StubICurrencyConverter // TODO replace to MsFake { ConvertToUsdDelegate = (arg) => { Assert.AreEqual(100, arg); return(10); } }; var exchangePoint = new ExchangePoint(calculatingMachine, currencyConverter, 10); // Вызов тестируемого метода // Act var result = exchangePoint.ExchangeMoney(rubles); // Проверка результата // Assert Assert.AreEqual(9, result); Assert.IsTrue(wasSumCalulating); }
public UpdateModel3DCommand(ExchangePoint parameters) : base("update", parameters) { }
public Model3DCommand(string type, ExchangePoint parameters) : base(type, parameters) { }