public void TestDateMetadataFieldCreateParamsDictionary() { var parameters = new DateMetadataFieldCreateParams(label) { Mandatory = true, DefaultValue = new DateTime(2018, 11, 5), ExternalId = externalId }; var dictionary = CheckParamsDictionary <DateMetadataFieldCreateParams, DateTime?>(parameters, "date", null); Assert.AreEqual("2018-11-05", dictionary["default_value"]); }
public void TestDateMetadataFieldCreateParamsCheck() { var parameters = new DateMetadataFieldCreateParams(null); DateTime?defaultValue = DateTime.MinValue; CheckMainFields(parameters, defaultValue); var validationParams = new MetadataValidationParams[] { new IntLessThanValidationParams(10), new IntGreaterThanValidationParams(10), new StringLengthValidationParams() }; AssertForbiddenValidations <DateMetadataFieldCreateParams, DateTime?>(parameters, validationParams); }
public void TestDateFieldDefaultValueValidation() { var todayDate = DateTime.Today.Date; var pastDate = todayDate.AddDays(-3); var yesterdayDate = todayDate.AddDays(-1); var futureDate = todayDate.AddDays(3); var validationRules = new List <MetadataValidationParams> { new DateGreaterThanValidationParams(pastDate), new DateLessThanValidationParams(todayDate) }; var lastThreeDaysValidation = new AndValidationParams(validationRules); // Test entering a metadata field with date validation and a valid default value. var validMetadataField = new DateMetadataFieldCreateParams(m_externalIdDateValidation) { ExternalId = m_externalIdDateValidation, DefaultValue = yesterdayDate, Validation = lastThreeDaysValidation }; var validMetadataFieldResult = m_cloudinary.AddMetadataField(validMetadataField); Assert.AreEqual(validMetadataField.DefaultValue.Value.ToString("yyyy-MM-dd"), validMetadataFieldResult.DefaultValue); Assert.NotNull(validMetadataFieldResult.Validation); Assert.AreEqual(validationRules.Count, validMetadataFieldResult.Validation.Rules.Count); // Test entering a metadata field with date validation and an invalid default value. var invalidMetadataField = new DateMetadataFieldCreateParams(m_externalIdDateValidation2) { ExternalId = m_externalIdDateValidation2, DefaultValue = futureDate, Validation = lastThreeDaysValidation }; var invalidMetadataFieldResult = m_cloudinary.AddMetadataField(invalidMetadataField); Assert.NotNull(invalidMetadataFieldResult.Error); }