public void ValidateRunTypeAnalysisGroupListWhenListIsNullOrEmpty(IEnumerable <CreateRunTypeAnalysisGroupModel> runTypeAnalysisGroups) { // Act (bool isValid, string errorMessage) = RunTypesValidations.ValidateRunTypeAnalysisGroupList(runTypeAnalysisGroups, _dummyAnalysisGroups); // Assert _ = isValid.Should().BeTrue(becauseArgs: null); _ = errorMessage.Should().BeEmpty(becauseArgs: null); }
public void ValidateRunTypeAnalysisGroupListVsAnalysisGroupsPass() { // Act (bool isValid, string errorMessage) = RunTypesValidations.ValidateRunTypeAnalysisGroupList(_dummyCreateRunTypeAnalysisGroupModels, _dummyAnalysisGroups); // Assert _ = isValid.Should().BeTrue(becauseArgs: null); _ = errorMessage.Should().Be("", becauseArgs: null); }
public void ValidateRunTypeAnalysisGroupListInvalidKPI(string passedInKPI, bool expectedtIsValid, string expectedErrorMessage) { // Arrange _dummyCreateRunTypeAnalysisGroupModels[0].KPI = passedInKPI; // Act (bool isValid, string errorMessage) = RunTypesValidations.ValidateRunTypeAnalysisGroupList(_dummyCreateRunTypeAnalysisGroupModels, _dummyAnalysisGroups); // Assert _ = isValid.Should().Be(expectedtIsValid, becauseArgs: null); _ = errorMessage.Should().Be(expectedErrorMessage, becauseArgs: null); }
public void ValidateRunTypeAnalysisGroupListVsAnalysisGroupsFail() { // Arrange var firstItem = _dummyCreateRunTypeAnalysisGroupModels.FirstOrDefault(); firstItem.AnalysisGroupId = 0; var expectedErrorMessage = $"Analysis group \"{firstItem.AnalysisGroupName}\" no longer exist"; // Act (bool isValid, string errorMessage) = RunTypesValidations.ValidateRunTypeAnalysisGroupList(_dummyCreateRunTypeAnalysisGroupModels, _dummyAnalysisGroups); // Assert _ = isValid.Should().BeFalse(becauseArgs: null); _ = errorMessage.Should().Be(expectedErrorMessage, becauseArgs: null); }
public IHttpActionResult Put(int id, [FromBody] CreateRunTypeModel command) { if (command is null || !ModelState.IsValid) { return(this.Error().InvalidParameters()); } var runType = _runTypeRepository.Get(id); if (runType is null) { return(this.Error().ResourceNotFound()); } (bool isValid, string message) = RunTypesValidations.ValidateRunTypeName(command.Name); if (!isValid) { return(this.Error().BadRequest(message)); } var runTypeByName = _runTypeRepository.FindByName(command.Name); if (runTypeByName != null && runTypeByName.Id != id) { return(this.Error().BadRequest("Run type name already exists: " + command.Name)); } (bool kpiIsValid, string kpiErrorMessage) = RunTypesValidations.ValidateDefaultKPIName(command.DefaultKPI); if (!kpiIsValid) { return(this.Error().BadRequest(kpiErrorMessage)); } var allAnalysisGroups = _analysisGroupRepository.GetAll(); (bool analysisGroupsIsValid, string errorMessage) = RunTypesValidations.ValidateRunTypeAnalysisGroupList(command.RunTypeAnalysisGroups, allAnalysisGroups); if (!analysisGroupsIsValid) { return(this.Error().BadRequest(errorMessage)); } _mapper.Map(command, runType); runType.ModifiedDate = DateTime.UtcNow; _runTypeRepository.Update(runType); _runTypeRepository.SaveChanges(); return(Ok(runType)); }