public void ConnectTo(IUsbSocket socket) { MAmp mAmps = socket.GetPower(); if (mAmps > this._maxMAmps) { throw new OverflowException(); } this._mAmps = mAmps; }
public override void Execute() { MAmp maxUsbPower = 200; var phone = new Phone(maxMAmps: maxUsbPower); Assert.False(phone.IsCharging); var outlet = new AcOutlet(amps: 15); var adapter = new UsbAdapter(socket: outlet, maxMAmps: maxUsbPower); phone.ConnectTo(adapter); Assert.True(phone.IsCharging); var badAdapter = new BadUsbAdapter(socket: outlet); Assert.Throws <OverflowException>(() => phone.ConnectTo(badAdapter)); }
public Phone(MAmp maxMAmps) { this._maxMAmps = maxMAmps; }
public UsbAdapter(IAcSocket socket, MAmp maxMAmps) { this._socket = socket; this._maxMAmps = maxMAmps; }