public void ValidationConstraintTests_FindMoreChildrenThanExpected()
        {
            //find two, only except max of 1
            var constraint = new ValidationConstraint <TestSerialization>("v", JTokenType.Array, true, 2, 1,
                                                                          (s, p) => p.Version = s.ToObject <int[]>());

            Assert.Throws <DistributedTraceAcceptPayloadParseException>(() => constraint.ParseAndThrowOnFailure(JsonObject, new TestSerialization()));
        }
        public void ValidationConstraintTests_ParseOptionalBoolean()
        {
            var testInstance = new TestSerialization();
            var constraint   = new ValidationConstraint <TestSerialization>("b", JTokenType.Boolean, false, 0, 0,
                                                                            (s, p) => p.BoolField = s.ToObject <bool>());

            testInstance.BoolField = true;
            constraint.ParseAndThrowOnFailure(JsonObject, testInstance);
            Assert.AreEqual(false, testInstance.BoolField);
        }
        public void ValidationConstraintTests_ParseOptionalFloat()
        {
            var testInstance = new TestSerialization();
            var constraint   = new ValidationConstraint <TestSerialization>("f", JTokenType.Float, false, 0, 0,
                                                                            (s, p) => p.FloatField = s.ToObject <float>());

            testInstance.FloatField = 42.42f;
            constraint.ParseAndThrowOnFailure(JsonObject, testInstance);
            Assert.AreEqual(0.666f, testInstance.FloatField);
        }
        public void ValidationConstraintTests_ParseOptionalString()
        {
            var testInstance = new TestSerialization();
            var constraint   = new ValidationConstraint <TestSerialization>("s", JTokenType.String, false, 0, 0,
                                                                            (s, p) => p.StringField = s.ToObject <string>());

            testInstance.StringField = null;
            constraint.ParseAndThrowOnFailure(JsonObject, testInstance);
            Assert.IsNotNull(testInstance.StringField);
            Assert.AreEqual("string value", testInstance.StringField);
        }
        public void ValidationConstraintTests_ParseOptionalVersion()
        {
            var testInstance = new TestSerialization();
            var constraint   = new ValidationConstraint <TestSerialization>("v", JTokenType.Array, false, 2, 2,
                                                                            (s, p) => p.Version = s.ToObject <int[]>());

            testInstance.Version = new[] { 42, 42 };

            constraint.ParseAndThrowOnFailure(JsonObject, testInstance);
            Assert.IsNotNull(testInstance.Version);
            Assert.AreEqual(1, testInstance.Version[0]);
            Assert.AreEqual(0, testInstance.Version[1]);
        }
        public void ValidationConstraintTests_ParseRequiredVersion()
        {
            var testInstance = new TestSerialization();

            var constraint = new ValidationConstraint <TestSerialization>(path: "v", type: JTokenType.Array, isRequired: true,
                                                                          miniumChildren: 2, maximumChildren: 2, parse: (s, p) => p.Version = s.ToObject <int[]>());

            testInstance.Version = new[] { 42, 42 };
            constraint.ParseAndThrowOnFailure(JsonObject, testInstance);
            Assert.IsNotNull(testInstance.Version);
            Assert.AreEqual(1, testInstance.Version[0]);
            Assert.AreEqual(0, testInstance.Version[1]);
        }
        public void ValidationConstraints_CheckThatArgumentsProperlyParsed()
        {
            var newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.Equal,
                ObjectType = _typeOfAssetEditable,
                Property = "Id",
                PropertyType = _typeOfInt,
                MainArgument = "1"
            };
            TrySaveAndSucceed(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.Equal,
                ObjectType = _typeOfAssetEditable,
                Property = "Id",
                PropertyType = _typeOfInt,
                MainArgument = "NotAnInt"
            };
            TrySaveAndFail(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.Between,
                ObjectType = _typeOfAssetEditable,
                Property = "Id",
                PropertyType = _typeOfInt,
                MainArgument = "1",
                SecondaryArgument = "2"
            };
            TrySaveAndSucceed(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.Between,
                ObjectType = _typeOfAssetEditable,
                Property = "Id",
                PropertyType = _typeOfInt,
                MainArgument = "1",
                SecondaryArgument = "NotAnInt"
            };
            TrySaveAndFail(newConstraint);
        }
        public void ValidationConstraints_Validate()
        {
            const string errorMessage = "The object should not have been saved given its constraints";
            var transac = SessionManagement.Db.StartTransaction();
            IList<ValidationConstraint> testConstraints = new List<ValidationConstraint>();
            try
            {
                var accor = SessionManagement.Db.Linq<AssetEditable>(true).SingleOrDefault(a => a.Name == "ACCOR");
                var total = SessionManagement.Db.Linq<AssetEditable>(true).SingleOrDefault(a => a.Name == "TOTAL");
                Assert.IsNotNull(total);
                var nameConstraint = new ValidationConstraint
                {
                    ConstraintType = trkValidationConstraintType.Equal,
                    ObjectType = _typeOfAssetEditable,
                    Property = "Name",
                    PropertyType = _typeOfString,
                    MainArgument = "ACCOR"
                };
                testConstraints.Add(nameConstraint);
                var savedNameConstraint = ValidationConstraintService.Instance.SaveOrUpdateList(testConstraints).SingleOrDefault();
                //Should succeed
                ValidationConstraintService.Instance.ValidateObject(accor);
                //Should fail
                try
                {
                    ValidationConstraintService.Instance.ValidateObject(total);
                    Assert.Fail(errorMessage);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }

                //Second Level
                var idConstraint1 = new ValidationConstraint
                {
                    ConstraintType = trkValidationConstraintType.Greater,
                    ObjectType = _typeOfAssetEditable,
                    Property = "Id",
                    PropertyType = _typeOfString,
                    MainArgument = "0",
                    ParentConstraint = savedNameConstraint
                };
                testConstraints.Add(idConstraint1);
                ValidationConstraintService.Instance.SaveOrUpdateList(testConstraints);
                //Should succeed
                ValidationConstraintService.Instance.ValidateObject(accor);

                //Should Fail (Id = 122)
                var idConstraint2 = new ValidationConstraint
                {
                    ConstraintType = trkValidationConstraintType.Lower,
                    ObjectType = _typeOfAssetEditable,
                    Property = "Id",
                    PropertyType = _typeOfString,
                    MainArgument = "30",
                    ParentConstraint = savedNameConstraint
                };
                testConstraints.Add(idConstraint2);
                testConstraints = ValidationConstraintService.Instance.SaveOrUpdateList(testConstraints);
                try
                {
                    ValidationConstraintService.Instance.ValidateObject(accor);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }

                //Remove it now that it has been tested
                testConstraints.ForEach(c =>
                {
                    if (c == idConstraint2)
                        c.RequiresDeletion = true;
                });

                var handlingQuotesConstraint = new ValidationConstraint
                {
                    ConstraintType = trkValidationConstraintType.True,
                    ObjectType = _typeOfAssetEditable,
                    Property = "HandlingQuotes",
                    PropertyType = _typeOfBool,
                    ParentConstraint = savedNameConstraint
                };
                testConstraints.Add(handlingQuotesConstraint);
                var thirdLevel = ValidationConstraintService.Instance.SaveOrUpdateList(testConstraints).SingleOrDefault(c => c.ToString() == handlingQuotesConstraint.ToString());
                //Should succeed
                ValidationConstraintService.Instance.ValidateObject(accor);

                var betweenConstraint = new ValidationConstraint
                {
                    ConstraintType = trkValidationConstraintType.Between,
                    ObjectType = _typeOfAssetEditable,
                    Property = "Id",
                    PropertyType = _typeOfInt,
                    MainArgument = "0",
                    SecondaryArgument = "100000000",
                    ParentConstraint = thirdLevel
                };
                testConstraints.Add(betweenConstraint);
                ValidationConstraintService.Instance.SaveOrUpdateList(testConstraints);
                //Should succeed
                ValidationConstraintService.Instance.ValidateObject(accor);

                var notNullConstraint = new ValidationConstraint
                {
                    ConstraintType = trkValidationConstraintType.NotNull,
                    ObjectType = _typeOfAssetEditable,
                    Property = "Status",
                    PropertyType = _typeOfAssetStatus,
                    ParentConstraint = thirdLevel
                };
                testConstraints.Add(notNullConstraint);
                ValidationConstraintService.Instance.SaveOrUpdateList(testConstraints);

                //Should succeed
                ValidationConstraintService.Instance.ValidateObject(accor);

                var differentConstraint = new ValidationConstraint
                {
                    ConstraintType = trkValidationConstraintType.Different,
                    ObjectType = _typeOfAssetEditable,
                    Property = "Id",
                    PropertyType = _typeOfInt,
                    MainArgument = "1",
                    ParentConstraint = thirdLevel
                };

                testConstraints.Add(differentConstraint);
                ValidationConstraintService.Instance.SaveOrUpdateList(testConstraints);
                //Should succeed
                ValidationConstraintService.Instance.ValidateObject(accor);

                var nullConstraint = new ValidationConstraint
                {
                    ConstraintType = trkValidationConstraintType.Null,
                    ObjectType = _typeOfAssetEditable,
                    Property = "AssetType",
                    PropertyType = _typeOfAssetType,
                    ParentConstraint = thirdLevel
                };
                testConstraints.Add(nullConstraint);
                ValidationConstraintService.Instance.SaveOrUpdateList(testConstraints);
                try
                {
                    //Should fail.
                    ValidationConstraintService.Instance.ValidateObject(accor);
                    Assert.Fail(errorMessage);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
                //If you want to add constraint remove the top one from the list.
            }
            finally
            {
                SessionManagement.Db.RollbackTrans(transac);
            }
        }
 public void ValidationConstraints_Update()
 {
     var constraintsToSave = new List<ValidationConstraint>();
     var newConstraint = new ValidationConstraint
     {
         ConstraintType = trkValidationConstraintType.False,
         ObjectType = _typeOfAssetEditable,
         Property = "HandlingQuotes",
         PropertyType = _typeOfBool,
     };
     constraintsToSave.Add(newConstraint);
     var savedItem = ValidationConstraintService.Instance.SaveOrUpdateList(constraintsToSave).Single();
     constraintsToSave.Clear();
     savedItem.ConstraintType = trkValidationConstraintType.True;
     constraintsToSave.Add(savedItem);
     savedItem = ValidationConstraintService.Instance.SaveOrUpdateList(constraintsToSave).Single();
     constraintsToSave.Clear();
     Assert.AreEqual(savedItem.ConstraintType, trkValidationConstraintType.True);
     savedItem.RequiresDeletion = true;
     constraintsToSave.Add(newConstraint);
     ValidationConstraintService.Instance.SaveOrUpdateList(constraintsToSave);
     Assert.IsNull(ValidationConstraintService.Instance.GetValidationConstraintById(savedItem.Id));
 }
        public void ValidationConstraints_SecondGreaterThanMainArgument()
        {
            var newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.Between,
                ObjectType = _typeOfAssetEditable,
                Property = "Id",
                PropertyType = _typeOfInt,
                MainArgument = "1",
                SecondaryArgument = "2"
            };
            TrySaveAndSucceed(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.Between,
                ObjectType = _typeOfAssetEditable,
                Property = "Id",
                PropertyType = _typeOfInt,
                MainArgument = "1",
                SecondaryArgument = "0"
            };
            TrySaveAndFail(newConstraint);
        }
 public ValidationException(ValidationConstraint constraint, PropertyInfo prop)
     : base(prop.ToString())
 {
     ValidationConstraint = constraint;
     Property = prop;
 }
 public ValidationException(ValidationConstraint constraint, string msg)
     : base(msg)
 {
     ValidationConstraint = constraint;
 }
        public void ValidationConstraints_DeleteParentFails()
        {
            var transaction = SessionManagement.Db.StartTransaction();
            try
            {
                //Check that a validation constraint cannot reference itself
                var parentConstraint = new ValidationConstraint
                {
                    ConstraintType = trkValidationConstraintType.NotNull,
                    ObjectType = _typeOfAssetEditable,
                    Property = "Id",
                    PropertyType = _typeOfInt,
                };

                var childConstraint = new ValidationConstraint
                {
                    ConstraintType = trkValidationConstraintType.NotNull,
                    ObjectType = _typeOfAssetEditable,
                    Property = "Code",
                    PropertyType = _typeOfString,
                };

                var constraintsToSave = new List<ValidationConstraint> { parentConstraint, childConstraint };
                var savedConstraints = ValidationConstraintService.Instance.SaveOrUpdateList(constraintsToSave);
                Assert.IsNotNull(savedConstraints);
                savedConstraints[1].ParentConstraint = savedConstraints[0];
                savedConstraints = ValidationConstraintService.Instance.SaveOrUpdateList(constraintsToSave);
                savedConstraints[0].RequiresDeletion = true;
                TrySaveAndFail(savedConstraints);
            }
            finally
            {
                SessionManagement.Db.RollbackTrans(transaction);
            }
        }
 public ValidateAttribute(ValidationConstraint constraint, string errorMsg)
 {
     _validationConstraint = constraint;
     _errorMsg = errorMsg;
 }
 public ValidateAttribute(ValidationConstraint constraint)
 {
     _validationConstraint = constraint;
 }
        public void ValidationConstraints_Save()
        {
            var newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.NotNull,
                ObjectType = _typeOfAssetEditable,
                Property = "Code",
                PropertyType = _typeOfString
            };
            TrySaveAndSucceed(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.Null,
                ObjectType = _typeOfAssetEditable,
                Property = "Code",
                PropertyType = _typeOfString
            };
            TrySaveAndSucceed(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.NotNull,
                ObjectType = _typeOfAssetEditable,
                Property = "Status",
                PropertyType = _typeOfAssetStatus
            };
            TrySaveAndSucceed(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.Null,
                ObjectType = _typeOfAssetEditable,
                Property = "Status",
                PropertyType = _typeOfAssetStatus
            };
            TrySaveAndSucceed(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.Equal,
                ObjectType = _typeOfAssetEditable,
                Property = "Id",
                PropertyType = _typeOfInt,
                MainArgument = "1"
            };
            TrySaveAndSucceed(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.Different,
                ObjectType = _typeOfAssetEditable,
                Property = "Id",
                PropertyType = _typeOfInt,
                MainArgument = "1"
            };
            TrySaveAndSucceed(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.Greater,
                ObjectType = _typeOfAssetEditable,
                Property = "Id",
                PropertyType = _typeOfInt,
                MainArgument = "1"
            };
            TrySaveAndSucceed(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.Lower,
                ObjectType = _typeOfAssetEditable,
                Property = "Id",
                PropertyType = _typeOfInt,
                MainArgument = "1"
            };
            TrySaveAndSucceed(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.True,
                ObjectType = _typeOfAssetEditable,
                Property = "HandlingQuotes",
                PropertyType = _typeOfBool,
            };
            TrySaveAndSucceed(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.False,
                ObjectType = _typeOfAssetEditable,
                Property = "HandlingQuotes",
                PropertyType = _typeOfBool,
            };
            TrySaveAndSucceed(newConstraint);
        }
 private static void TrySaveAndSucceed(ValidationConstraint constraintsToSave)
 {
     var constraintsList = new List<ValidationConstraint> { constraintsToSave };
     TrySaveAndSucceed(constraintsList);
 }
        public void ValidationConstraints_SaveFailed()
        {
            var newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.False,
                ObjectType = _typeOfAssetEditable,
                Property = "Status",
                PropertyType = _typeOfAssetStatus
            };
            TrySaveAndFail(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.True,
                ObjectType = _typeOfAssetEditable,
                Property = "Status",
                PropertyType = _typeOfAssetStatus
            };
            TrySaveAndFail(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.Greater,
                ObjectType = _typeOfAssetEditable,
                Property = "Status",
                PropertyType = _typeOfAssetStatus
            };
            TrySaveAndFail(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.Lower,
                ObjectType = _typeOfAssetEditable,
                Property = "Status",
                PropertyType = _typeOfAssetStatus
            };
            TrySaveAndFail(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.Between,
                ObjectType = _typeOfAssetEditable,
                Property = "Status",
                PropertyType = _typeOfAssetStatus
            };
            TrySaveAndFail(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.Equal,
                ObjectType = _typeOfAssetEditable,
                Property = "Status",
                PropertyType = _typeOfAssetStatus
            };
            TrySaveAndFail(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.True,
                ObjectType = _typeOfAssetEditable,
                Property = "Code",
                PropertyType = _typeOfString
            };
            TrySaveAndFail(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.False,
                ObjectType = _typeOfAssetEditable,
                Property = "Code",
                PropertyType = _typeOfString
            };
            TrySaveAndFail(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.False,
                ObjectType = _typeOfAssetEditable,
                Property = "UnknownProperty",
                PropertyType = _typeOfString
            };
            TrySaveAndFail(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.Between,
                ObjectType = _typeOfAssetEditable,
                Property = "Id",
                PropertyType = _typeOfInt,
                MainArgument = "1"
            };
            TrySaveAndFail(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.Between,
                ObjectType = _typeOfAssetEditable,
                Property = "Id",
                PropertyType = _typeOfInt,
                SecondaryArgument = "1"
            };
            TrySaveAndFail(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.NotNull,
                ObjectType = _typeOfAssetEditable,
                Property = "Id",
                PropertyType = _typeOfInt,
                SecondaryArgument = "1"
            };
            TrySaveAndFail(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.Null,
                ObjectType = _typeOfAssetEditable,
                Property = "Id",
                PropertyType = _typeOfInt,
                SecondaryArgument = "1"
            };
            TrySaveAndFail(newConstraint);

            newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.NotNull,
                ObjectType = _typeOfAssetEditable,
                Property = "Id",
                PropertyType = "RandomTypeThatDoesNotExist",
            };
            TrySaveAndFail(newConstraint);
        }
Пример #19
0
        public async Task <CustomerValidationResponse> GetCustomers(int page)
        {
            Debug.WriteLine($"Beginning {nameof(GetCustomers)} - Page {page}");
            Uri uri = new Uri($"https://backend-challenge-winter-2017.herokuapp.com/customers.json?page={page}", UriKind.Absolute);
            HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, uri);

            Debug.WriteLine("Sending request ...");
            HttpResponseMessage response = await m_client.SendAsync(requestMessage);

            Debug.WriteLine("Request recieved");

            // If there was an error, return early with the error
            if (!response.IsSuccessStatusCode)
            {
                Debug.WriteLine("The response status code is not valid");
                return(null);
            }

            string responseAsString = await response.Content.ReadAsStringAsync();

            var jsonObject = JObject.Parse(responseAsString);
            //Debug.WriteLine(jsonObject.ToString());

            // Parse Validations
            //Debug.WriteLine(jsonObject["validations"].ToString());
            var validationResults         = JsonConvert.DeserializeObject <List <JObject> >(jsonObject["validations"].ToString());
            List <Validation> validations = new List <Validation>();

            foreach (var item in validationResults)
            {
                foreach (var property in item)
                {
                    // Parse the Validation Constraints
                    //Debug.WriteLine(property.Value);
                    ValidationConstraint constraint = new ValidationConstraint();

                    // Get the required if it exists
                    var requiredToken = property.Value.SelectToken("required");
                    if (requiredToken != null)
                    {
                        if (bool.TryParse(requiredToken.ToString(), out bool b))
                        {
                            constraint.Required = b;
                            //Console.WriteLine($"{property.Key} | {requiredToken.ToString()} | {b} | {constraint.Required}");
                        }
                    }

                    // Get the Type if it exists
                    var typeToken = property.Value.SelectToken("type");
                    if (typeToken != null)
                    {
                        constraint.Type = typeToken.ToString();
                    }

                    // Get the length if it exists
                    var lengthToken = property.Value.SelectToken("length");
                    if (lengthToken != null)
                    {
                        // Assume to be string
                        constraint.Type = "string";

                        // Get the Min Token
                        var minToken = lengthToken.SelectToken("min");
                        if (minToken != null)
                        {
                            if (int.TryParse(minToken.ToString(), out int min))
                            {
                                constraint.Length.Min = min;
                            }
                        }

                        // Get the Max Token
                        var maxToken = lengthToken.SelectToken("max");
                        if (maxToken != null)
                        {
                            if (int.TryParse(maxToken.ToString(), out int max))
                            {
                                constraint.Length.Max = max;
                            }
                        }
                    }

                    // Add the Validation to the list
                    validations.Add(new Validation(property.Key, constraint));
                }
            }

            // Parse Customers
            //Debug.WriteLine(jsonObject["customers"].ToString());
            var             customerResults = JsonConvert.DeserializeObject <List <JObject> >(jsonObject["customers"].ToString());
            List <Customer> customers       = new List <Customer>();

            foreach (var item in customerResults)
            {
                Customer customer = new Customer();
                customer.id      = item.GetValue("id").ToObject <int>();
                customer.name    = item.GetValue("name").ToObject <string>();
                customer.email   = item.GetValue("email").ToObject <string>();
                customer.country = item.GetValue("country").ToObject <string>();

                // Get the age. Prevent Json.net from converting types
                if (item.GetValue("age").Type == JTokenType.Null)
                {
                    customer.age = null;
                }
                else if (item.GetValue("age").Type == JTokenType.String)
                {
                    customer.age = -1;
                }
                else
                {
                    customer.age = item.GetValue("age").ToObject <int?>();
                }
                //Debug.WriteLine(item.GetValue("age").Type);
                //Debug.WriteLine(customer.age);

                // Get newsletter. Prevent Json.net from converting types
                if (item.GetValue("newsletter").Type == JTokenType.Null)
                {
                    customer.newsletter = null;
                }
                else if (item.GetValue("newsletter").Type == JTokenType.String)
                {
                    customer.newsletter = null;
                }
                else
                {
                    customer.newsletter = item.GetValue("newsletter").ToObject <bool?>();
                }
                //Debug.WriteLine(customer.newsletter);
                //Debug.WriteLine(item.GetValue("newsletter").Type);

                //Debug.WriteLine(item.ToString());
                customers.Add(customer);
            }

            // Parse Paginations
            //Debug.WriteLine(jsonObject["pagination"].ToString());
            var        paginationResults = JsonConvert.DeserializeObject <JObject>(jsonObject["pagination"].ToString());
            Pagination pagination        = new Pagination(paginationResults["current_page"].Value <int>(), paginationResults["per_page"].Value <int>(), paginationResults["total"].Value <int>());
            //Debug.WriteLine(pagination.ToString());

            CustomerValidationResponse returnedResponse = new CustomerValidationResponse();

            returnedResponse.Validations = validations;
            returnedResponse.Customers   = customers;
            returnedResponse.Pagination  = pagination;
            return(returnedResponse);
        }
        public void ValidationConstraints_SaveItselfAsParentFails()
        {
            //Check that a validation constraint cannot reference itself
            var newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.NotNull,
                ObjectType = _typeOfAssetEditable,
                Property = "Id",
                PropertyType = _typeOfInt,
            };

            var constraintsToSave = new List<ValidationConstraint> { newConstraint };
            var savedConstraint = ValidationConstraintService.Instance.SaveOrUpdateList(constraintsToSave).SingleOrDefault();
            Assert.IsNotNull(savedConstraint);
            constraintsToSave.Clear();
            savedConstraint.ParentConstraint = savedConstraint;
            TrySaveAndFail(newConstraint);

            //Finally delete the constraint that had to be saved.
            savedConstraint.RequiresDeletion = true;
            constraintsToSave.Add(newConstraint);
            ValidationConstraintService.Instance.SaveOrUpdateList(constraintsToSave);
            Assert.IsNull(ValidationConstraintService.Instance.GetValidationConstraintById(savedConstraint.Id));
            constraintsToSave.Clear();
        }
 public ValidationException(ValidationConstraint constraint, string msg, bool isBoxerpValidation)
     : base(msg)
 {
     ValidationConstraint = constraint;
     _isBoxerpValidationAttribute = isBoxerpValidation;
 }
        public void ValidationConstraints_SaveSomeConstraints()
        {
            var portfolioType = new PortfolioEditable().GetType().AssemblyQualifiedName;
            var userInfoType = new UserInfo().GetType().AssemblyQualifiedName;

            var newConstraint = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.NotNull,
                ObjectType = portfolioType,
                Property = "Comment",
                PropertyType = portfolioType
            };
            var newConstraint2 = new ValidationConstraint
            {
                ConstraintType = trkValidationConstraintType.NotNull,
                ObjectType = portfolioType,
                Property = "Manager",
                PropertyType = userInfoType
            };

            var constraintsToSave = new List<ValidationConstraint> { newConstraint, newConstraint2 };
            ValidationConstraintService.Instance.SaveOrUpdateList(constraintsToSave);
        }
 public ValidationException(ValidationConstraint constraint, PropertyInfo prop, string msg)
     : base(msg)
 {
     ValidationConstraint = constraint;
     Property = prop;
 }
        public RuntimeProperties(ServiceConfigParameters ConfigParameters)
        {
            _ServiceConfigParameters = ConfigParameters;
            //personal
            _Staff_ID = new StaffID();
            _Full_Name = new FullName();
            _Country = new Country();
            _ContractType = new ContractType();
            _ContractTypeForReports = new ContractTypeForReports();
            _Position = new Position();
            _DateOfTREnd = new DateOfTREnd();
            _DateOfTRStart = new DateOfTRStart();
            _DateOfEntrance = new DateOfEntrance();
            _CalendarName = new CalendarName();
            _TemplateFilter = new TemplateFilter();
            _ArePropReadyPersonal = new ArePropReady();
            _BusinessUnitInfo = new BusinessUnitInfo();
            _PMSA = new PMSA();
            _PMSAItem = new PMSAItem();
            _Gender = new Gender();
            _ActivityCodeInfo = new ActivityCodeInfo();
            _OfficialLS = new OfficialLS();
            _PhoneDirOnly = new PhoneDirOnly();
            //update
            _SelectedDate = new SelectedDate();
            _SelectedDateStatus = new SelectedDateStatus();
            _SelectedDateTransactionStatus = new SelectedDateTransactionStatus();
            _SelectedDateType = new SelectedDateType();
            _SelectedDateisOptional = new SelectedDateisOptional();
            _PercentPerDay = new PercentPerDay();
            _SelectedJob = new SelectedJob();
            _MaxHoursDaily = new MaxHoursDaily();
            _ArePropReadyTRUpdate = new ArePropReady();
            _TRInputListClient = new TRInputListClient();
            _LastOpenDay = new LastOpenDay();

            //submit
            _SumOfHours = new SumOfHours();
            _TRInputList = new TRInputList();
            _WorkingHoursWeekly = new WorkingHoursWeekly();
            _MinHoursDaily = new MinHoursDaily();
            _FirstSubmitableDay = new FirstSubmitableDay();
            _SelectedActivityCode = new SelectedActivityCode();
            _Description = new Description();
            _Location = new Location();
            _BusinessUnit = new BusinessUnit();
            _ReasonCode = new ReasonCode();
            _ArePropReadyTRSubmit = new ArePropReady();
            _PeriodEnd = new PeriodEnd();
            //reports

            _PeriodStarting = new PeriodStarting();
            _ArePropReadyReports = new ArePropReady();
            _ReportIntervalFrom = new ReportIntervalFrom();
            _ReportIntervalTo = new ReportIntervalTo();
            _UserIDList = new UserIDList();
            _SelectedReportTemplate = new SelectedReportTemplate();
            _SelectedReportType = new SelectedReportType();

            //külön queryk-ben/Getparameters-ben kap értéket

            _LastSubmittedDay = new LastSubmittedDay();
            _JobCh = new JobCH();
            _InsertedHour = new InstertedHour();
            _ValidationConstraint = new ValidationConstraint();
            _JobFilter = new JobFilter();
            _ActivityCodeFilter = new ActivityCodeFilter();
            _UserGroup = new UserGroup();
            _ReasonCodeFilter = new ReasonCodeFilter();
        }