コード例 #1
0
        public void ValidDeclaration_ReturnsFalse_IfFieldsNullOrEmpty(string ID, string defaultValue)
        {
            // Arrange
            var validator = new DeclarationValidator();
            var existing  = new List <Declaration>();

            // Act
            var valid = validator.Validate(existing, ID, defaultValue);

            // Assert
            Assert.IsFalse(valid);
        }
コード例 #2
0
        public void ValidDeclaration_ReturnsTrue_IfDeclarationIsValidAndNoExisting()
        {
            // Arrange
            var validator = new DeclarationValidator();
            var existing  = new List <Declaration>();

            // Act
            var valid = validator.Validate(existing, "1", "default");

            // Assert
            Assert.IsTrue(valid);
        }
コード例 #3
0
        public void ValidDeclaration_ReturnsFalse_IfIDNotUnique()
        {
            // Arrange
            var validator = new DeclarationValidator();
            var ID        = "1";
            var existing  = new List <Declaration>()
            {
                new Declaration(ID, "default 1")
            };

            // Act
            var valid = validator.Validate(existing, ID, "default 2");

            // Assert
            Assert.IsFalse(valid);
        }
コード例 #4
0
        public OperationResponse <bool> Post(EditDeclaration editDeclaration)
        {
            OperationResponse <bool> response = new OperationResponse <bool>();

            try
            {
                var newDeclaration          = editDeclaration.Declaration;
                DeclarationValidator obj    = new DeclarationValidator();
                ValidationResult     result = obj.Validate(newDeclaration);
                if (result.IsValid)
                {
                    var data = DeclarationBll.EditDeclaration(newDeclaration);

                    ReferenceDto reference = new ReferenceDto();
                    for (int i = 0; i < editDeclaration.ReferenceData.Length; i++)
                    {
                        reference.DeclarationId = newDeclaration.DeclarationId;
                        reference.ReferenceId   = editDeclaration.ReferenceData[i].ReferenceId;
                        reference.InvoiceDate   = editDeclaration.ReferenceData[i].InvoiceDate;
                        reference.Reference     = editDeclaration.ReferenceData[i].Reference;
                        reference.Type          = editDeclaration.ReferenceData[i].Type;
                        DeclarationBll.AddReference(reference);
                    }
                    response.OnSuccess(data, "Record Successfully Updated");
                    return(response);
                }
                else
                {
                    List <string> errors = new List <string>();
                    foreach (var err in result.Errors)
                    {
                        errors.Add(err.ErrorMessage);
                    }
                    response.OnError("one or more validations failed", errors);
                    return(response);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.Message + " " + e.StackTrace);
                response.OnException("Error in updating record");
                return(response);
            }
        }
コード例 #5
0
        public OperationResponse <bool> Post(AddDeclaration newDeclaration)
        {
            OperationResponse <bool> response = new OperationResponse <bool>();

            try
            {
                var declaration             = newDeclaration.Declaration;
                DeclarationValidator obj    = new DeclarationValidator();
                ValidationResult     result = obj.Validate(declaration);
                if (result.IsValid)
                {
                    var          data      = DeclarationBll.AddDeclaration(declaration);
                    var          id        = data;
                    ReferenceDto reference = new ReferenceDto();
                    for (int i = 0; i < newDeclaration.ReferenceData.Length; i++)
                    {
                        reference.DeclarationId = data;
                        reference.InvoiceDate   = newDeclaration.ReferenceData[i].InvoiceDate;
                        reference.Reference     = newDeclaration.ReferenceData[i].Reference;
                        reference.Type          = newDeclaration.ReferenceData[i].Type;
                        DeclarationBll.AddReference(reference);
                    }
                    response.OnSuccess(true, "Declaration Successfully added!");
                    return(response);
                }
                else
                {
                    List <string> error = new List <string>();
                    foreach (var err in result.Errors)
                    {
                        error.Add(err.ErrorMessage);
                    }
                    response.OnError("One or more validations failed", error);
                    return(response);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.Message + " " + e.StackTrace);
                response.OnException("Request to Add new declaration failed at server side.");
                return(response);
            }
        }