/// <summary> /// Запуск пасеки. /// </summary> private void Start() { this.apiary.Start(ApiaryXmlState.LoadState()); this.Refresh(RefreshApiaryVmOptions.ShowActualApiary); this.isWorking = true; this.RefreshCanExecuteCommands(); }
public void ApiaryXmlState_GetStandardConfig() { ApiaryXmlState.ClearCache(); ApiaryXmlState standardState = ApiaryXmlState.LoadState(); int workersInFirstBeehive = standardState .BeehiveStates.First(st => st.BeehiveNumber == 1) .WorkerBeesCount; Assert.AreEqual(30, workersInFirstBeehive); }
/// <summary> /// Создать тестовую модель представления пасеки. /// </summary> public ApiaryVmDesignMode() { Beehives = new ObservableCollection <IBeehiveVM>(new [] { new BeehiveVmDesignMode(1), new BeehiveVmDesignMode(2), new BeehiveVmDesignMode(3), new BeehiveVmDesignMode(4) }); this.StartCommand = new SimpleCommand(this.Start, this.CanStart); this.StopCommand = new SimpleCommand(this.Stop, this.CanStop); this.HarvestHoneyCommand = new SimpleCommand( this.HarvestHoney, this.CanHarvestHoney); this.RaisePropertyChanged(nameof(this.BeehivesCount)); this.RaisePropertyChanged(nameof(this.BeesCount)); this.state = ApiaryXmlState.LoadState(); }
/// <summary> /// Получить/выбрать состояние пасеки, в соответствии с которым /// будет обновляться view-модель пасеки. /// </summary> /// <param name="options">Опции обновления view-модели пасеки.</param> /// <returns>Состояние пасеки.</returns> private IApiaryState GetStateForRefresh(RefreshApiaryVmOptions options) { IApiaryState result; switch (options) { case RefreshApiaryVmOptions.ShowActualApiary: result = this.apiary; break; case RefreshApiaryVmOptions.ShowTempSavedState: result = ApiaryXmlState.LoadState(); break; default: throw new ArgumentOutOfRangeException( nameof(options), "Передано непредусмотренное значение опций обновления view-модели пасеки"); } return(result); }
public void ApiaryXmlState_ClearCache() { ApiaryXmlState state = ApiaryXmlState.LoadState(); int randomValue = new Random().Next(1, 1000); state.BeehiveStates.First(st => st.BeehiveNumber == 1) .WorkerBeesCount = randomValue; state.SaveInCache(); ApiaryXmlState.ClearCache(); ApiaryXmlState standardState = ApiaryXmlState.LoadState(); int workersInFirstBeehive = standardState .BeehiveStates.First(st => st.BeehiveNumber == 1) .WorkerBeesCount; Assert.AreNotEqual(randomValue, workersInFirstBeehive); }
public void ApiaryXmlState_SaveState() { ApiaryXmlState beforeUpdating = ApiaryXmlState.LoadState(); int randomValue = new Random().Next(1, 1000); beforeUpdating.BeehiveStates.First(st => st.BeehiveNumber == 1) .WorkerBeesCount = randomValue; beforeUpdating.SaveInCache(); ApiaryXmlState afterUpdating = ApiaryXmlState.LoadState(); int workersInFirstBeehive = afterUpdating .BeehiveStates.First(st => st.BeehiveNumber == 1) .WorkerBeesCount; Assert.AreEqual(randomValue, workersInFirstBeehive); ApiaryXmlState.ClearCache(); }