Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public void ValidateDefaultKPIName(string passedInKPI, bool expectedtIsValid, string expectedErrorMessage)
        {
            // Act
            (bool isValid, string errorMessage) = RunTypesValidations.ValidateDefaultKPIName(passedInKPI);

            // Assert
            _ = isValid.Should().Be(expectedtIsValid, becauseArgs: null);
            _ = errorMessage.Should().Be(expectedErrorMessage, becauseArgs: null);
        }
Exemplo n.º 3
0
        public void EmptyNameInvalid(string passedInName)
        {
            // Act
            (bool isValid, string errorMessage) = RunTypesValidations.ValidateRunTypeName(passedInName);

            // Assert
            _ = isValid.Should().BeFalse(becauseArgs: null);
            _ = errorMessage.Should().Be("Name cannot be empty", becauseArgs: null);
        }
Exemplo n.º 4
0
        public void ValidateRunTypeAnalysisGroupListVsAnalysisGroupsPass()
        {
            // Act
            (bool isValid, string errorMessage) = RunTypesValidations.ValidateRunTypeAnalysisGroupList(_dummyCreateRunTypeAnalysisGroupModels, _dummyAnalysisGroups);

            // Assert
            _ = isValid.Should().BeTrue(becauseArgs: null);
            _ = errorMessage.Should().Be("", becauseArgs: null);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        public void ValidateDuplicatePairs()
        {
            // Arrange
            _dummyCreateRunTypeAnalysisGroupModels[1].AnalysisGroupId   = _dummyCreateRunTypeAnalysisGroupModels[2].AnalysisGroupId;
            _dummyCreateRunTypeAnalysisGroupModels[1].AnalysisGroupName = _dummyCreateRunTypeAnalysisGroupModels[2].AnalysisGroupName;
            string expectedErrorMessage =
                $"There are duplicate Analysis Group and KPI combinations: {_dummyCreateRunTypeAnalysisGroupModels[2].AnalysisGroupName} - {_dummyCreateRunTypeAnalysisGroupModels[2].KPI}";

            // Act
            (bool isValid, string errorMessage) = RunTypesValidations.ValidateDuplicateAnalysisGroupAndKPIPairs(_dummyCreateRunTypeAnalysisGroupModels);

            // Assert
            _ = isValid.Should().BeFalse(becauseArgs: null);
            _ = errorMessage.Should().Be(expectedErrorMessage, becauseArgs: null);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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));
        }