public void LoadSettings(SavedSettings settings) { Rotor1 = ComponentFactory.CreateRotor(settings.Slot1.RotorType, RotorSlot.One, settings.Slot1.Position); Rotor2 = ComponentFactory.CreateRotor(settings.Slot2.RotorType, RotorSlot.Two, settings.Slot2.Position); Rotor3 = ComponentFactory.CreateRotor(settings.Slot3.RotorType, RotorSlot.Three, settings.Slot3.Position); Reflector = ComponentFactory.CreateReflector(settings.ReflectorType); Plugboard = ComponentFactory.CreatePlugboard(settings.PlugboardConnections); InitializeComponentList(); }
public void AddConnection_NotAllowRecursiveConnection() { // Arrange var factory = new ComponentFactory(new UtilityFactory()); var plugboard = factory.CreatePlugboard(); // Act plugboard.AddConnection('A', 'A'); // Assert Assert.Empty(plugboard.Connections); }
public void AddConnection_NotAllowSameConnections(char from, char to, Dictionary <char, char> connections) { // Arrange var factory = new ComponentFactory(new UtilityFactory()); var plugboard = factory.CreatePlugboard(connections); var connectionsCount = plugboard.Connections.Count; // Act plugboard.AddConnection(from, to); // Assert Assert.True(plugboard.Connections.Count == connectionsCount); }
public void AddConnection_EmptyDictionaryAndCorrectConnections(char from, char to) { // Arrange var factory = new ComponentFactory(new UtilityFactory()); var plugboard = factory.CreatePlugboard(); // Act plugboard.AddConnection(from, to); var connections = plugboard.Connections; // Assert Assert.True(connections.ContainsKey(from)); Assert.True(connections[from] == to); Assert.True(connections.ContainsKey(to)); Assert.True(connections[to] == from); }
public async void Process_GetCorrectOutput(Dictionary <char, char> connections, char inputLetter, char expectedLetter, bool step, bool expectedStep) { // Arrange var utilityFactory = new UtilityFactory(); var factory = new ComponentFactory(utilityFactory); var plugboard = factory.CreatePlugboard(connections); var inputValue = CommonHelper.LetterToNumber(inputLetter); var signal = await utilityFactory.CreateSignal(inputValue, step, SignalDirection.In); // Act var resultSignal = await plugboard.Process(signal); var resultValue = resultSignal.Value; var resultLetter = CommonHelper.NumberToLetter(resultValue); var resultStep = resultSignal.Step; // Assert Assert.Equal(expectedLetter, resultLetter); Assert.Equal(expectedStep, resultStep); }