/// <summary> /// The validate settings. /// </summary> /// <param name="settings"> /// The settings. /// </param> /// <param name="throws"> /// The throws. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public static bool ValidateSettings(BiscuitMakerSettings settings, bool throws = false) { var errorMessage = string.Empty; errorMessage += GetErrorMessage( throws, settings == null && string.IsNullOrEmpty(errorMessage), "Settings can not be null"); errorMessage += GetErrorMessage( throws, settings != null && (string.IsNullOrEmpty(errorMessage) && settings.ConveyorSize <= 2 + settings.OvenSize), "Conveyor too small"); errorMessage += GetErrorMessage( throws, settings != null && (string.IsNullOrEmpty(errorMessage) && (settings.ExtruderIndex >= settings.StamperIndex || settings.StamperIndex >= settings.OvenIndex || settings.OvenIndex >= (settings.OvenIndex + settings.OvenSize) || (settings.OvenIndex + settings.OvenSize) >= settings.ConveyorSize)), "Invalid component placement"); errorMessage += GetErrorMessage( throws, settings != null && (string.IsNullOrEmpty(errorMessage) && (settings.OvenMaxTemp <= settings.OvenMinTemp || settings.OvenMaxTemp <= 0 || settings.OvenMinTemp <= 0 || settings.OvenHeatingRate <= 0 || settings.OvenCoolingRate <= 0)), "Invalid oven temperature settings" ); return(string.IsNullOrEmpty(errorMessage)); }
public void ValidateNullSettingsTest() { BiscuitMakerSettings settings = null; Action action = () => BiscuitMakerSettingsValidator.ValidateSettings(settings, true); action.Should().Throw <ArgumentException>().WithMessage("Settings can not be null"); }
/// <summary> /// The create. /// </summary> /// <param name="settings"> /// The settings. /// </param> /// <returns> /// The <see cref="BiscuitMakerObject"/>. /// </returns> public static BiscuitMakerObject Create(BiscuitMakerSettings settings = null) { var settingsAreValid = BiscuitMakerSettingsValidator.ValidateSettings(settings, false); if (!settingsAreValid) { return(null); } var components = new List <IBiscuitComponent>(); var switchComponent = Switch.Create(); components.Add(switchComponent); var switcher = new Switcher(); components.Add(switcher); if (settings != null) { var conveyor = Conveyor.Create(count: settings.ConveyorSize); components.Add(conveyor); } if (settings != null) { var oven = Oven.Create(settings.RoomTemperature); components.Add(oven); } var bucket = BiscuitBucket.Create(); components.Add(bucket); var motor = new Motor(); components.Add(motor); var timeRunner = new TimeRunner(); components.Add(timeRunner); var biscuitMaker = BiscuitMakerObject.Create(components, settings); biscuitMaker.FirstSwitcher.RaiseSwitchOn += OvenManager.HandleSwitchOn; biscuitMaker.FirstTimeRunner.RaiseClockTick += OvenManager.HandleClockTick; biscuitMaker.FirstTimeRunner.RaiseClockTick += biscuitMaker.FirstMotor.HandleClockTick; biscuitMaker.FirstMotor.RaisePulse += ConveyorManager.HandleMotorPulse; return(biscuitMaker); }
public void ValidateInvalidOvenTemperatureSettingsTest() { BiscuitMakerSettings settings = new BiscuitMakerSettings { ConveyorSize = 6, ExtruderIndex = 0, OvenCoolingRate = 10, OvenHeatingRate = 10, OvenIndex = 3, OvenMaxTemp = 220, OvenMinTemp = 240, OvenSize = 2, StamperIndex = 1, }; Action action = () => BiscuitMakerSettingsValidator.ValidateSettings(settings, true); action.Should().Throw <ArgumentException>().WithMessage("Invalid oven temperature settings"); }
public void ValidateValidSettingsTest() { var settings = new BiscuitMakerSettings { ConveyorSize = 6, ExtruderIndex = 0, OvenCoolingRate = 10, OvenHeatingRate = 10, OvenIndex = 3, OvenMaxTemp = 240, OvenMinTemp = 220, OvenSize = 2, StamperIndex = 1, }; Action action = () => BiscuitMakerSettingsValidator.ValidateSettings(settings); action.Should().NotThrow(); }
/// <summary> /// The load from config. /// </summary> /// <returns> /// The <see cref="BiscuitMakerSettings"/>. /// </returns> public static BiscuitMakerSettings LoadFromConfig() { var settings = new BiscuitMakerSettings(); var appSettings = ConfigurationManager.AppSettings; settings.ConveyorSize = int.Parse(appSettings["ConveyorSize"]); settings.OvenMaxTemp = int.Parse(appSettings["OvenMaxTemp"]); settings.OvenMinTemp = int.Parse(appSettings["OvenMinTemp"]); settings.OvenHeatingRate = int.Parse(appSettings["OvenHeatingRate"]); settings.OvenCoolingRate = int.Parse(appSettings["OvenCoolingRate"]); settings.ExtruderIndex = int.Parse(appSettings["ExtruderIndex"]); settings.StamperIndex = int.Parse(appSettings["StamperIndex"]); settings.OvenIndex = int.Parse(appSettings["OvenIndex"]); settings.OvenSize = int.Parse(appSettings["OvenSize"]); settings.RoomTemperature = int.Parse(appSettings["RoomTemperature"]); settings.RevolutionsPerTick = int.Parse(appSettings["RevolutionsPerTick"]); return(settings); }