public static IEnumerable <Message> Analyse(this LocoConfiguration configuration, IEnumerable <Manufacturer> manufacturers, LocoAddressBooking?existingBooking = null) { var messages = new List <Message>(30) { new Message(MessageSeverity.Information, Strings.DecoderManufacturer, manufacturers.SingleOrDefault(m => m.Number == configuration.ManufacturerId)?.Name ?? Strings.Unknown), new Message(MessageSeverity.Information, configuration.IsLongAddress ? Strings.LongAddress : Strings.ShortAddress, configuration.LocoAddress), new Message(MessageSeverity.Information, Strings.SpeedSteps, configuration.Is28Or128SpeedSteps ? "28/128" : "14") }; if (existingBooking != null) { messages.Add(new Message(MessageSeverity.Warning, string.Format(CultureInfo.CurrentCulture, Strings.ExistingLocoAddressWarning, existingBooking.Address, existingBooking.Owner, existingBooking.Loco))); } if (configuration.ConsistAddress > 0) { messages.Add(new Message(MessageSeverity.Suggestion, Strings.CV19Warning, configuration.ConsistAddress)); } if (configuration.DeaccellerationRate > 5) { messages.Add(new Message(MessageSeverity.Suggestion, Strings.DeaccelerationWarning, configuration.DeaccellerationRate)); } if (configuration.IsAnalogOperationEnabled) { messages.Add(new Message(MessageSeverity.Warning, Strings.AnalogOperationWillBeDIsabled)); } if (configuration.IsRailComEnabled) { messages.Add(new Message(MessageSeverity.Warning, Strings.RailComWillBeDisabled)); } if (configuration.DecoderNumber > 0) { messages.Add(new Message(MessageSeverity.Information, Strings.DecoderNumberIsNonZero, configuration.DecoderNumber)); } return(messages); }
public static LocoConfiguration Restored(this LocoConfiguration stored) { if (stored.LocoAddress != stored.OriginalLocoAddress) { stored.LocoAddress = stored.OriginalLocoAddress; } return(stored); }
public void SetLongAddressWorks() { var target = new LocoConfiguration { LocoAddress = 128 }; Assert.AreEqual(128, target.LocoAddress); Assert.IsTrue(target.IsLongAddress); }
public void SetShortAddressWorks() { var target = new LocoConfiguration { LocoAddress = 127 }; Assert.AreEqual(127, target.LocoAddress); Assert.IsFalse(target.IsLongAddress); }
public void GetLongAddressWorks() { var target = new LocoConfiguration { PrimaryAddress = 3, ExtendedAddressMsb = 197, ExtendedAddressLsb = 230, ConfigurationVariable29 = CV29Flags.ExtendedAddresInUse }; Assert.AreEqual(1510, target.LocoAddress); }
public static LocoConfiguration Corrected(this LocoConfiguration original, bool resetConsistAddress, bool resetDeacceleration, int?newLocoAddress) { original.DisableAnalogeOperation(); original.DisableRailCom(); if (resetConsistAddress) { original.ConsistAddress = 0; } if (resetDeacceleration) { original.DeaccellerationRate = 1; } original.OriginalLocoAddress = original.LocoAddress; if (newLocoAddress.HasValue) { original.LocoAddress = newLocoAddress.Value; } return(original); }
public void SetAddress3Throws() { var target = new LocoConfiguration(); Assert.ThrowsException <ArgumentOutOfRangeException>(() => target.LocoAddress = 3); }
public void Save(LocoConfiguration configuration) => Stored[configuration.LocoAddress] = configuration;
public void Write(LocoConfiguration configuration) { Instance = configuration; }
public TestDecoderService(LocoConfiguration instance) { Instance = instance; }
private static LocoChecker Create(LocoConfiguration configuration) => new LocoChecker("Manufacturers.txt".Read, new TestDecoderService(configuration), new TestLocoAddressService(), new TestLocoConfigurationStore());