public void Setup() { //Creating stubs for dependencies stubdoor = Substitute.For <IDoor>(); stubCharger = Substitute.For <IChargeControl>(); stubDisplay = Substitute.For <IDisplay>(); stubRFIDReader = Substitute.For <IRFIDReader>(); stubUsb = Substitute.For <IUsbCharger>(); //Initialising classes for tests usb = new UsbChargerSimulator(); rfidReader = new RFIDReader(); display = new ConcreteDisplay(); door = new Door(); chargeControl = new ChargeControl(stubUsb); stationControl = new StationControl(stubCharger, stubdoor, stubDisplay, stubRFIDReader); _rfidEventArgs = null; rfidReader.RFIDDetectedEvent += (o, args) => { _rfidEventArgs = args; }; _doorEventArgs = null; door.DoorEvent += (o, args) => { _doorEventArgs = args; }; _currentEventArgs = null; usb.CurrentValueEvent += (o, args) => { _currentEventArgs = args; }; }
static void Main(string[] args) { UsbChargerSimulator usb = new UsbChargerSimulator(); IChargeControl charger = new ChargeControl(usb); IDoor door = new Door(); RFIDReader rfidReader = new RFIDReader(); IDisplay display = new ConcreteDisplay(); StationControl control = new StationControl(charger, door, display, rfidReader); bool finish = false; do { string input; System.Console.WriteLine("Indtast E, O, C, R: "); input = Console.ReadLine(); if (string.IsNullOrEmpty(input)) { continue; } switch (input[0]) { case 'E': finish = true; break; case 'O': door.OpenDoor(); break; case 'C': door.CloseDoor(); break; case 'R': System.Console.WriteLine("Indtast RFID id: "); string idString = System.Console.ReadLine(); int id = Convert.ToInt32(idString); rfidReader.ReadRFID(id); break; default: break; } } while (!finish); }