public void TryValidateObject_on_valid_parent_returns_no_errors()
        {
            var parent = new Parent {
                PropertyA = 1, PropertyB = 1
            };
            var validationResults = new List <ValidationResult>();

            var result = _validator.TryValidateObject(parent, validationResults);

            Assert.IsTrue(result);
            Assert.AreEqual(0, validationResults.Count);
        }
        public void TryValidateObject_on_valid_parent_returns_no_errors()
        {
            // Arrange
            var parent = new Parent
            {
                PropertyA = 1,
                PropertyB = 1
            };

            // Act
            var result = _validator.TryValidateObject(parent, out var validationResults);

            // Assert
            Assert.IsTrue(result);
            Assert.AreEqual(0, validationResults.Count);
        }
Esempio n. 3
0
        /// <summary>
        ///  Retrieves triangle vertice information
        /// </summary>
        /// <param name="taskId">Task identification</param>
        /// <param name="bLTriangleModel">Business layer triangle model that contains the  row and column information</param>
        /// <param name="cancellationToken">Cancellation token to cancel operation</param>
        /// <returns>Business layer result model that contains if the operation was successful
        /// and the triangle vertice information</returns>
        public IBLResultBase TriangleCalculateVerices(long taskId
                                                      , IBLTriangleModel bLTriangleModel
                                                      , CancellationToken?cancellationToken = null)
        {
            IBLResultBase resultBase = new BLResultBase();

            resultBase.ResultOperation = ResultOperationEnums.TriangleCalulateVertices;
            resultBase.Errors          = new List <string>();

            // Verify
            var validateResults = new List <ValidationResult>();
            var res             = _dataAnnotationsValidator.TryValidateObject(bLTriangleModel, validateResults);

            if (res)
            {
                var blModels = new List <IBLModel>();
                var dlRow    = _mapper.Map <DLRowModel>(bLTriangleModel);
                var dlColumn = _mapper.Map <DLColumnModel>(bLTriangleModel);
                var vertices = _dLWebApiTriangle.TriangleVertices(dlRow, dlColumn);
                if (vertices != null)
                {
                    blModels.AddRange(vertices.Select(vertice => _mapper.Map <BLTriangleVerticeModel>(vertice as DLTriangleVerticeModel)));
                }
                resultBase.ResultContent = blModels;
                if (blModels.Any())
                {
                    resultBase.ResultSuccess = true;
                }
                else
                {
                    resultBase.ResultSuccess = false;
                    resultBase.Errors.Add($"No vertices found for row = {bLTriangleModel.Row}, column = {bLTriangleModel.Column}");
                }
            }
            else
            {
                resultBase.HasErrors     = true;
                resultBase.ResultSuccess = false;

                resultBase.Errors.Add(validateResults[0].ErrorMessage);
            }
            return(resultBase);
        }