Пример #1
0
        public ActionResult Edit(int id)
        {
            var viewModel = _scenarioService.GetScenario(new GetScenarioRequest {
                Id = id
            }).MapTo <ScenarioViewModel>();

            return(View(viewModel));
        }
    /// <inheritdoc />
    public ConditionCheckResultModel Validate(StubModel stub)
    {
        var result   = new ConditionCheckResultModel();
        var state    = stub.Conditions?.Scenario?.ScenarioState;
        var scenario = stub.Scenario;

        if (string.IsNullOrWhiteSpace(state) || string.IsNullOrWhiteSpace(scenario))
        {
            return(result);
        }

        var scenarioState = _scenarioService.GetScenario(scenario);

        if (scenarioState == null)
        {
            scenarioState = new ScenarioStateModel(scenario);
            _scenarioService.SetScenario(scenario, scenarioState);
        }

        if (!string.Equals(scenarioState.State.Trim(), state.Trim(), StringComparison.OrdinalIgnoreCase))
        {
            result.Log =
                $"Scenario '{stub.Scenario}' is in state '{scenarioState.State}', but '{state}' was expected.";
            result.ConditionValidation = ConditionValidationType.Invalid;
        }
        else
        {
            result.ConditionValidation = ConditionValidationType.Valid;
        }

        return(result);
    }
Пример #3
0
    /// <inheritdoc />
    public Task <ScenarioStateModel> Handle(GetScenarioQuery request, CancellationToken cancellationToken)
    {
        var scenario = _scenarioService.GetScenario(request.Scenario);

        if (scenario == null)
        {
            throw new NotFoundException($"Scenario with name '{request.Scenario}'.");
        }

        return(Task.FromResult(scenario));
    }
Пример #4
0
        private ScenarioResultViewModel GetScenarioResultViewModel(int scenarioId)
        {
            var result = _outputConfigService.CalculateOputput(new CalculateOutputRequest {
                ScenarioId = scenarioId
            });
            var viewModel = result.MapTo <ScenarioResultViewModel>();

            viewModel.ScenarioName = _scenarioService.GetScenario(new GetScenarioRequest {
                Id = scenarioId
            }).Name;
            return(viewModel);
        }
Пример #5
0
    /// <inheritdoc />
    public Task <StubResponseWriterResultModel> WriteToResponseAsync(StubModel stub, ResponseModel response)
    {
        if (string.IsNullOrWhiteSpace(stub.Response.Scenario?.SetScenarioState) ||
            string.IsNullOrWhiteSpace(stub.Scenario))
        {
            return(Task.FromResult(StubResponseWriterResultModel.IsNotExecuted(GetType().Name)));
        }

        var scenario      = stub.Scenario;
        var scenarioState = _scenarioService.GetScenario(scenario) ?? new ScenarioStateModel(scenario);

        scenarioState.State = stub.Response.Scenario.SetScenarioState;
        _scenarioService.SetScenario(scenario, scenarioState);
        return(Task.FromResult(StubResponseWriterResultModel.IsExecuted(GetType().Name)));
    }
Пример #6
0
        private AssumptionDataInputViewModel GetAssumptionDataInputViewModel(int scenarioId)
        {
            var scenario = _scenarioService.GetScenario(new GetScenarioRequest {
                Id = scenarioId
            });
            var viewModel = new AssumptionDataInputViewModel();

            viewModel.Scenario = scenario.MapTo <AssumptionDataInputViewModel.ScenarioViewModel>();
            viewModel.KeyAssumptionCategories = _assumptionCategoryService.GetAssumptionCategories(new GetAssumptionCategoriesRequest {
                Take = -1, SortingDictionary = new Dictionary <string, SortOrder>(), IncludeAssumptionList = true
            })
                                                .AssumptionCategorys.MapTo <AssumptionDataInputViewModel.AssumptionCategoryViewModel>();
            viewModel.AssumptionDataList = _assumptionDataService.GetAssumptionDatas(new GetAssumptionDatasRequest
            {
                Take = -1,
                SortingDictionary = new SortedDictionary <string, SortOrder> {
                },
                ScenarioId        = scenarioId
            }).AssumptionDatas.MapTo <AssumptionDataInputViewModel.AssumptionDataViewModel>();

            return(viewModel);
        }
Пример #7
0
 public ActionResult <BaseResponse> GetScenario(Guid id)
 {
     return(_scenarioService.GetScenario(id)
            .GetActionResult <BusinessLogic.Model.Scenarios.Scenario, Scenario>(this));
 }