Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
 public static LocoConfiguration Restored(this LocoConfiguration stored)
 {
     if (stored.LocoAddress != stored.OriginalLocoAddress)
     {
         stored.LocoAddress = stored.OriginalLocoAddress;
     }
     return(stored);
 }
Exemplo n.º 3
0
        public void SetLongAddressWorks()
        {
            var target = new LocoConfiguration {
                LocoAddress = 128
            };

            Assert.AreEqual(128, target.LocoAddress);
            Assert.IsTrue(target.IsLongAddress);
        }
Exemplo n.º 4
0
        public void SetShortAddressWorks()
        {
            var target = new LocoConfiguration {
                LocoAddress = 127
            };

            Assert.AreEqual(127, target.LocoAddress);
            Assert.IsFalse(target.IsLongAddress);
        }
Exemplo n.º 5
0
        public void GetLongAddressWorks()
        {
            var target = new LocoConfiguration
            {
                PrimaryAddress          = 3,
                ExtendedAddressMsb      = 197,
                ExtendedAddressLsb      = 230,
                ConfigurationVariable29 = CV29Flags.ExtendedAddresInUse
            };

            Assert.AreEqual(1510, target.LocoAddress);
        }
Exemplo n.º 6
0
 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);
 }
Exemplo n.º 7
0
        public void SetAddress3Throws()
        {
            var target = new LocoConfiguration();

            Assert.ThrowsException <ArgumentOutOfRangeException>(() => target.LocoAddress = 3);
        }
Exemplo n.º 8
0
 public void Save(LocoConfiguration configuration) => Stored[configuration.LocoAddress] = configuration;
Exemplo n.º 9
0
 public void Write(LocoConfiguration configuration)
 {
     Instance = configuration;
 }
Exemplo n.º 10
0
 public TestDecoderService(LocoConfiguration instance)
 {
     Instance = instance;
 }
Exemplo n.º 11
0
 private static LocoChecker Create(LocoConfiguration configuration) => new LocoChecker("Manufacturers.txt".Read, new TestDecoderService(configuration), new TestLocoAddressService(), new TestLocoConfigurationStore());