From 1463c09ffb1c0177884121b3af841366c5f83a98 Mon Sep 17 00:00:00 2001 From: Mihail Date: Fri, 23 Jan 2026 11:05:36 +0100 Subject: [PATCH 01/11] feature/add fluentValidation validators for the min-max values --- Dappi.HeadlessCms/Dappi.HeadlessCms.csproj | 1 + .../Models/UpdateFieldRequest.cs | 2 + Dappi.HeadlessCms/ServiceExtensions.cs | 6 +++ .../Validators/FieldRequestValidator.cs | 47 +++++++++++++++++ .../Validators/FieldValidationHelper.cs | 51 +++++++++++++++++++ 5 files changed, 107 insertions(+) create mode 100644 Dappi.HeadlessCms/Validators/FieldRequestValidator.cs create mode 100644 Dappi.HeadlessCms/Validators/FieldValidationHelper.cs diff --git a/Dappi.HeadlessCms/Dappi.HeadlessCms.csproj b/Dappi.HeadlessCms/Dappi.HeadlessCms.csproj index 2b8024c..745a384 100644 --- a/Dappi.HeadlessCms/Dappi.HeadlessCms.csproj +++ b/Dappi.HeadlessCms/Dappi.HeadlessCms.csproj @@ -11,6 +11,7 @@ + diff --git a/Dappi.HeadlessCms/Models/UpdateFieldRequest.cs b/Dappi.HeadlessCms/Models/UpdateFieldRequest.cs index 2d85cd0..3586fb8 100644 --- a/Dappi.HeadlessCms/Models/UpdateFieldRequest.cs +++ b/Dappi.HeadlessCms/Models/UpdateFieldRequest.cs @@ -10,6 +10,8 @@ public class UpdateFieldRequest [Required] public string NewFieldName { get; set; } = null!; + public required string FieldType { get; set; } + public bool IsRequired { get; set; } = false; public string? Regex { get; set; } diff --git a/Dappi.HeadlessCms/ServiceExtensions.cs b/Dappi.HeadlessCms/ServiceExtensions.cs index d07efea..ff3eae5 100644 --- a/Dappi.HeadlessCms/ServiceExtensions.cs +++ b/Dappi.HeadlessCms/ServiceExtensions.cs @@ -8,6 +8,9 @@ using Dappi.HeadlessCms.Services; using Dappi.HeadlessCms.Services.Identity; using Dappi.HeadlessCms.Core; +using Dappi.HeadlessCms.Validators; +using FluentValidation; +using FluentValidation.AspNetCore; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; @@ -59,6 +62,9 @@ public static IServiceCollection AddDappi( services.AddScoped(); services.AddDappiSwaggerGen(); + services.AddFluentValidationAutoValidation(); + services.AddValidatorsFromAssemblyContaining(); + services.AddControllers() .AddJsonOptions(jsonOptions ?? (options => { diff --git a/Dappi.HeadlessCms/Validators/FieldRequestValidator.cs b/Dappi.HeadlessCms/Validators/FieldRequestValidator.cs new file mode 100644 index 0000000..ab199e1 --- /dev/null +++ b/Dappi.HeadlessCms/Validators/FieldRequestValidator.cs @@ -0,0 +1,47 @@ +using Dappi.HeadlessCms.Models; +using FluentValidation; + +namespace Dappi.HeadlessCms.Validators; + +public class FieldRequestValidator : AbstractValidator +{ + public FieldRequestValidator() + { + RuleFor(x => x.Min) + .Must((request, min) => FieldValidationHelper.ValidateMinValue(request.FieldType, min)) + .WithMessage("Min value is invalid for the field type.") + .When(x => x.Min.HasValue); + + RuleFor(x => x.Max) + .Must((request, max) => FieldValidationHelper.ValidateMaxValue(request.FieldType, max)) + .WithMessage("Max value is invalid for the field type.") + .When(x => x.Max.HasValue); + + RuleFor(x => x) + .Must(request => FieldValidationHelper.ValidateMinMaxRelationship(request.Min, request.Max)) + .WithMessage("Min value cannot be greater than max value.") + .When(x => x.Min.HasValue && x.Max.HasValue); + } +} + +public class UpdateFieldRequestValidator : AbstractValidator +{ + public UpdateFieldRequestValidator() + { + RuleFor(x => x.Min) + .Must((request, min) => FieldValidationHelper.ValidateMinValue(request.FieldType, min)) + .WithMessage("Min value is invalid for the field type.") + .When(x => x.Min.HasValue); + + RuleFor(x => x.Max) + .Must((request, max) => FieldValidationHelper.ValidateMaxValue(request.FieldType, max)) + .WithMessage("Max value is invalid for the field type.") + .When(x => x.Max.HasValue); + + RuleFor(x => x) + .Must(request => FieldValidationHelper.ValidateMinMaxRelationship(request.Min, request.Max)) + .WithMessage("Min value cannot be greater than max value.") + .When(x => x.Min.HasValue && x.Max.HasValue); + } +} + diff --git a/Dappi.HeadlessCms/Validators/FieldValidationHelper.cs b/Dappi.HeadlessCms/Validators/FieldValidationHelper.cs new file mode 100644 index 0000000..9974c3e --- /dev/null +++ b/Dappi.HeadlessCms/Validators/FieldValidationHelper.cs @@ -0,0 +1,51 @@ +namespace Dappi.HeadlessCms.Validators; + +public static class FieldValidationHelper +{ + public static readonly string[] TextTypes = { "string" }; + public static readonly string[] NumericTypes = { "int", "double", "float" }; + + public static bool ValidateMinValue(string fieldType, double? min) + { + if (!min.HasValue) + return true; + + if (TextTypes.Contains(fieldType)) + { + return min.Value >= 0 && Math.Floor(min.Value) == min.Value; + } + + if (NumericTypes.Contains(fieldType)) + { + return !double.IsNaN(min.Value); + } + + return true; + } + + public static bool ValidateMaxValue(string fieldType, double? max) + { + if (!max.HasValue) + return true; + + if (TextTypes.Contains(fieldType)) + { + return max.Value >= 0 && Math.Floor(max.Value) == max.Value; + } + + if (NumericTypes.Contains(fieldType)) + { + return !double.IsNaN(max.Value); + } + + return true; + } + + public static bool ValidateMinMaxRelationship(double? min, double? max) + { + if (!min.HasValue || !max.HasValue) + return true; + + return min.Value <= max.Value; + } +} From b0ef0aca1e9e78d70ed24ba1277126a138e89472 Mon Sep 17 00:00:00 2001 From: Mihail Date: Fri, 23 Jan 2026 15:52:08 +0100 Subject: [PATCH 02/11] Add xUnit tests for the DomainModelEditor for the min-max feature --- .../Core/DomainModelEditorTests.cs | 457 +++++++++++++++++- 1 file changed, 449 insertions(+), 8 deletions(-) diff --git a/Dappi.HeadlessCms.Tests/Core/DomainModelEditorTests.cs b/Dappi.HeadlessCms.Tests/Core/DomainModelEditorTests.cs index f89eace..9fecd71 100644 --- a/Dappi.HeadlessCms.Tests/Core/DomainModelEditorTests.cs +++ b/Dappi.HeadlessCms.Tests/Core/DomainModelEditorTests.cs @@ -143,13 +143,13 @@ public class {{DomainModelName}} var actual = await File.ReadAllTextAsync(_filePath); Assert.Equal(expected.ReplaceLineEndings(), actual.ReplaceLineEndings()); } - + [Theory] [ClassData(typeof(ValidPropertyTypes))] public async Task DomainModelEditor_Should_Add_Optional_Property(string type) { - var expected = $$""" + var expected = $$""" using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using Dappi.HeadlessCms.Models; @@ -169,18 +169,459 @@ public class {{DomainModelName}} } } """; - Property property = new() - { - DomainModel = DomainModelName, Name = TestPropertyName, Type = type, IsRequired = false, - }; - var modelRequest = new ModelRequest { ModelName = DomainModelName, IsAuditableEntity = false }; + Property property = new() + { + DomainModel = DomainModelName, + Name = TestPropertyName, + Type = type, + IsRequired = false, + }; + var modelRequest = new ModelRequest { ModelName = DomainModelName, IsAuditableEntity = false }; + _domainModelEditor.CreateEntityModel(modelRequest); + _domainModelEditor.AddProperty(property); + await _domainModelEditor.SaveAsync(); + var actual = await File.ReadAllTextAsync(_filePath); + Assert.Equal(expected.ReplaceLineEndings(), actual.ReplaceLineEndings()); + } + + [Fact] + public async Task DomainModelEditor_AddProperty_Should_Add_Length_Attribute_With_Both_Min_And_Max() + { + var modelRequest = new ModelRequest { ModelName = DomainModelName, IsAuditableEntity = false }; + _domainModelEditor.CreateEntityModel(modelRequest); + + var property = new Property + { + DomainModel = DomainModelName, + Name = "Description", + Type = "string", + IsRequired = false, + Min = "10", + Max = "100" + }; + + var expected = $$""" + using System.ComponentModel.DataAnnotations; + using System.ComponentModel.DataAnnotations.Schema; + using Dappi.HeadlessCms.Models; + using Dappi.Core.Attributes; + using Dappi.HeadlessCms.Core.Attributes; + using Dappi.Core.Enums; + + namespace {{_assemblyName}}.Entities + { + [{{CcControllerAttribute.ShortName}}] + public class {{DomainModelName}} + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } + + [Length(10, 100)] + public string? Description { get; set; } + } + } + """; + + _domainModelEditor.AddProperty(property); + await _domainModelEditor.SaveAsync(); + + var actual = await File.ReadAllTextAsync(_filePath); + Assert.Equal(expected.ReplaceLineEndings(), actual.ReplaceLineEndings()); + } + + [Fact] + public async Task DomainModelEditor_AddProperty_Should_Add_MinLength_Attribute_When_Only_Min_Specified() + { + var modelRequest = new ModelRequest { ModelName = DomainModelName, IsAuditableEntity = false }; + _domainModelEditor.CreateEntityModel(modelRequest); + + var property = new Property + { + DomainModel = DomainModelName, + Name = "Username", + Type = "string", + IsRequired = true, + Min = "5", + Max = null + }; + + var expected = $$""" + using System.ComponentModel.DataAnnotations; + using System.ComponentModel.DataAnnotations.Schema; + using Dappi.HeadlessCms.Models; + using Dappi.Core.Attributes; + using Dappi.HeadlessCms.Core.Attributes; + using Dappi.Core.Enums; + + namespace {{_assemblyName}}.Entities + { + [{{CcControllerAttribute.ShortName}}] + public class {{DomainModelName}} + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } + + [MinLength(5)] + public string Username { get; set; } + } + } + """; + + _domainModelEditor.AddProperty(property); + await _domainModelEditor.SaveAsync(); + + var actual = await File.ReadAllTextAsync(_filePath); + Assert.Equal(expected.ReplaceLineEndings(), actual.ReplaceLineEndings()); + } + + [Fact] + public async Task DomainModelEditor_AddProperty_Should_Add_MaxLength_Attribute_When_Only_Max_Specified() + { + var modelRequest = new ModelRequest { ModelName = DomainModelName, IsAuditableEntity = false }; + _domainModelEditor.CreateEntityModel(modelRequest); + + var property = new Property + { + DomainModel = DomainModelName, + Name = "ShortCode", + Type = "string", + IsRequired = false, + Min = null, + Max = "20" + }; + + var expected = $$""" + using System.ComponentModel.DataAnnotations; + using System.ComponentModel.DataAnnotations.Schema; + using Dappi.HeadlessCms.Models; + using Dappi.Core.Attributes; + using Dappi.HeadlessCms.Core.Attributes; + using Dappi.Core.Enums; + + namespace {{_assemblyName}}.Entities + { + [{{CcControllerAttribute.ShortName}}] + public class {{DomainModelName}} + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } + + [MaxLength(20)] + public string? ShortCode { get; set; } + } + } + """; + + _domainModelEditor.AddProperty(property); + await _domainModelEditor.SaveAsync(); + + var actual = await File.ReadAllTextAsync(_filePath); + Assert.Equal(expected.ReplaceLineEndings(), actual.ReplaceLineEndings()); + } + + [Fact] + public async Task DomainModelEditor_AddProperty_Should_Not_Add_Length_Attributes_When_Neither_Min_Nor_Max_Specified() + { + var modelRequest = new ModelRequest { ModelName = DomainModelName, IsAuditableEntity = false }; + _domainModelEditor.CreateEntityModel(modelRequest); + + var property = new Property + { + DomainModel = DomainModelName, + Name = "Title", + Type = "string", + IsRequired = false, + Min = null, + Max = null + }; + + var expected = $$""" + using System.ComponentModel.DataAnnotations; + using System.ComponentModel.DataAnnotations.Schema; + using Dappi.HeadlessCms.Models; + using Dappi.Core.Attributes; + using Dappi.HeadlessCms.Core.Attributes; + using Dappi.Core.Enums; + + namespace {{_assemblyName}}.Entities + { + [{{CcControllerAttribute.ShortName}}] + public class {{DomainModelName}} + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } + public string? Title { get; set; } + } + } + """; + + _domainModelEditor.AddProperty(property); + await _domainModelEditor.SaveAsync(); + + var actual = await File.ReadAllTextAsync(_filePath); + Assert.Equal(expected.ReplaceLineEndings(), actual.ReplaceLineEndings()); + } + + [Theory] + [InlineData("int", "1", "100")] + public async Task DomainModelEditor_AddProperty_Should_Add_Range_Attribute_For_Int_Types(string type, string min, string max) + { + var modelRequest = new ModelRequest { ModelName = DomainModelName, IsAuditableEntity = false }; + _domainModelEditor.CreateEntityModel(modelRequest); + + var property = new Property + { + DomainModel = DomainModelName, + Name = "Name", + Type = type, + IsRequired = false, + Min = min, + Max = max + }; + + _domainModelEditor.AddProperty(property); + await _domainModelEditor.SaveAsync(); + + var actual = await File.ReadAllTextAsync(_filePath); + Assert.Contains($"[Range({min}, {max})]", actual); + Assert.Contains($"public {type}? Name", actual); + } + + [Theory] + [InlineData("float", "-101.5", "142.5")] + [InlineData("double", "-123.92", "128.29")] + public async Task DomainModelEditor_AddProperty_Should_Add_Range_Attribute_For_Decimal_Types(string type, string min, string max) + { + var modelRequest = new ModelRequest { ModelName = DomainModelName, IsAuditableEntity = false }; _domainModelEditor.CreateEntityModel(modelRequest); + + var property = new Property + { + DomainModel = DomainModelName, + Name = "Name", + Type = type, + IsRequired = false, + Min = min, + Max = max + }; + _domainModelEditor.AddProperty(property); await _domainModelEditor.SaveAsync(); + + var actual = await File.ReadAllTextAsync(_filePath); + Assert.Contains($"[Range({min}, {max})]", actual); + Assert.Contains($"public {type}? Name", actual); + } + + [Fact] + public async Task DomainModelEditor_AddProperty_Should_Add_Range_With_Min_Only_For_Numeric_Types() + { + var modelRequest = new ModelRequest { ModelName = DomainModelName, IsAuditableEntity = false }; + _domainModelEditor.CreateEntityModel(modelRequest); + + var property = new Property + { + DomainModel = DomainModelName, + Name = "Name", + Type = "int", + IsRequired = false, + Min = "18", + Max = null + }; + + var expected = $$""" + using System.ComponentModel.DataAnnotations; + using System.ComponentModel.DataAnnotations.Schema; + using Dappi.HeadlessCms.Models; + using Dappi.Core.Attributes; + using Dappi.HeadlessCms.Core.Attributes; + using Dappi.Core.Enums; + + namespace {{_assemblyName}}.Entities + { + [{{CcControllerAttribute.ShortName}}] + public class {{DomainModelName}} + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } + + [Range(18, 2147483647)] + public int? Name { get; set; } + } + } + """; + + _domainModelEditor.AddProperty(property); + await _domainModelEditor.SaveAsync(); + var actual = await File.ReadAllTextAsync(_filePath); Assert.Equal(expected.ReplaceLineEndings(), actual.ReplaceLineEndings()); } - + + [Fact] + public async Task DomainModelEditor_AddProperty_Should_Add_Range_With_Max_Only_For_Numeric_Types() + { + var modelRequest = new ModelRequest { ModelName = DomainModelName, IsAuditableEntity = false }; + _domainModelEditor.CreateEntityModel(modelRequest); + + var property = new Property + { + DomainModel = DomainModelName, + Name = "Name", + Type = "int", + IsRequired = false, + Min = null, + Max = "100" + }; + + var expected = $$""" + using System.ComponentModel.DataAnnotations; + using System.ComponentModel.DataAnnotations.Schema; + using Dappi.HeadlessCms.Models; + using Dappi.Core.Attributes; + using Dappi.HeadlessCms.Core.Attributes; + using Dappi.Core.Enums; + + namespace {{_assemblyName}}.Entities + { + [{{CcControllerAttribute.ShortName}}] + public class {{DomainModelName}} + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } + + [Range(-2147483648, 100)] + public int? Name { get; set; } + } + } + """; + + _domainModelEditor.AddProperty(property); + await _domainModelEditor.SaveAsync(); + + var actual = await File.ReadAllTextAsync(_filePath); + Assert.Equal(expected.ReplaceLineEndings(), actual.ReplaceLineEndings()); + } + + [Fact] + public async Task DomainModelEditor_AddProperty_Should_Not_Add_Range_Attribute_When_Neither_Min_Nor_Max_Specified() + { + var modelRequest = new ModelRequest { ModelName = DomainModelName, IsAuditableEntity = false }; + _domainModelEditor.CreateEntityModel(modelRequest); + + var property = new Property + { + DomainModel = DomainModelName, + Name = "Name", + Type = "int", + IsRequired = false, + Min = null, + Max = null + }; + + var expected = $$""" + using System.ComponentModel.DataAnnotations; + using System.ComponentModel.DataAnnotations.Schema; + using Dappi.HeadlessCms.Models; + using Dappi.Core.Attributes; + using Dappi.HeadlessCms.Core.Attributes; + using Dappi.Core.Enums; + + namespace {{_assemblyName}}.Entities + { + [{{CcControllerAttribute.ShortName}}] + public class {{DomainModelName}} + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } + public int? Name { get; set; } + } + } + """; + + _domainModelEditor.AddProperty(property); + await _domainModelEditor.SaveAsync(); + + var actual = await File.ReadAllTextAsync(_filePath); + Assert.Equal(expected.ReplaceLineEndings(), actual.ReplaceLineEndings()); + } + + [Fact] + public async Task DomainModelEditor_UpdateProperty_Should_Update_String_Length_To_Both_Properties() + { + var modelRequest = new ModelRequest { ModelName = DomainModelName, IsAuditableEntity = false }; + _domainModelEditor.CreateEntityModel(modelRequest); + + var originalProperty = new Property + { + DomainModel = DomainModelName, + Name = "Name", + Type = "string", + IsRequired = false, + }; + + _domainModelEditor.AddProperty(originalProperty); + await _domainModelEditor.SaveAsync(); + + var updatedProperty = new Property + { + DomainModel = DomainModelName, + Name = "Name", + Type = "string", + IsRequired = false, + Min = "3", + Max = "55" + }; + + _domainModelEditor.UpdateProperty(DomainModelName, "Name", updatedProperty); + await _domainModelEditor.SaveAsync(); + + var actual = await File.ReadAllTextAsync(_filePath); + Assert.Contains("[Length(3, 55)]", actual); + } + + [Fact] + public async Task DomainModelEditor_UpdateProperty_Should_Change_String_From_MinLength_To_Length() + { + var modelRequest = new ModelRequest { ModelName = DomainModelName, IsAuditableEntity = false }; + _domainModelEditor.CreateEntityModel(modelRequest); + + var originalProperty = new Property + { + DomainModel = DomainModelName, + Name = "Code", + Type = "string", + IsRequired = false, + Min = "1" + }; + _domainModelEditor.AddProperty(originalProperty); + await _domainModelEditor.SaveAsync(); + + var updatedProperty = new Property + { + DomainModel = DomainModelName, + Name = "Code", + Type = "string", + IsRequired = false, + Min = "5", + Max = "15" + }; + + _domainModelEditor.UpdateProperty(DomainModelName, "Code", updatedProperty); + await _domainModelEditor.SaveAsync(); + + var actual = await File.ReadAllTextAsync(_filePath); + Assert.Contains("[Length(5, 15)]", actual); + Assert.DoesNotContain("[MinLength", actual); + } + #pragma warning disable CA1816 public void Dispose() #pragma warning restore CA1816 From a6909f3935c41bdce86f4b7454d7d913a2789e43 Mon Sep 17 00:00:00 2001 From: Mihail Date: Fri, 23 Jan 2026 16:46:59 +0100 Subject: [PATCH 03/11] refactor/ use collection expressions to initialize TextTypes and NumericTypes arrays. --- Dappi.HeadlessCms/Validators/FieldValidationHelper.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dappi.HeadlessCms/Validators/FieldValidationHelper.cs b/Dappi.HeadlessCms/Validators/FieldValidationHelper.cs index 9974c3e..b4d84ae 100644 --- a/Dappi.HeadlessCms/Validators/FieldValidationHelper.cs +++ b/Dappi.HeadlessCms/Validators/FieldValidationHelper.cs @@ -2,8 +2,9 @@ namespace Dappi.HeadlessCms.Validators; public static class FieldValidationHelper { - public static readonly string[] TextTypes = { "string" }; - public static readonly string[] NumericTypes = { "int", "double", "float" }; + public static readonly string[] TextTypes = ["string"]; + public static readonly string[] NumericTypes = ["int", "double", "float"]; + public static bool ValidateMinValue(string fieldType, double? min) { From 6f1e0bc768194439adbeb6f4f439c50bf5965db7 Mon Sep 17 00:00:00 2001 From: Mihail Date: Mon, 26 Jan 2026 14:27:11 +0100 Subject: [PATCH 04/11] Add tests for the FieldRequest and UpdateFieldRequest validators --- .../Dappi.HeadlessCms.Tests.csproj | 1 + .../Validators/FieldRequestValidatorTests.cs | 327 +++++++++++++++++ .../UpdateFieldRequestValidatorTests.cs | 345 ++++++++++++++++++ 3 files changed, 673 insertions(+) create mode 100644 Dappi.HeadlessCms.Tests/Validators/FieldRequestValidatorTests.cs create mode 100644 Dappi.HeadlessCms.Tests/Validators/UpdateFieldRequestValidatorTests.cs diff --git a/Dappi.HeadlessCms.Tests/Dappi.HeadlessCms.Tests.csproj b/Dappi.HeadlessCms.Tests/Dappi.HeadlessCms.Tests.csproj index a1b2fa0..34e3518 100644 --- a/Dappi.HeadlessCms.Tests/Dappi.HeadlessCms.Tests.csproj +++ b/Dappi.HeadlessCms.Tests/Dappi.HeadlessCms.Tests.csproj @@ -10,6 +10,7 @@ + diff --git a/Dappi.HeadlessCms.Tests/Validators/FieldRequestValidatorTests.cs b/Dappi.HeadlessCms.Tests/Validators/FieldRequestValidatorTests.cs new file mode 100644 index 0000000..8cd6579 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/Validators/FieldRequestValidatorTests.cs @@ -0,0 +1,327 @@ +using Dappi.HeadlessCms.Models; +using Dappi.HeadlessCms.Validators; +using FluentValidation.TestHelper; + +namespace Dappi.HeadlessCms.Tests.Validators; + +public class FieldRequestValidatorTests +{ + private readonly FieldRequestValidator _validator = new(); + + [Fact] + public void Should_have_error_when_Min_is_negative_for_string_field() + { + var model = new FieldRequest + { + FieldName = "TestField", + FieldType = "string", + Min = -1 + }; + + var result = _validator.TestValidate(model); + + result.ShouldHaveValidationErrorFor(x => x.Min) + .WithErrorMessage("Min value is invalid for the field type."); + } + + [Fact] + public void Should_have_error_when_Min_has_decimal_value_for_string_field() + { + var model = new FieldRequest + { + FieldName = "TestField", + FieldType = "string", + Min = 5.5 + }; + + var result = _validator.TestValidate(model); + + result.ShouldHaveValidationErrorFor(x => x.Min) + .WithErrorMessage("Min value is invalid for the field type."); + } + + [Theory] + [InlineData(0)] + [InlineData(5)] + [InlineData(100)] + public void Should_not_have_error_when_Min_is_valid_for_string_field(double minValue) + { + var model = new FieldRequest + { + FieldName = "TestField", + FieldType = "string", + Min = minValue + }; + + var result = _validator.TestValidate(model); + + result.ShouldNotHaveValidationErrorFor(x => x.Min); + } + + [Theory] + [InlineData(0)] + [InlineData(5)] + [InlineData(-5)] + [InlineData(100.5)] + [InlineData(-100.5)] + public void Should_not_have_error_when_Min_is_valid_for_numeric_field(double minValue) + { + var model = new FieldRequest + { + FieldName = "TestField", + FieldType = "int", + Min = minValue + }; + + var result = _validator.TestValidate(model); + + result.ShouldNotHaveValidationErrorFor(x => x.Min); + } + + [Fact] + public void Should_have_error_when_Min_is_NaN_for_numeric_field() + { + var model = new FieldRequest + { + FieldName = "TestField", + FieldType = "int", + Min = double.NaN + }; + + var result = _validator.TestValidate(model); + + result.ShouldHaveValidationErrorFor(x => x.Min) + .WithErrorMessage("Min value is invalid for the field type."); + } + + [Fact] + public void Should_not_have_error_when_Min_is_null() + { + var model = new FieldRequest + { + FieldName = "TestField", + FieldType = "string", + Min = null + }; + + var result = _validator.TestValidate(model); + + result.ShouldNotHaveValidationErrorFor(x => x.Min); + } + + [Fact] + public void Should_have_error_when_Max_is_negative_for_string_field() + { + var model = new FieldRequest + { + FieldName = "TestField", + FieldType = "string", + Max = -1 + }; + + var result = _validator.TestValidate(model); + + result.ShouldHaveValidationErrorFor(x => x.Max) + .WithErrorMessage("Max value is invalid for the field type."); + } + + [Fact] + public void Should_have_error_when_Max_has_decimal_value_for_string_field() + { + var model = new FieldRequest + { + FieldName = "TestField", + FieldType = "string", + Max = 5.5 + }; + + var result = _validator.TestValidate(model); + + result.ShouldHaveValidationErrorFor(x => x.Max) + .WithErrorMessage("Max value is invalid for the field type."); + } + + [Theory] + [InlineData(0)] + [InlineData(5)] + [InlineData(100)] + public void Should_not_have_error_when_Max_is_valid_for_string_field(double maxValue) + { + var model = new FieldRequest + { + FieldName = "TestField", + FieldType = "string", + Max = maxValue + }; + + var result = _validator.TestValidate(model); + + result.ShouldNotHaveValidationErrorFor(x => x.Max); + } + + [Theory] + [InlineData(0)] + [InlineData(5)] + [InlineData(-5)] + [InlineData(100.5)] + [InlineData(-100.5)] + public void Should_not_have_error_when_Max_is_valid_for_numeric_field(double maxValue) + { + var model = new FieldRequest + { + FieldName = "TestField", + FieldType = "int", + Max = maxValue + }; + + var result = _validator.TestValidate(model); + + result.ShouldNotHaveValidationErrorFor(x => x.Max); + } + + [Fact] + public void Should_have_error_when_Max_is_NaN_for_numeric_field() + { + var model = new FieldRequest + { + FieldName = "TestField", + FieldType = "int", + Max = double.NaN + }; + + var result = _validator.TestValidate(model); + + result.ShouldHaveValidationErrorFor(x => x.Max) + .WithErrorMessage("Max value is invalid for the field type."); + } + + [Fact] + public void Should_not_have_error_when_Max_is_null() + { + var model = new FieldRequest + { + FieldName = "TestField", + FieldType = "string", + Max = null + }; + + var result = _validator.TestValidate(model); + + result.ShouldNotHaveValidationErrorFor(x => x.Max); + } + + [Fact] + public void Should_have_error_when_Min_is_greater_than_Max() + { + var model = new FieldRequest + { + FieldName = "TestField", + FieldType = "int", + Min = 10, + Max = 5 + }; + + var result = _validator.TestValidate(model); + + result.ShouldHaveValidationErrorFor(x => x) + .WithErrorMessage("Min value cannot be greater than max value."); + } + + [Fact] + public void Should_not_have_error_when_Min_equals_Max() + { + var model = new FieldRequest + { + FieldName = "TestField", + FieldType = "int", + Min = 5, + Max = 5 + }; + + var result = _validator.TestValidate(model); + + result.ShouldNotHaveValidationErrorFor(x => x); + } + + [Fact] + public void Should_not_have_error_when_Min_is_less_than_Max() + { + var model = new FieldRequest + { + FieldName = "TestField", + FieldType = "int", + Min = 5, + Max = 10 + }; + + var result = _validator.TestValidate(model); + + result.ShouldNotHaveValidationErrorFor(x => x); + } + + [Fact] + public void Should_not_have_error_when_only_Min_is_specified() + { + var model = new FieldRequest + { + FieldName = "TestField", + FieldType = "int", + Min = 5, + Max = null + }; + + var result = _validator.TestValidate(model); + + result.ShouldNotHaveValidationErrorFor(x => x); + } + + [Fact] + public void Should_not_have_error_when_only_Max_is_specified() + { + var model = new FieldRequest + { + FieldName = "TestField", + FieldType = "int", + Min = null, + Max = 10 + }; + + var result = _validator.TestValidate(model); + + result.ShouldNotHaveValidationErrorFor(x => x); + } + + [Fact] + public void Should_not_have_error_when_both_Min_and_Max_are_null() + { + var model = new FieldRequest + { + FieldName = "TestField", + FieldType = "int", + Min = null, + Max = null + }; + + var result = _validator.TestValidate(model); + + result.ShouldNotHaveValidationErrorFor(x => x); + } + + [Fact] + public void Should_have_errors_when_Min_and_Max_are_invalid_for_string_field() + { + var model = new FieldRequest + { + FieldName = "TestField", + FieldType = "string", + Min = -1, + Max = 5.5 + }; + + var result = _validator.TestValidate(model); + + result.ShouldHaveValidationErrorFor(x => x.Min); + result.ShouldHaveValidationErrorFor(x => x.Max); + } +} + diff --git a/Dappi.HeadlessCms.Tests/Validators/UpdateFieldRequestValidatorTests.cs b/Dappi.HeadlessCms.Tests/Validators/UpdateFieldRequestValidatorTests.cs new file mode 100644 index 0000000..7c15c47 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/Validators/UpdateFieldRequestValidatorTests.cs @@ -0,0 +1,345 @@ +using Dappi.HeadlessCms.Models; +using Dappi.HeadlessCms.Validators; +using FluentValidation.TestHelper; + +namespace Dappi.HeadlessCms.Tests.Validators; + +public class UpdateFieldRequestValidatorTests +{ + private readonly UpdateFieldRequestValidator _validator = new(); + + [Fact] + public void Should_have_error_when_Min_is_negative_for_string_field() + { + var model = new UpdateFieldRequest + { + OldFieldName = "OldField", + NewFieldName = "NewField", + FieldType = "string", + Min = -1 + }; + + var result = _validator.TestValidate(model); + + result.ShouldHaveValidationErrorFor(x => x.Min) + .WithErrorMessage("Min value is invalid for the field type."); + } + + [Fact] + public void Should_have_error_when_Min_has_decimal_value_for_string_field() + { + var model = new UpdateFieldRequest + { + OldFieldName = "OldField", + NewFieldName = "NewField", + FieldType = "string", + Min = 5.5 + }; + + var result = _validator.TestValidate(model); + + result.ShouldHaveValidationErrorFor(x => x.Min) + .WithErrorMessage("Min value is invalid for the field type."); + } + + [Theory] + [InlineData(0)] + [InlineData(5)] + [InlineData(100)] + public void Should_not_have_error_when_Min_is_valid_for_string_field(double minValue) + { + var model = new UpdateFieldRequest + { + OldFieldName = "OldField", + NewFieldName = "NewField", + FieldType = "string", + Min = minValue + }; + + var result = _validator.TestValidate(model); + + result.ShouldNotHaveValidationErrorFor(x => x.Min); + } + + [Theory] + [InlineData(0)] + [InlineData(5)] + [InlineData(-5)] + [InlineData(100.5)] + [InlineData(-100.5)] + public void Should_not_have_error_when_Min_is_valid_for_numeric_field(double minValue) + { + var model = new UpdateFieldRequest + { + OldFieldName = "OldField", + NewFieldName = "NewField", + FieldType = "int", + Min = minValue + }; + + var result = _validator.TestValidate(model); + + result.ShouldNotHaveValidationErrorFor(x => x.Min); + } + + [Fact] + public void Should_have_error_when_Min_is_NaN_for_numeric_field() + { + var model = new UpdateFieldRequest + { + OldFieldName = "OldField", + NewFieldName = "NewField", + FieldType = "int", + Min = double.NaN + }; + + var result = _validator.TestValidate(model); + + result.ShouldHaveValidationErrorFor(x => x.Min) + .WithErrorMessage("Min value is invalid for the field type."); + } + + [Fact] + public void Should_not_have_error_when_Min_is_null() + { + var model = new UpdateFieldRequest + { + OldFieldName = "OldField", + NewFieldName = "NewField", + FieldType = "string", + Min = null + }; + + var result = _validator.TestValidate(model); + + result.ShouldNotHaveValidationErrorFor(x => x.Min); + } + + [Fact] + public void Should_have_error_when_Max_is_negative_for_string_field() + { + var model = new UpdateFieldRequest + { + OldFieldName = "OldField", + NewFieldName = "NewField", + FieldType = "string", + Max = -1 + }; + + var result = _validator.TestValidate(model); + + result.ShouldHaveValidationErrorFor(x => x.Max) + .WithErrorMessage("Max value is invalid for the field type."); + } + + [Fact] + public void Should_have_error_when_Max_has_decimal_value_for_string_field() + { + var model = new UpdateFieldRequest + { + OldFieldName = "OldField", + NewFieldName = "NewField", + FieldType = "string", + Max = 5.5 + }; + + var result = _validator.TestValidate(model); + + result.ShouldHaveValidationErrorFor(x => x.Max) + .WithErrorMessage("Max value is invalid for the field type."); + } + + [Theory] + [InlineData(0)] + [InlineData(5)] + [InlineData(100)] + public void Should_not_have_error_when_Max_is_valid_for_string_field(double maxValue) + { + var model = new UpdateFieldRequest + { + OldFieldName = "OldField", + NewFieldName = "NewField", + FieldType = "string", + Max = maxValue + }; + + var result = _validator.TestValidate(model); + + result.ShouldNotHaveValidationErrorFor(x => x.Max); + } + + [Theory] + [InlineData(0)] + [InlineData(5)] + [InlineData(-5)] + [InlineData(100.5)] + [InlineData(-100.5)] + public void Should_not_have_error_when_Max_is_valid_for_numeric_field(double maxValue) + { + var model = new UpdateFieldRequest + { + OldFieldName = "OldField", + NewFieldName = "NewField", + FieldType = "int", + Max = maxValue + }; + + var result = _validator.TestValidate(model); + + result.ShouldNotHaveValidationErrorFor(x => x.Max); + } + + [Fact] + public void Should_have_error_when_Max_is_NaN_for_numeric_field() + { + var model = new UpdateFieldRequest + { + OldFieldName = "OldField", + NewFieldName = "NewField", + FieldType = "int", + Max = double.NaN + }; + + var result = _validator.TestValidate(model); + + result.ShouldHaveValidationErrorFor(x => x.Max) + .WithErrorMessage("Max value is invalid for the field type."); + } + + [Fact] + public void Should_not_have_error_when_Max_is_null() + { + var model = new UpdateFieldRequest + { + OldFieldName = "OldField", + NewFieldName = "NewField", + FieldType = "string", + Max = null + }; + + var result = _validator.TestValidate(model); + + result.ShouldNotHaveValidationErrorFor(x => x.Max); + } + + [Fact] + public void Should_have_error_when_Min_is_greater_than_Max() + { + var model = new UpdateFieldRequest + { + OldFieldName = "OldField", + NewFieldName = "NewField", + FieldType = "int", + Min = 10, + Max = 5 + }; + + var result = _validator.TestValidate(model); + + result.ShouldHaveValidationErrorFor(x => x) + .WithErrorMessage("Min value cannot be greater than max value."); + } + + [Fact] + public void Should_not_have_error_when_Min_equals_Max() + { + var model = new UpdateFieldRequest + { + OldFieldName = "OldField", + NewFieldName = "NewField", + FieldType = "int", + Min = 5, + Max = 5 + }; + + var result = _validator.TestValidate(model); + + result.ShouldNotHaveValidationErrorFor(x => x); + } + + [Fact] + public void Should_not_have_error_when_Min_is_less_than_Max() + { + var model = new UpdateFieldRequest + { + OldFieldName = "OldField", + NewFieldName = "NewField", + FieldType = "int", + Min = 5, + Max = 10 + }; + + var result = _validator.TestValidate(model); + + result.ShouldNotHaveValidationErrorFor(x => x); + } + + [Fact] + public void Should_not_have_error_when_only_Min_is_specified() + { + var model = new UpdateFieldRequest + { + OldFieldName = "OldField", + NewFieldName = "NewField", + FieldType = "int", + Min = 5, + Max = null + }; + + var result = _validator.TestValidate(model); + + result.ShouldNotHaveValidationErrorFor(x => x); + } + + [Fact] + public void Should_not_have_error_when_only_Max_is_specified() + { + var model = new UpdateFieldRequest + { + OldFieldName = "OldField", + NewFieldName = "NewField", + FieldType = "int", + Min = null, + Max = 10 + }; + + var result = _validator.TestValidate(model); + + result.ShouldNotHaveValidationErrorFor(x => x); + } + + [Fact] + public void Should_not_have_error_when_both_Min_and_Max_are_null() + { + var model = new UpdateFieldRequest + { + OldFieldName = "OldField", + NewFieldName = "NewField", + FieldType = "int", + Min = null, + Max = null + }; + + var result = _validator.TestValidate(model); + + result.ShouldNotHaveValidationErrorFor(x => x); + } + + [Fact] + public void Should_have_errors_when_Min_and_Max_are_invalid_for_string_field() + { + var model = new UpdateFieldRequest + { + OldFieldName = "OldField", + NewFieldName = "NewField", + FieldType = "string", + Min = -1, + Max = 5.5 + }; + + var result = _validator.TestValidate(model); + + result.ShouldHaveValidationErrorFor(x => x.Min); + result.ShouldHaveValidationErrorFor(x => x.Max); + } +} From 8c563662200dff504cd4922b574be50aeedcae6d Mon Sep 17 00:00:00 2001 From: Mihail Date: Tue, 27 Jan 2026 11:47:56 +0100 Subject: [PATCH 05/11] Make the Validators Tests parametrised --- .../Validators/FieldRequestValidatorTests.cs | 454 ++++++++---------- .../UpdateFieldRequestValidatorTests.cs | 450 +++++++++-------- 2 files changed, 422 insertions(+), 482 deletions(-) diff --git a/Dappi.HeadlessCms.Tests/Validators/FieldRequestValidatorTests.cs b/Dappi.HeadlessCms.Tests/Validators/FieldRequestValidatorTests.cs index 8cd6579..67a1657 100644 --- a/Dappi.HeadlessCms.Tests/Validators/FieldRequestValidatorTests.cs +++ b/Dappi.HeadlessCms.Tests/Validators/FieldRequestValidatorTests.cs @@ -1,3 +1,4 @@ +using System.Linq.Expressions; using Dappi.HeadlessCms.Models; using Dappi.HeadlessCms.Validators; using FluentValidation.TestHelper; @@ -8,320 +9,281 @@ public class FieldRequestValidatorTests { private readonly FieldRequestValidator _validator = new(); - [Fact] - public void Should_have_error_when_Min_is_negative_for_string_field() + [Theory] + [MemberData(nameof(FieldRequestValidatorTestData.InvalidMinTestCases), MemberType = typeof(FieldRequestValidatorTestData))] + public void Should_have_error_for_invalid_Min_value(FieldRequest model, Expression> propertyExpression, string expectedErrorMessage) { - var model = new FieldRequest - { - FieldName = "TestField", - FieldType = "string", - Min = -1 - }; - var result = _validator.TestValidate(model); - result.ShouldHaveValidationErrorFor(x => x.Min) - .WithErrorMessage("Min value is invalid for the field type."); + result.ShouldHaveValidationErrorFor(propertyExpression) + .WithErrorMessage(expectedErrorMessage); } - [Fact] - public void Should_have_error_when_Min_has_decimal_value_for_string_field() + [Theory] + [MemberData(nameof(FieldRequestValidatorTestData.ValidMinTestCases), MemberType = typeof(FieldRequestValidatorTestData))] + public void Should_not_have_error_for_valid_Min_value(FieldRequest model, Expression> propertyExpression) { - var model = new FieldRequest - { - FieldName = "TestField", - FieldType = "string", - Min = 5.5 - }; - var result = _validator.TestValidate(model); - result.ShouldHaveValidationErrorFor(x => x.Min) - .WithErrorMessage("Min value is invalid for the field type."); + result.ShouldNotHaveValidationErrorFor(propertyExpression); } [Theory] - [InlineData(0)] - [InlineData(5)] - [InlineData(100)] - public void Should_not_have_error_when_Min_is_valid_for_string_field(double minValue) + [MemberData(nameof(FieldRequestValidatorTestData.InvalidMaxTestCases), MemberType = typeof(FieldRequestValidatorTestData))] + public void Should_have_error_for_invalid_Max_value(FieldRequest model, Expression> propertyExpression, string expectedErrorMessage) { - var model = new FieldRequest - { - FieldName = "TestField", - FieldType = "string", - Min = minValue - }; - var result = _validator.TestValidate(model); - result.ShouldNotHaveValidationErrorFor(x => x.Min); + result.ShouldHaveValidationErrorFor(propertyExpression) + .WithErrorMessage(expectedErrorMessage); } [Theory] - [InlineData(0)] - [InlineData(5)] - [InlineData(-5)] - [InlineData(100.5)] - [InlineData(-100.5)] - public void Should_not_have_error_when_Min_is_valid_for_numeric_field(double minValue) + [MemberData(nameof(FieldRequestValidatorTestData.ValidMaxTestCases), MemberType = typeof(FieldRequestValidatorTestData))] + public void Should_not_have_error_for_valid_Max_value( + FieldRequest model, + Expression> propertyExpression) { - var model = new FieldRequest - { - FieldName = "TestField", - FieldType = "int", - Min = minValue - }; - var result = _validator.TestValidate(model); - result.ShouldNotHaveValidationErrorFor(x => x.Min); + result.ShouldNotHaveValidationErrorFor(propertyExpression); } - [Fact] - public void Should_have_error_when_Min_is_NaN_for_numeric_field() + [Theory] + [MemberData(nameof(FieldRequestValidatorTestData.MinMaxComparisonTestCases), MemberType = typeof(FieldRequestValidatorTestData))] + public void Should_validate_Min_Max_comparison(FieldRequest model, bool shouldHaveError, string? expectedErrorMessage) { - var model = new FieldRequest - { - FieldName = "TestField", - FieldType = "int", - Min = double.NaN - }; - var result = _validator.TestValidate(model); - result.ShouldHaveValidationErrorFor(x => x.Min) - .WithErrorMessage("Min value is invalid for the field type."); + if (shouldHaveError) + { + result.ShouldHaveValidationErrorFor(x => x) + .WithErrorMessage(expectedErrorMessage!); + } + else + { + result.ShouldNotHaveValidationErrorFor(x => x); + } } +} - [Fact] - public void Should_not_have_error_when_Min_is_null() +public class FieldRequestValidatorTestData +{ + public static IEnumerable InvalidMinTestCases() { - var model = new FieldRequest + Expression> minExpression = x => x.Min; + const string errorMessage = "Min value is invalid for the field type."; + + yield return new object[] { - FieldName = "TestField", - FieldType = "string", - Min = null + new FieldRequest { FieldName = "TestField", FieldType = "string", Min = -1 }, + minExpression, + errorMessage }; - - var result = _validator.TestValidate(model); - - result.ShouldNotHaveValidationErrorFor(x => x.Min); - } - - [Fact] - public void Should_have_error_when_Max_is_negative_for_string_field() - { - var model = new FieldRequest + + yield return new object[] { - FieldName = "TestField", - FieldType = "string", - Max = -1 + new FieldRequest { FieldName = "TestField", FieldType = "string", Min = 5.5 }, + minExpression, + errorMessage }; - - var result = _validator.TestValidate(model); - - result.ShouldHaveValidationErrorFor(x => x.Max) - .WithErrorMessage("Max value is invalid for the field type."); - } - - [Fact] - public void Should_have_error_when_Max_has_decimal_value_for_string_field() - { - var model = new FieldRequest + + yield return new object[] { - FieldName = "TestField", - FieldType = "string", - Max = 5.5 + new FieldRequest { FieldName = "TestField", FieldType = "int", Min = double.NaN }, + minExpression, + errorMessage }; - - var result = _validator.TestValidate(model); - - result.ShouldHaveValidationErrorFor(x => x.Max) - .WithErrorMessage("Max value is invalid for the field type."); } - [Theory] - [InlineData(0)] - [InlineData(5)] - [InlineData(100)] - public void Should_not_have_error_when_Max_is_valid_for_string_field(double maxValue) + public static IEnumerable ValidMinTestCases() { - var model = new FieldRequest + Expression> minExpression = x => x.Min; + + yield return new object[] { - FieldName = "TestField", - FieldType = "string", - Max = maxValue + new FieldRequest { FieldName = "TestField", FieldType = "string", Min = 0 }, + minExpression }; - - var result = _validator.TestValidate(model); - - result.ShouldNotHaveValidationErrorFor(x => x.Max); - } - - [Theory] - [InlineData(0)] - [InlineData(5)] - [InlineData(-5)] - [InlineData(100.5)] - [InlineData(-100.5)] - public void Should_not_have_error_when_Max_is_valid_for_numeric_field(double maxValue) - { - var model = new FieldRequest + + yield return new object[] { - FieldName = "TestField", - FieldType = "int", - Max = maxValue + new FieldRequest { FieldName = "TestField", FieldType = "string", Min = 5 }, + minExpression }; - - var result = _validator.TestValidate(model); - - result.ShouldNotHaveValidationErrorFor(x => x.Max); - } - - [Fact] - public void Should_have_error_when_Max_is_NaN_for_numeric_field() - { - var model = new FieldRequest + + yield return new object[] { - FieldName = "TestField", - FieldType = "int", - Max = double.NaN + new FieldRequest { FieldName = "TestField", FieldType = "string", Min = 100 }, + minExpression }; - - var result = _validator.TestValidate(model); - - result.ShouldHaveValidationErrorFor(x => x.Max) - .WithErrorMessage("Max value is invalid for the field type."); - } - - [Fact] - public void Should_not_have_error_when_Max_is_null() - { - var model = new FieldRequest + + yield return new object[] { - FieldName = "TestField", - FieldType = "string", - Max = null + new FieldRequest { FieldName = "TestField", FieldType = "int", Min = 0 }, + minExpression }; - - var result = _validator.TestValidate(model); - - result.ShouldNotHaveValidationErrorFor(x => x.Max); - } - - [Fact] - public void Should_have_error_when_Min_is_greater_than_Max() - { - var model = new FieldRequest + + yield return new object[] { - FieldName = "TestField", - FieldType = "int", - Min = 10, - Max = 5 + new FieldRequest { FieldName = "TestField", FieldType = "int", Min = 5 }, + minExpression }; - - var result = _validator.TestValidate(model); - - result.ShouldHaveValidationErrorFor(x => x) - .WithErrorMessage("Min value cannot be greater than max value."); - } - - [Fact] - public void Should_not_have_error_when_Min_equals_Max() - { - var model = new FieldRequest + + yield return new object[] { - FieldName = "TestField", - FieldType = "int", - Min = 5, - Max = 5 + new FieldRequest { FieldName = "TestField", FieldType = "int", Min = -5 }, + minExpression }; - - var result = _validator.TestValidate(model); - - result.ShouldNotHaveValidationErrorFor(x => x); - } - - [Fact] - public void Should_not_have_error_when_Min_is_less_than_Max() - { - var model = new FieldRequest + + yield return new object[] { - FieldName = "TestField", - FieldType = "int", - Min = 5, - Max = 10 + new FieldRequest { FieldName = "TestField", FieldType = "int", Min = 100.5 }, + minExpression }; - - var result = _validator.TestValidate(model); - - result.ShouldNotHaveValidationErrorFor(x => x); - } - - [Fact] - public void Should_not_have_error_when_only_Min_is_specified() - { - var model = new FieldRequest + + yield return new object[] { - FieldName = "TestField", - FieldType = "int", - Min = 5, - Max = null + new FieldRequest { FieldName = "TestField", FieldType = "int", Min = -100.5 }, + minExpression + }; + + yield return new object[] + { + new FieldRequest { FieldName = "TestField", FieldType = "string", Min = null }, + minExpression }; - - var result = _validator.TestValidate(model); - - result.ShouldNotHaveValidationErrorFor(x => x); } - [Fact] - public void Should_not_have_error_when_only_Max_is_specified() + public static IEnumerable InvalidMaxTestCases() { - var model = new FieldRequest + Expression> maxExpression = x => x.Max; + const string errorMessage = "Max value is invalid for the field type."; + + yield return new object[] { - FieldName = "TestField", - FieldType = "int", - Min = null, - Max = 10 + new FieldRequest { FieldName = "TestField", FieldType = "string", Max = -1 }, + maxExpression, + errorMessage + }; + + yield return new object[] + { + new FieldRequest { FieldName = "TestField", FieldType = "string", Max = 5.5 }, + maxExpression, + errorMessage + }; + + yield return new object[] + { + new FieldRequest { FieldName = "TestField", FieldType = "int", Max = double.NaN }, + maxExpression, + errorMessage }; - - var result = _validator.TestValidate(model); - - result.ShouldNotHaveValidationErrorFor(x => x); } - [Fact] - public void Should_not_have_error_when_both_Min_and_Max_are_null() + public static IEnumerable ValidMaxTestCases() { - var model = new FieldRequest + Expression> maxExpression = x => x.Max; + + yield return new object[] { - FieldName = "TestField", - FieldType = "int", - Min = null, - Max = null + new FieldRequest { FieldName = "TestField", FieldType = "string", Max = 0 }, + maxExpression + }; + + yield return new object[] + { + new FieldRequest { FieldName = "TestField", FieldType = "string", Max = 5 }, + maxExpression + }; + + yield return new object[] + { + new FieldRequest { FieldName = "TestField", FieldType = "string", Max = 100 }, + maxExpression + }; + + yield return new object[] + { + new FieldRequest { FieldName = "TestField", FieldType = "int", Max = 0 }, + maxExpression + }; + + yield return new object[] + { + new FieldRequest { FieldName = "TestField", FieldType = "int", Max = 5 }, + maxExpression + }; + + yield return new object[] + { + new FieldRequest { FieldName = "TestField", FieldType = "int", Max = -5 }, + maxExpression + }; + + yield return new object[] + { + new FieldRequest { FieldName = "TestField", FieldType = "int", Max = 100.5 }, + maxExpression + }; + + yield return new object[] + { + new FieldRequest { FieldName = "TestField", FieldType = "int", Max = -100.5 }, + maxExpression + }; + + yield return new object[] + { + new FieldRequest { FieldName = "TestField", FieldType = "string", Max = null }, + maxExpression }; - - var result = _validator.TestValidate(model); - - result.ShouldNotHaveValidationErrorFor(x => x); } - [Fact] - public void Should_have_errors_when_Min_and_Max_are_invalid_for_string_field() + public static IEnumerable MinMaxComparisonTestCases() { - var model = new FieldRequest + yield return new object[] { - FieldName = "TestField", - FieldType = "string", - Min = -1, - Max = 5.5 + new FieldRequest { FieldName = "TestField", FieldType = "int", Min = 10, Max = 5 }, + true, + "Min value cannot be greater than max value." + }; + + yield return new object[] + { + new FieldRequest { FieldName = "TestField", FieldType = "int", Min = 5, Max = 5 }, + false, + null! + }; + + yield return new object[] + { + new FieldRequest { FieldName = "TestField", FieldType = "int", Min = 5, Max = 10 }, + false, + null! + }; + + yield return new object[] + { + new FieldRequest { FieldName = "TestField", FieldType = "int", Min = 5, Max = null }, + false, + null! + }; + + yield return new object[] + { + new FieldRequest { FieldName = "TestField", FieldType = "int", Min = null, Max = 10 }, + false, + null! + }; + + yield return new object[] + { + new FieldRequest { FieldName = "TestField", FieldType = "int", Min = null, Max = null }, + false, + null! }; - - var result = _validator.TestValidate(model); - - result.ShouldHaveValidationErrorFor(x => x.Min); - result.ShouldHaveValidationErrorFor(x => x.Max); } } diff --git a/Dappi.HeadlessCms.Tests/Validators/UpdateFieldRequestValidatorTests.cs b/Dappi.HeadlessCms.Tests/Validators/UpdateFieldRequestValidatorTests.cs index 7c15c47..720f574 100644 --- a/Dappi.HeadlessCms.Tests/Validators/UpdateFieldRequestValidatorTests.cs +++ b/Dappi.HeadlessCms.Tests/Validators/UpdateFieldRequestValidatorTests.cs @@ -1,3 +1,4 @@ +using System.Linq.Expressions; using Dappi.HeadlessCms.Models; using Dappi.HeadlessCms.Validators; using FluentValidation.TestHelper; @@ -8,338 +9,315 @@ public class UpdateFieldRequestValidatorTests { private readonly UpdateFieldRequestValidator _validator = new(); - [Fact] - public void Should_have_error_when_Min_is_negative_for_string_field() + [Theory] + [MemberData(nameof(UpdateFieldValidationTestData.InvalidMinTestCases), MemberType = typeof(UpdateFieldValidationTestData))] + public void Should_have_error_for_invalid_Min_value( + UpdateFieldRequest model, + Expression> propertyExpression, + string expectedErrorMessage) { - var model = new UpdateFieldRequest - { - OldFieldName = "OldField", - NewFieldName = "NewField", - FieldType = "string", - Min = -1 - }; - var result = _validator.TestValidate(model); - result.ShouldHaveValidationErrorFor(x => x.Min) - .WithErrorMessage("Min value is invalid for the field type."); + result.ShouldHaveValidationErrorFor(propertyExpression) + .WithErrorMessage(expectedErrorMessage); } - [Fact] - public void Should_have_error_when_Min_has_decimal_value_for_string_field() + [Theory] + [MemberData(nameof(UpdateFieldValidationTestData.ValidMinTestCases), MemberType = typeof(UpdateFieldValidationTestData))] + public void Should_not_have_error_for_valid_Min_value( + UpdateFieldRequest model, + Expression> propertyExpression) { - var model = new UpdateFieldRequest - { - OldFieldName = "OldField", - NewFieldName = "NewField", - FieldType = "string", - Min = 5.5 - }; - var result = _validator.TestValidate(model); - result.ShouldHaveValidationErrorFor(x => x.Min) - .WithErrorMessage("Min value is invalid for the field type."); + result.ShouldNotHaveValidationErrorFor(propertyExpression); } [Theory] - [InlineData(0)] - [InlineData(5)] - [InlineData(100)] - public void Should_not_have_error_when_Min_is_valid_for_string_field(double minValue) + [MemberData(nameof(UpdateFieldValidationTestData.InvalidMaxTestCases), MemberType = typeof(UpdateFieldValidationTestData))] + public void Should_have_error_for_invalid_Max_value( + UpdateFieldRequest model, + Expression> propertyExpression, + string expectedErrorMessage) { - var model = new UpdateFieldRequest - { - OldFieldName = "OldField", - NewFieldName = "NewField", - FieldType = "string", - Min = minValue - }; - var result = _validator.TestValidate(model); - result.ShouldNotHaveValidationErrorFor(x => x.Min); + result.ShouldHaveValidationErrorFor(propertyExpression) + .WithErrorMessage(expectedErrorMessage); } [Theory] - [InlineData(0)] - [InlineData(5)] - [InlineData(-5)] - [InlineData(100.5)] - [InlineData(-100.5)] - public void Should_not_have_error_when_Min_is_valid_for_numeric_field(double minValue) + [MemberData(nameof(UpdateFieldValidationTestData.ValidMaxTestCases), MemberType = typeof(UpdateFieldValidationTestData))] + public void Should_not_have_error_for_valid_Max_value( + UpdateFieldRequest model, + Expression> propertyExpression) { - var model = new UpdateFieldRequest - { - OldFieldName = "OldField", - NewFieldName = "NewField", - FieldType = "int", - Min = minValue - }; - var result = _validator.TestValidate(model); - result.ShouldNotHaveValidationErrorFor(x => x.Min); + result.ShouldNotHaveValidationErrorFor(propertyExpression); } - [Fact] - public void Should_have_error_when_Min_is_NaN_for_numeric_field() + [Theory] + [MemberData(nameof(UpdateFieldValidationTestData.MinMaxComparisonTestCases), MemberType = typeof(UpdateFieldValidationTestData))] + public void Should_validate_Min_Max_comparison( + UpdateFieldRequest model, + bool shouldHaveError, + string? expectedErrorMessage) { - var model = new UpdateFieldRequest - { - OldFieldName = "OldField", - NewFieldName = "NewField", - FieldType = "int", - Min = double.NaN - }; - var result = _validator.TestValidate(model); - result.ShouldHaveValidationErrorFor(x => x.Min) - .WithErrorMessage("Min value is invalid for the field type."); + if (shouldHaveError) + { + result.ShouldHaveValidationErrorFor(x => x) + .WithErrorMessage(expectedErrorMessage!); + } + else + { + result.ShouldNotHaveValidationErrorFor(x => x); + } } +} - [Fact] - public void Should_not_have_error_when_Min_is_null() +public class UpdateFieldValidationTestData +{ + public static IEnumerable InvalidMinTestCases() { - var model = new UpdateFieldRequest + Expression> minExpression = x => x.Min; + const string errorMessage = "Min value is invalid for the field type."; + + yield return new object[] { - OldFieldName = "OldField", - NewFieldName = "NewField", - FieldType = "string", - Min = null + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "string", Min = -1 }, + minExpression, + errorMessage }; - var result = _validator.TestValidate(model); - - result.ShouldNotHaveValidationErrorFor(x => x.Min); - } - - [Fact] - public void Should_have_error_when_Max_is_negative_for_string_field() - { - var model = new UpdateFieldRequest + yield return new object[] { - OldFieldName = "OldField", - NewFieldName = "NewField", - FieldType = "string", - Max = -1 + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "string", Min = 5.5 }, + minExpression, + errorMessage }; - var result = _validator.TestValidate(model); - - result.ShouldHaveValidationErrorFor(x => x.Max) - .WithErrorMessage("Max value is invalid for the field type."); - } - - [Fact] - public void Should_have_error_when_Max_has_decimal_value_for_string_field() - { - var model = new UpdateFieldRequest + yield return new object[] { - OldFieldName = "OldField", - NewFieldName = "NewField", - FieldType = "string", - Max = 5.5 + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "int", Min = double.NaN }, + minExpression, + errorMessage }; - - var result = _validator.TestValidate(model); - - result.ShouldHaveValidationErrorFor(x => x.Max) - .WithErrorMessage("Max value is invalid for the field type."); } - [Theory] - [InlineData(0)] - [InlineData(5)] - [InlineData(100)] - public void Should_not_have_error_when_Max_is_valid_for_string_field(double maxValue) + public static IEnumerable ValidMinTestCases() { - var model = new UpdateFieldRequest + Expression> minExpression = x => x.Min; + + yield return new object[] { - OldFieldName = "OldField", - NewFieldName = "NewField", - FieldType = "string", - Max = maxValue + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "string", Min = 0 }, + minExpression }; - var result = _validator.TestValidate(model); - - result.ShouldNotHaveValidationErrorFor(x => x.Max); - } + yield return new object[] + { + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "string", Min = 5 }, + minExpression + }; - [Theory] - [InlineData(0)] - [InlineData(5)] - [InlineData(-5)] - [InlineData(100.5)] - [InlineData(-100.5)] - public void Should_not_have_error_when_Max_is_valid_for_numeric_field(double maxValue) - { - var model = new UpdateFieldRequest + yield return new object[] { - OldFieldName = "OldField", - NewFieldName = "NewField", - FieldType = "int", - Max = maxValue + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "string", Min = 100 }, + minExpression }; - var result = _validator.TestValidate(model); + yield return new object[] + { + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "int", Min = 0 }, + minExpression + }; - result.ShouldNotHaveValidationErrorFor(x => x.Max); - } + yield return new object[] + { + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "int", Min = 5 }, + minExpression + }; - [Fact] - public void Should_have_error_when_Max_is_NaN_for_numeric_field() - { - var model = new UpdateFieldRequest + yield return new object[] { - OldFieldName = "OldField", - NewFieldName = "NewField", - FieldType = "int", - Max = double.NaN + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "int", Min = -5 }, + minExpression }; - var result = _validator.TestValidate(model); + yield return new object[] + { + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "int", Min = 100.5 }, + minExpression + }; - result.ShouldHaveValidationErrorFor(x => x.Max) - .WithErrorMessage("Max value is invalid for the field type."); - } + yield return new object[] + { + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "int", Min = -100.5 }, + minExpression + }; - [Fact] - public void Should_not_have_error_when_Max_is_null() - { - var model = new UpdateFieldRequest + yield return new object[] { - OldFieldName = "OldField", - NewFieldName = "NewField", - FieldType = "string", - Max = null + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "double", Min = 5.5 }, + minExpression }; - var result = _validator.TestValidate(model); + yield return new object[] + { + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "float", Min = 5.5 }, + minExpression + }; - result.ShouldNotHaveValidationErrorFor(x => x.Max); + yield return new object[] + { + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "string", Min = null }, + minExpression + }; } - [Fact] - public void Should_have_error_when_Min_is_greater_than_Max() + public static IEnumerable InvalidMaxTestCases() { - var model = new UpdateFieldRequest + Expression> maxExpression = x => x.Max; + const string errorMessage = "Max value is invalid for the field type."; + + yield return new object[] { - OldFieldName = "OldField", - NewFieldName = "NewField", - FieldType = "int", - Min = 10, - Max = 5 + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "string", Max = -1 }, + maxExpression, + errorMessage }; - var result = _validator.TestValidate(model); + yield return new object[] + { + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "string", Max = 5.5 }, + maxExpression, + errorMessage + }; - result.ShouldHaveValidationErrorFor(x => x) - .WithErrorMessage("Min value cannot be greater than max value."); + yield return new object[] + { + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "int", Max = double.NaN }, + maxExpression, + errorMessage + }; } - [Fact] - public void Should_not_have_error_when_Min_equals_Max() + public static IEnumerable ValidMaxTestCases() { - var model = new UpdateFieldRequest + Expression> maxExpression = x => x.Max; + + yield return new object[] { - OldFieldName = "OldField", - NewFieldName = "NewField", - FieldType = "int", - Min = 5, - Max = 5 + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "string", Max = 0 }, + maxExpression }; - var result = _validator.TestValidate(model); - - result.ShouldNotHaveValidationErrorFor(x => x); - } + yield return new object[] + { + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "string", Max = 5 }, + maxExpression + }; - [Fact] - public void Should_not_have_error_when_Min_is_less_than_Max() - { - var model = new UpdateFieldRequest + yield return new object[] { - OldFieldName = "OldField", - NewFieldName = "NewField", - FieldType = "int", - Min = 5, - Max = 10 + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "string", Max = 100 }, + maxExpression }; - var result = _validator.TestValidate(model); + yield return new object[] + { + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "int", Max = 0 }, + maxExpression + }; - result.ShouldNotHaveValidationErrorFor(x => x); - } + yield return new object[] + { + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "int", Max = 5 }, + maxExpression + }; - [Fact] - public void Should_not_have_error_when_only_Min_is_specified() - { - var model = new UpdateFieldRequest + yield return new object[] { - OldFieldName = "OldField", - NewFieldName = "NewField", - FieldType = "int", - Min = 5, - Max = null + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "int", Max = -5 }, + maxExpression }; - var result = _validator.TestValidate(model); + yield return new object[] + { + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "int", Max = 100.5 }, + maxExpression + }; - result.ShouldNotHaveValidationErrorFor(x => x); - } + yield return new object[] + { + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "int", Max = -100.5 }, + maxExpression + }; - [Fact] - public void Should_not_have_error_when_only_Max_is_specified() - { - var model = new UpdateFieldRequest + yield return new object[] { - OldFieldName = "OldField", - NewFieldName = "NewField", - FieldType = "int", - Min = null, - Max = 10 + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "double", Max = 5.5 }, + maxExpression }; - var result = _validator.TestValidate(model); + yield return new object[] + { + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "float", Max = 5.5 }, + maxExpression + }; - result.ShouldNotHaveValidationErrorFor(x => x); + yield return new object[] + { + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "string", Max = null }, + maxExpression + }; } - [Fact] - public void Should_not_have_error_when_both_Min_and_Max_are_null() + public static IEnumerable MinMaxComparisonTestCases() { - var model = new UpdateFieldRequest + yield return new object[] { - OldFieldName = "OldField", - NewFieldName = "NewField", - FieldType = "int", - Min = null, - Max = null + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "int", Min = 10, Max = 5 }, + true, + "Min value cannot be greater than max value." }; - var result = _validator.TestValidate(model); + yield return new object[] + { + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "int", Min = 5, Max = 5 }, + false, + null! + }; - result.ShouldNotHaveValidationErrorFor(x => x); - } + yield return new object[] + { + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "int", Min = 5, Max = 10 }, + false, + null! + }; - [Fact] - public void Should_have_errors_when_Min_and_Max_are_invalid_for_string_field() - { - var model = new UpdateFieldRequest + yield return new object[] { - OldFieldName = "OldField", - NewFieldName = "NewField", - FieldType = "string", - Min = -1, - Max = 5.5 + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "int", Min = 5, Max = null }, + false, + null! }; - var result = _validator.TestValidate(model); + yield return new object[] + { + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "int", Min = null, Max = 10 }, + false, + null! + }; - result.ShouldHaveValidationErrorFor(x => x.Min); - result.ShouldHaveValidationErrorFor(x => x.Max); + yield return new object[] + { + new UpdateFieldRequest { OldFieldName = "OldField", NewFieldName = "NewField", FieldType = "int", Min = null, Max = null }, + false, + null! + }; } } From 82b7f6950fb10faa602cf6d9507fe19c1c69355b Mon Sep 17 00:00:00 2001 From: Mihail Date: Tue, 27 Jan 2026 13:39:52 +0100 Subject: [PATCH 06/11] refactor/ change the range attribute generation to use type constants instead of numeric literals --- .../Core/DomainModelEditorTests.cs | 4 +- .../Core/Extensions/RoslynHelpers.cs | 63 ++++++++++--------- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/Dappi.HeadlessCms.Tests/Core/DomainModelEditorTests.cs b/Dappi.HeadlessCms.Tests/Core/DomainModelEditorTests.cs index 9fecd71..0827bbd 100644 --- a/Dappi.HeadlessCms.Tests/Core/DomainModelEditorTests.cs +++ b/Dappi.HeadlessCms.Tests/Core/DomainModelEditorTests.cs @@ -450,7 +450,7 @@ public class {{DomainModelName}} [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } - [Range(18, 2147483647)] + [Range(18, int.MaxValue)] public int? Name { get; set; } } } @@ -496,7 +496,7 @@ public class {{DomainModelName}} [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } - [Range(-2147483648, 100)] + [Range(int.MinValue, 100)] public int? Name { get; set; } } } diff --git a/Dappi.HeadlessCms/Core/Extensions/RoslynHelpers.cs b/Dappi.HeadlessCms/Core/Extensions/RoslynHelpers.cs index a039cbc..68631a1 100644 --- a/Dappi.HeadlessCms/Core/Extensions/RoslynHelpers.cs +++ b/Dappi.HeadlessCms/Core/Extensions/RoslynHelpers.cs @@ -168,45 +168,48 @@ public static PropertyDeclarationSyntax WithRangeAttribute(this PropertyDeclarat } } - if (minDouble == null) + ExpressionSyntax CreateMinMaxExpression(string typeName, bool isMax) { - minDouble = propertyType.ToLower() switch + var keyword = typeName.ToLower() switch { - "int" => int.MinValue, - "float" => float.MinValue, - "double" => double.MinValue, - "decimal" => (double)decimal.MinValue, - "long" => long.MinValue, - "short" => short.MinValue, - "byte" => byte.MinValue, - _ => double.MinValue + "int" => SyntaxKind.IntKeyword, + "float" => SyntaxKind.FloatKeyword, + "double" => SyntaxKind.DoubleKeyword, + _ => SyntaxKind.DoubleKeyword }; + + return SyntaxFactory.MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + SyntaxFactory.PredefinedType(SyntaxFactory.Token(keyword)), + SyntaxFactory.IdentifierName(isMax ? "MaxValue" : "MinValue")); + } + + ExpressionSyntax minExpression; + if (minDouble == null) + { + minExpression = CreateMinMaxExpression(propertyType, false); + } + else + { + minExpression = SyntaxFactory.LiteralExpression( + SyntaxKind.NumericLiteralExpression, + SyntaxFactory.Literal(minDouble.Value.ToString(System.Globalization.CultureInfo.InvariantCulture), minDouble.Value)); } + ExpressionSyntax maxExpression; if (maxDouble == null) { - maxDouble = propertyType.ToLower() switch - { - "int" => int.MaxValue, - "float" => float.MaxValue, - "double" => double.MaxValue, - "decimal" => (double)decimal.MaxValue, - "long" => long.MaxValue, - "short" => short.MaxValue, - "byte" => byte.MaxValue, - _ => double.MaxValue - }; + maxExpression = CreateMinMaxExpression(propertyType, true); + } + else + { + maxExpression = SyntaxFactory.LiteralExpression( + SyntaxKind.NumericLiteralExpression, + SyntaxFactory.Literal(maxDouble.Value.ToString(System.Globalization.CultureInfo.InvariantCulture), maxDouble.Value)); } - var minLiteral = SyntaxFactory.LiteralExpression( - SyntaxKind.NumericLiteralExpression, - SyntaxFactory.Literal(minDouble.Value.ToString(System.Globalization.CultureInfo.InvariantCulture), minDouble.Value)); - var maxLiteral = SyntaxFactory.LiteralExpression( - SyntaxKind.NumericLiteralExpression, - SyntaxFactory.Literal(maxDouble.Value.ToString(System.Globalization.CultureInfo.InvariantCulture), maxDouble.Value)); - - arguments.Add(SyntaxFactory.AttributeArgument(minLiteral)); - arguments.Add(SyntaxFactory.AttributeArgument(maxLiteral)); + arguments.Add(SyntaxFactory.AttributeArgument(minExpression)); + arguments.Add(SyntaxFactory.AttributeArgument(maxExpression)); attribute = attribute.WithArgumentList( SyntaxFactory.AttributeArgumentList(SyntaxFactory.SeparatedList(arguments)) From 0abae22f5852ea2d94edd8adf2c0adfc801d9b90 Mon Sep 17 00:00:00 2001 From: Mihail Date: Wed, 28 Jan 2026 16:34:07 +0100 Subject: [PATCH 07/11] add controller level tests for the min-max feature --- .../Controllers/ModelsControllerTests.cs | 152 +++++++++++++++++- .../TestData/PropertyAndClassNames.cs | 33 ++++ .../DoubleMinMax/model.verified.txt | 20 +++ .../DoubleMinMax/response.verified.txt | 13 ++ .../FloatMinMax/model.verified.txt | 1 + .../IntEqual/model.verified.txt | 20 +++ .../IntEqual/response.verified.txt | 13 ++ .../IntMinMax/model.verified.txt | 1 + .../IntNegative/model.verified.txt | 20 +++ .../IntNegative/response.verified.txt | 13 ++ .../StringMaxOnly/model.verified.txt | 1 + .../StringMinMax/model.verified.txt | 20 +++ .../StringMinMax/response.verified.txt | 13 ++ .../StringMinOnly/model.verified.txt | 20 +++ .../StringMinOnly/response.verified.txt | 13 ++ .../response.verified.txt | 20 +++ .../response.verified.txt | 20 +++ .../response.verified.txt | 1 + .../StringBothNegative/response.verified.txt | 23 +++ .../StringDecimalMax/response.verified.txt | 20 +++ .../StringDecimalMin/response.verified.txt | 20 +++ .../response.verified.txt | 20 +++ .../StringNegativeMin/response.verified.txt | 1 + .../123InvalidClass/response.verified.txt | 1 + .../Invalid Name/response.verified.txt | 1 + .../Invalid@ClassName/response.verified.txt | 1 + .../Property@/response.verified.txt | 1 + .../async/response.verified.txt | 1 + .../await/response.verified.txt | 1 + .../class!/response.verified.txt | 1 + .../class/response.verified.txt | 1 + .../int/response.verified.txt | 1 + .../public/response.verified.txt | 1 + .../var/response.verified.txt | 1 + .../void/response.verified.txt | 1 + .../DoubleMinMax/model.verified.txt | 1 + .../FloatMinMax/model.verified.txt | 1 + .../IntEqual/model.verified.txt | 1 + .../IntMinMax/model.verified.txt | 1 + .../IntNegative/model.verified.txt | 1 + .../StringMaxOnly/model.verified.txt | 1 + .../StringMinMax/model.verified.txt | 1 + .../StringMinOnly/model.verified.txt | 1 + .../response.verified.txt | 1 + .../response.verified.txt | 1 + .../response.verified.txt | 1 + .../StringBothNegative/response.verified.txt | 1 + .../StringDecimalMax/response.verified.txt | 1 + .../StringDecimalMin/response.verified.txt | 1 + .../response.verified.txt | 1 + .../StringNegativeMin/response.verified.txt | 1 + 51 files changed, 504 insertions(+), 2 deletions(-) create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/DoubleMinMax/model.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/DoubleMinMax/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/FloatMinMax/model.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntEqual/model.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntEqual/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntMinMax/model.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntNegative/model.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntNegative/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMaxOnly/model.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMinMax/model.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMinMax/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMinOnly/model.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMinOnly/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/DoubleMinGreaterThanMax/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/FloatMinGreaterThanMax/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/IntMinGreaterThanMax/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/StringBothNegative/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/StringDecimalMax/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/StringDecimalMin/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/StringMinGreaterThanMax/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/StringNegativeMin/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/123InvalidClass/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Invalid Name/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Invalid@ClassName/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Property@/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/async/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/await/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/class!/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/class/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/int/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/public/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/var/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/void/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/DoubleMinMax/model.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/FloatMinMax/model.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntEqual/model.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntMinMax/model.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntNegative/model.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMaxOnly/model.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMinMax/model.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMinOnly/model.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/DoubleMinGreaterThanMax/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/FloatMinGreaterThanMax/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/IntMinGreaterThanMax/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringBothNegative/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringDecimalMax/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringDecimalMin/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringMinGreaterThanMax/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringNegativeMin/response.verified.txt diff --git a/Dappi.HeadlessCms.Tests/Controllers/ModelsControllerTests.cs b/Dappi.HeadlessCms.Tests/Controllers/ModelsControllerTests.cs index 85d557b..c13b234 100644 --- a/Dappi.HeadlessCms.Tests/Controllers/ModelsControllerTests.cs +++ b/Dappi.HeadlessCms.Tests/Controllers/ModelsControllerTests.cs @@ -69,7 +69,7 @@ public async Task CreateModel_Should_Return_BadRequest_If_Model_Name_Is_Empty() [Theory] [ClassData(typeof(InvalidPropertyTypesAndClassNames))] - public async Task CreateModel_Should_Return_BadRequest_If_Model_Name_Is_Invalid(string modelName) + public async Task CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid(string modelName) { var auth = await _client.Authorize(); _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {auth?.Token}"); @@ -78,7 +78,7 @@ public async Task CreateModel_Should_Return_BadRequest_If_Model_Name_Is_Invalid( var res = await _client.PostAsJsonAsync(_baseUrl, request); _verifySettings.UseDirectory( - $"{_snapshotPath}/{nameof(CreateModel_Should_Return_BadRequest_If_Model_Name_Is_Invalid)}/{modelName}"); + $"{_snapshotPath}/{nameof(CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid)}/{modelName}"); await Verify(res, _verifySettings).UseFileName("response"); } @@ -436,6 +436,154 @@ public async Task AddField_Should_Add_ManyToMany_Relation_To_Models() await Verify(res, _verifySettings).UseFileName("response"); } + [Theory] + [ClassData(typeof(ValidMinMaxConstraints))] + public async Task AddField_Should_Accept_Valid_MinMax_Constraints( + string fieldType, + double? min, + double? max, + string testName) + { + var auth = await _client.Authorize(); + _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {auth?.Token}"); + + var modelRequest = new ModelRequest { ModelName = $"MinMaxTest{testName}", IsAuditableEntity = false }; + await _client.PostAsJsonAsync(_baseUrl, modelRequest); + + var fieldRequest = new FieldRequest + { + FieldName = "TestField", + FieldType = fieldType, + IsRequired = false, + Min = min, + Max = max + }; + + var res = await _client.PutAsJsonAsync($"{_baseUrl}/{modelRequest.ModelName}", fieldRequest); + var filePath = Path.Combine(_entitiesPath, $"{modelRequest.ModelName}.cs"); + var actual = await File.ReadAllTextAsync(filePath); + + _verifySettings.UseDirectory( + $"{_snapshotPath}/{nameof(AddField_Should_Accept_Valid_MinMax_Constraints)}/{testName}"); + await Verify(actual, _verifySettings).UseFileName("model"); + await Verify(res, _verifySettings).UseFileName("response"); + } + + [Theory] + [ClassData(typeof(InvalidMinMaxConstraints))] + public async Task AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints( + string fieldType, + double? min, + double? max, + string testName) + { + var auth = await _client.Authorize(); + _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {auth?.Token}"); + + var modelRequest = new ModelRequest { ModelName = $"InvalidMinMax{testName}", IsAuditableEntity = false }; + await _client.PostAsJsonAsync(_baseUrl, modelRequest); + + var fieldRequest = new FieldRequest + { + FieldName = "TestField", + FieldType = fieldType, + IsRequired = false, + Min = min, + Max = max + }; + + var res = await _client.PutAsJsonAsync($"{_baseUrl}/{modelRequest.ModelName}", fieldRequest); + + _verifySettings.UseDirectory( + $"{_snapshotPath}/{nameof(AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints)}/{testName}"); + await Verify(res, _verifySettings).UseFileName("response"); + } + + [Theory] + [ClassData(typeof(InvalidMinMaxConstraints))] + public async Task UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update( + string fieldType, + double? min, + double? max, + string testName) + { + var auth = await _client.Authorize(); + _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {auth?.Token}"); + + var modelRequest = new ModelRequest { ModelName = $"UpdateInvalidMinMax{testName}", IsAuditableEntity = false }; + await _client.PutAsJsonAsync(_baseUrl, modelRequest); + + var fieldRequest = new FieldRequest + { + FieldName = "TestField", + FieldType = fieldType, + IsRequired = false, + Min = 0, + Max = 100 + }; + await _client.PutAsJsonAsync($"{_baseUrl}/{modelRequest.ModelName}", fieldRequest); + + var updateRequest = new UpdateFieldRequest + { + OldFieldName = "TestField", + NewFieldName = "TestField", + FieldType = fieldType, + IsRequired = false, + Min = min, + Max = max + }; + + var res = await _client.PutAsJsonAsync($"{_baseUrl}/{modelRequest.ModelName}", updateRequest); + + _verifySettings.UseDirectory( + $"{_snapshotPath}/{nameof(UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update)}/{testName}"); + await Verify(res, _verifySettings).UseFileName("response"); + } + + [Theory] + [ClassData(typeof(ValidMinMaxConstraints))] + public async Task UpdateField_Should_Accept_Valid_MinMax_Update( + string fieldType, + double? min, + double? max, + string testName) + { + var auth = await _client.Authorize(); + _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {auth?.Token}"); + + var modelRequest = new ModelRequest { ModelName = $"UpdateValidMinMax{testName}", IsAuditableEntity = false }; + await _client.PostAsJsonAsync(_baseUrl, modelRequest); + + var fieldRequest = new FieldRequest + { + FieldName = "TestField", + FieldType = fieldType, + IsRequired = false, + Min = 0, + Max = 10 + }; + await _client.PutAsJsonAsync($"{_baseUrl}/{modelRequest.ModelName}", fieldRequest); + + var updateRequest = new UpdateFieldRequest + { + OldFieldName = "TestField", + NewFieldName = "TestField", + FieldType = fieldType, + IsRequired = false, + Min = min, + Max = max + }; + + var res = await _client.PostAsJsonAsync($"{_baseUrl}/{modelRequest.ModelName}", updateRequest); + var filePath = Path.Combine(_entitiesPath, $"{modelRequest.ModelName}.cs"); + var actual = await File.ReadAllTextAsync(filePath); + + _verifySettings.UseDirectory( + $"{_snapshotPath}/{nameof(UpdateField_Should_Accept_Valid_MinMax_Update)}/{testName}"); + await Verify(actual, _verifySettings).UseFileName("model"); + await Verify(res, _verifySettings).UseFileName("response"); + } + [Fact] public async Task DeleteModel_Should_Return_NotFound_If_Model_Does_Not_Exist() { diff --git a/Dappi.HeadlessCms.Tests/TestData/PropertyAndClassNames.cs b/Dappi.HeadlessCms.Tests/TestData/PropertyAndClassNames.cs index f283880..d3f9a99 100644 --- a/Dappi.HeadlessCms.Tests/TestData/PropertyAndClassNames.cs +++ b/Dappi.HeadlessCms.Tests/TestData/PropertyAndClassNames.cs @@ -49,4 +49,37 @@ public TestFieldTypeAndFieldName() } } + + public class ValidMinMaxConstraints : TheoryData + { + public ValidMinMaxConstraints() + { + Add("string", 0, 10, "StringMinMax"); + Add("string", 0, null, "StringMinOnly"); + Add("string", null, 50, "StringMaxOnly"); + + Add("int", -10, 10, "IntNegative"); + Add("int", 0, 100, "IntMinMax"); + Add("double", -99.5, 99.5, "DoubleMinMax"); + Add("float", 0.5, 100.5, "FloatMinMax"); + + Add("int", 5, 5, "IntEqual"); + } + } + + public class InvalidMinMaxConstraints : TheoryData + { + public InvalidMinMaxConstraints() + { + Add("string", -1, 10, "StringNegativeMin"); + Add("string", 5.5, 10, "StringDecimalMin"); + Add("string", 1, 10.5, "StringDecimalMax"); + Add("string", -5, -1, "StringBothNegative"); + + Add("int", 10, 5, "IntMinGreaterThanMax"); + Add("string", 50, 10, "StringMinGreaterThanMax"); + Add("double", 100.5, 50.5, "DoubleMinGreaterThanMax"); + Add("float", 100.5, 50.5, "FloatMinGreaterThanMax"); + } + } } \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/DoubleMinMax/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/DoubleMinMax/model.verified.txt new file mode 100644 index 0000000..b3f3781 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/DoubleMinMax/model.verified.txt @@ -0,0 +1,20 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Dappi.HeadlessCms.Models; +using Dappi.Core.Attributes; +using Dappi.HeadlessCms.Core.Attributes; +using Dappi.Core.Enums; + +namespace Entities +{ + [CcController] + public class MinMaxTestDoubleMinMax + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } + + [Range(-99.5, 99.5)] + public double? TestField { get; set; } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/DoubleMinMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/DoubleMinMax/response.verified.txt new file mode 100644 index 0000000..2a0cd9d --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/DoubleMinMax/response.verified.txt @@ -0,0 +1,13 @@ +{ + Status: 200 OK, + Content: { + Headers: { + Content-Length: 225, + Content-Type: application/json; charset=utf-8 + }, + Value: { + Message: Field 'TestField' of type 'double' added successfully to 'MinMaxTestDoubleMinMax' model., + FilePath: {CurrentDirectory}Entities/MinMaxTestDoubleMinMax.cs + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/FloatMinMax/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/FloatMinMax/model.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/FloatMinMax/model.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntEqual/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntEqual/model.verified.txt new file mode 100644 index 0000000..026fc15 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntEqual/model.verified.txt @@ -0,0 +1,20 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Dappi.HeadlessCms.Models; +using Dappi.Core.Attributes; +using Dappi.HeadlessCms.Core.Attributes; +using Dappi.Core.Enums; + +namespace Entities +{ + [CcController] + public class MinMaxTestIntEqual + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } + + [Range(5, 5)] + public int? TestField { get; set; } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntEqual/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntEqual/response.verified.txt new file mode 100644 index 0000000..735ab18 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntEqual/response.verified.txt @@ -0,0 +1,13 @@ +{ + Status: 200 OK, + Content: { + Headers: { + Content-Length: 214, + Content-Type: application/json; charset=utf-8 + }, + Value: { + Message: Field 'TestField' of type 'int' added successfully to 'MinMaxTestIntEqual' model., + FilePath: {CurrentDirectory}Entities/MinMaxTestIntEqual.cs + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntMinMax/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntMinMax/model.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntMinMax/model.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntNegative/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntNegative/model.verified.txt new file mode 100644 index 0000000..1f87df2 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntNegative/model.verified.txt @@ -0,0 +1,20 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Dappi.HeadlessCms.Models; +using Dappi.Core.Attributes; +using Dappi.HeadlessCms.Core.Attributes; +using Dappi.Core.Enums; + +namespace Entities +{ + [CcController] + public class MinMaxTestIntNegative + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } + + [Range(-10, 10)] + public int? TestField { get; set; } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntNegative/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntNegative/response.verified.txt new file mode 100644 index 0000000..9d68684 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntNegative/response.verified.txt @@ -0,0 +1,13 @@ +{ + Status: 200 OK, + Content: { + Headers: { + Content-Length: 220, + Content-Type: application/json; charset=utf-8 + }, + Value: { + Message: Field 'TestField' of type 'int' added successfully to 'MinMaxTestIntNegative' model., + FilePath: {CurrentDirectory}Entities/MinMaxTestIntNegative.cs + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMaxOnly/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMaxOnly/model.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMaxOnly/model.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMinMax/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMinMax/model.verified.txt new file mode 100644 index 0000000..f29eb38 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMinMax/model.verified.txt @@ -0,0 +1,20 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Dappi.HeadlessCms.Models; +using Dappi.Core.Attributes; +using Dappi.HeadlessCms.Core.Attributes; +using Dappi.Core.Enums; + +namespace Entities +{ + [CcController] + public class MinMaxTestStringMinMax + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } + + [Length(0, 10)] + public string? TestField { get; set; } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMinMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMinMax/response.verified.txt new file mode 100644 index 0000000..e2b0c42 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMinMax/response.verified.txt @@ -0,0 +1,13 @@ +{ + Status: 200 OK, + Content: { + Headers: { + Content-Length: 225, + Content-Type: application/json; charset=utf-8 + }, + Value: { + Message: Field 'TestField' of type 'string' added successfully to 'MinMaxTestStringMinMax' model., + FilePath: {CurrentDirectory}Entities/MinMaxTestStringMinMax.cs + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMinOnly/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMinOnly/model.verified.txt new file mode 100644 index 0000000..70c53f4 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMinOnly/model.verified.txt @@ -0,0 +1,20 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Dappi.HeadlessCms.Models; +using Dappi.Core.Attributes; +using Dappi.HeadlessCms.Core.Attributes; +using Dappi.Core.Enums; + +namespace Entities +{ + [CcController] + public class MinMaxTestStringMinOnly + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } + + [MinLength(0)] + public string? TestField { get; set; } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMinOnly/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMinOnly/response.verified.txt new file mode 100644 index 0000000..d9e1415 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMinOnly/response.verified.txt @@ -0,0 +1,13 @@ +{ + Status: 200 OK, + Content: { + Headers: { + Content-Length: 227, + Content-Type: application/json; charset=utf-8 + }, + Value: { + Message: Field 'TestField' of type 'string' added successfully to 'MinMaxTestStringMinOnly' model., + FilePath: {CurrentDirectory}Entities/MinMaxTestStringMinOnly.cs + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/DoubleMinGreaterThanMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/DoubleMinGreaterThanMax/response.verified.txt new file mode 100644 index 0000000..45238ae --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/DoubleMinGreaterThanMax/response.verified.txt @@ -0,0 +1,20 @@ +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 254, + Content-Type: application/problem+json; charset=utf-8 + }, + Value: { + type: https://tools.ietf.org/html/rfc9110#section-15.5.1, + title: One or more validation errors occurred., + status: 400, + errors: { + : [ + Min value cannot be greater than max value. + ] + }, + traceId: {Scrubbed} + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/FloatMinGreaterThanMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/FloatMinGreaterThanMax/response.verified.txt new file mode 100644 index 0000000..45238ae --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/FloatMinGreaterThanMax/response.verified.txt @@ -0,0 +1,20 @@ +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 254, + Content-Type: application/problem+json; charset=utf-8 + }, + Value: { + type: https://tools.ietf.org/html/rfc9110#section-15.5.1, + title: One or more validation errors occurred., + status: 400, + errors: { + : [ + Min value cannot be greater than max value. + ] + }, + traceId: {Scrubbed} + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/IntMinGreaterThanMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/IntMinGreaterThanMax/response.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/IntMinGreaterThanMax/response.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/StringBothNegative/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/StringBothNegative/response.verified.txt new file mode 100644 index 0000000..b2e2e9e --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/StringBothNegative/response.verified.txt @@ -0,0 +1,23 @@ +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 305, + Content-Type: application/problem+json; charset=utf-8 + }, + Value: { + type: https://tools.ietf.org/html/rfc9110#section-15.5.1, + title: One or more validation errors occurred., + status: 400, + errors: { + Max: [ + Max value is invalid for the field type. + ], + Min: [ + Min value is invalid for the field type. + ] + }, + traceId: {Scrubbed} + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/StringDecimalMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/StringDecimalMax/response.verified.txt new file mode 100644 index 0000000..4c02c84 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/StringDecimalMax/response.verified.txt @@ -0,0 +1,20 @@ +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 254, + Content-Type: application/problem+json; charset=utf-8 + }, + Value: { + type: https://tools.ietf.org/html/rfc9110#section-15.5.1, + title: One or more validation errors occurred., + status: 400, + errors: { + Max: [ + Max value is invalid for the field type. + ] + }, + traceId: {Scrubbed} + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/StringDecimalMin/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/StringDecimalMin/response.verified.txt new file mode 100644 index 0000000..1e49594 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/StringDecimalMin/response.verified.txt @@ -0,0 +1,20 @@ +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 254, + Content-Type: application/problem+json; charset=utf-8 + }, + Value: { + type: https://tools.ietf.org/html/rfc9110#section-15.5.1, + title: One or more validation errors occurred., + status: 400, + errors: { + Min: [ + Min value is invalid for the field type. + ] + }, + traceId: {Scrubbed} + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/StringMinGreaterThanMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/StringMinGreaterThanMax/response.verified.txt new file mode 100644 index 0000000..45238ae --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/StringMinGreaterThanMax/response.verified.txt @@ -0,0 +1,20 @@ +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 254, + Content-Type: application/problem+json; charset=utf-8 + }, + Value: { + type: https://tools.ietf.org/html/rfc9110#section-15.5.1, + title: One or more validation errors occurred., + status: 400, + errors: { + : [ + Min value cannot be greater than max value. + ] + }, + traceId: {Scrubbed} + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/StringNegativeMin/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/StringNegativeMin/response.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/StringNegativeMin/response.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/123InvalidClass/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/123InvalidClass/response.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/123InvalidClass/response.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Invalid Name/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Invalid Name/response.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Invalid Name/response.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Invalid@ClassName/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Invalid@ClassName/response.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Invalid@ClassName/response.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Property@/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Property@/response.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Property@/response.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/async/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/async/response.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/async/response.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/await/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/await/response.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/await/response.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/class!/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/class!/response.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/class!/response.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/class/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/class/response.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/class/response.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/int/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/int/response.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/int/response.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/public/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/public/response.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/public/response.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/var/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/var/response.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/var/response.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/void/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/void/response.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/void/response.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/DoubleMinMax/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/DoubleMinMax/model.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/DoubleMinMax/model.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/FloatMinMax/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/FloatMinMax/model.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/FloatMinMax/model.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntEqual/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntEqual/model.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntEqual/model.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntMinMax/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntMinMax/model.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntMinMax/model.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntNegative/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntNegative/model.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntNegative/model.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMaxOnly/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMaxOnly/model.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMaxOnly/model.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMinMax/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMinMax/model.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMinMax/model.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMinOnly/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMinOnly/model.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMinOnly/model.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/DoubleMinGreaterThanMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/DoubleMinGreaterThanMax/response.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/DoubleMinGreaterThanMax/response.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/FloatMinGreaterThanMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/FloatMinGreaterThanMax/response.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/FloatMinGreaterThanMax/response.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/IntMinGreaterThanMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/IntMinGreaterThanMax/response.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/IntMinGreaterThanMax/response.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringBothNegative/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringBothNegative/response.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringBothNegative/response.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringDecimalMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringDecimalMax/response.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringDecimalMax/response.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringDecimalMin/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringDecimalMin/response.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringDecimalMin/response.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringMinGreaterThanMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringMinGreaterThanMax/response.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringMinGreaterThanMax/response.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringNegativeMin/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringNegativeMin/response.verified.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringNegativeMin/response.verified.txt @@ -0,0 +1 @@ + \ No newline at end of file From 71baa375402607aaf8a1bded039e296686e1fab6 Mon Sep 17 00:00:00 2001 From: Mihail Date: Wed, 28 Jan 2026 16:39:06 +0100 Subject: [PATCH 08/11] add verified tests --- .../response.verified.txt | 21 ++++++++++++++++++- .../StringNegativeMin/response.verified.txt | 21 ++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/IntMinGreaterThanMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/IntMinGreaterThanMax/response.verified.txt index 5f28270..45238ae 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/IntMinGreaterThanMax/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/IntMinGreaterThanMax/response.verified.txt @@ -1 +1,20 @@ - \ No newline at end of file +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 254, + Content-Type: application/problem+json; charset=utf-8 + }, + Value: { + type: https://tools.ietf.org/html/rfc9110#section-15.5.1, + title: One or more validation errors occurred., + status: 400, + errors: { + : [ + Min value cannot be greater than max value. + ] + }, + traceId: {Scrubbed} + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/StringNegativeMin/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/StringNegativeMin/response.verified.txt index 5f28270..1e49594 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/StringNegativeMin/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Return_BadRequest_For_Invalid_MinMax_Constraints/StringNegativeMin/response.verified.txt @@ -1 +1,20 @@ - \ No newline at end of file +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 254, + Content-Type: application/problem+json; charset=utf-8 + }, + Value: { + type: https://tools.ietf.org/html/rfc9110#section-15.5.1, + title: One or more validation errors occurred., + status: 400, + errors: { + Min: [ + Min value is invalid for the field type. + ] + }, + traceId: {Scrubbed} + } + } +} \ No newline at end of file From d4681cdfa4cdf6940afe79217d3bba5bd09d4f9b Mon Sep 17 00:00:00 2001 From: Mihail Date: Thu, 29 Jan 2026 11:50:45 +0100 Subject: [PATCH 09/11] fix: change the content to include relative path --- .../Controllers/ModelsControllerTests.cs | 18 +++++++++++--- .../DoubleMinMax/response.verified.txt | 4 ++-- .../FloatMinMax/model.verified.txt | 21 +++++++++++++++- .../FloatMinMax/response.verified.txt | 13 ++++++++++ .../IntEqual/response.verified.txt | 4 ++-- .../IntMinMax/model.verified.txt | 21 +++++++++++++++- .../IntMinMax/response.verified.txt | 13 ++++++++++ .../IntNegative/response.verified.txt | 4 ++-- .../StringMaxOnly/model.verified.txt | 21 +++++++++++++++- .../StringMaxOnly/response.verified.txt | 13 ++++++++++ .../StringMinMax/response.verified.txt | 4 ++-- .../StringMinOnly/response.verified.txt | 4 ++-- .../response.verified.txt | 4 ++-- .../response.verified.txt | 4 ++-- .../response.verified.txt | 4 ++-- .../response.verified.txt | 4 ++-- .../TestBoolType/response.verified.txt | 4 ++-- .../TestDateOnlyType/response.verified.txt | 4 ++-- .../TestDateTimeType/response.verified.txt | 4 ++-- .../TestIntType/response.verified.txt | 4 ++-- .../TestStringType/response.verified.txt | 4 ++-- .../TestBoolType/response.verified.txt | 4 ++-- .../TestDateOnlyType/response.verified.txt | 4 ++-- .../TestDateTimeType/response.verified.txt | 4 ++-- .../TestIntType/response.verified.txt | 4 ++-- .../TestStringType/response.verified.txt | 4 ++-- .../123InvalidClass/response.verified.txt | 11 ++++++++- .../Invalid Name/response.verified.txt | 11 ++++++++- .../Invalid@ClassName/response.verified.txt | 11 ++++++++- .../Property@/response.verified.txt | 11 ++++++++- .../async/response.verified.txt | 11 ++++++++- .../await/response.verified.txt | 11 ++++++++- .../class!/response.verified.txt | 11 ++++++++- .../class/response.verified.txt | 11 ++++++++- .../int/response.verified.txt | 11 ++++++++- .../public/response.verified.txt | 11 ++++++++- .../var/response.verified.txt | 11 ++++++++- .../void/response.verified.txt | 11 ++++++++- .../response.verified.txt | 4 ++-- .../response.verified.txt | 4 ++-- .../response.verified.txt | 4 ++-- .../DoubleMinMax/model.verified.txt | 21 +++++++++++++++- .../DoubleMinMax/response.verified.txt | 13 ++++++++++ .../FloatMinMax/model.verified.txt | 21 +++++++++++++++- .../FloatMinMax/response.verified.txt | 13 ++++++++++ .../IntEqual/model.verified.txt | 21 +++++++++++++++- .../IntEqual/response.verified.txt | 13 ++++++++++ .../IntMinMax/model.verified.txt | 21 +++++++++++++++- .../IntMinMax/response.verified.txt | 13 ++++++++++ .../IntNegative/model.verified.txt | 21 +++++++++++++++- .../IntNegative/response.verified.txt | 13 ++++++++++ .../StringMaxOnly/model.verified.txt | 21 +++++++++++++++- .../StringMaxOnly/response.verified.txt | 13 ++++++++++ .../StringMinMax/model.verified.txt | 21 +++++++++++++++- .../StringMinMax/response.verified.txt | 13 ++++++++++ .../StringMinOnly/model.verified.txt | 21 +++++++++++++++- .../StringMinOnly/response.verified.txt | 13 ++++++++++ .../response.verified.txt | 21 +++++++++++++++- .../response.verified.txt | 21 +++++++++++++++- .../response.verified.txt | 21 +++++++++++++++- .../StringBothNegative/response.verified.txt | 24 ++++++++++++++++++- .../StringDecimalMax/response.verified.txt | 21 +++++++++++++++- .../StringDecimalMin/response.verified.txt | 21 +++++++++++++++- .../response.verified.txt | 21 +++++++++++++++- .../StringNegativeMin/response.verified.txt | 21 +++++++++++++++- .../Controllers/ModelsController.cs | 12 ++++++---- 66 files changed, 713 insertions(+), 82 deletions(-) create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/FloatMinMax/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntMinMax/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMaxOnly/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/DoubleMinMax/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/FloatMinMax/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntEqual/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntMinMax/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntNegative/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMaxOnly/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMinMax/response.verified.txt create mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMinOnly/response.verified.txt diff --git a/Dappi.HeadlessCms.Tests/Controllers/ModelsControllerTests.cs b/Dappi.HeadlessCms.Tests/Controllers/ModelsControllerTests.cs index c13b234..91f788e 100644 --- a/Dappi.HeadlessCms.Tests/Controllers/ModelsControllerTests.cs +++ b/Dappi.HeadlessCms.Tests/Controllers/ModelsControllerTests.cs @@ -1,3 +1,4 @@ +using System.Net.Http; using System.Net.Http.Json; using System.Text.RegularExpressions; using Dappi.HeadlessCms.Models; @@ -511,7 +512,7 @@ public async Task UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {auth?.Token}"); var modelRequest = new ModelRequest { ModelName = $"UpdateInvalidMinMax{testName}", IsAuditableEntity = false }; - await _client.PutAsJsonAsync(_baseUrl, modelRequest); + await _client.PostAsJsonAsync(_baseUrl, modelRequest); var fieldRequest = new FieldRequest { @@ -533,7 +534,7 @@ public async Task UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update Max = max }; - var res = await _client.PutAsJsonAsync($"{_baseUrl}/{modelRequest.ModelName}", updateRequest); + var res = await PatchAsJsonAsync(_client, $"{_baseUrl}/{modelRequest.ModelName}/fields", updateRequest); _verifySettings.UseDirectory( $"{_snapshotPath}/{nameof(UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update)}/{testName}"); @@ -574,7 +575,7 @@ public async Task UpdateField_Should_Accept_Valid_MinMax_Update( Max = max }; - var res = await _client.PostAsJsonAsync($"{_baseUrl}/{modelRequest.ModelName}", updateRequest); + var res = await PatchAsJsonAsync(_client, $"{_baseUrl}/{modelRequest.ModelName}/fields", updateRequest); var filePath = Path.Combine(_entitiesPath, $"{modelRequest.ModelName}.cs"); var actual = await File.ReadAllTextAsync(filePath); @@ -708,6 +709,17 @@ public async Task Other_Relations_Should_Not_Be_Deleted() await Verify(deleteRes, _verifySettings).UseFileName("response"); } + private static Task PatchAsJsonAsync(HttpClient client, string requestUri, T value) + { + var content = JsonContent.Create(value); + var request = new HttpRequestMessage(HttpMethod.Patch, requestUri) + { + Content = content + }; + + return client.SendAsync(request); + } + public void Dispose() { if (Directory.Exists(_entitiesPath)) diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/DoubleMinMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/DoubleMinMax/response.verified.txt index 2a0cd9d..9251f54 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/DoubleMinMax/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/DoubleMinMax/response.verified.txt @@ -2,12 +2,12 @@ Status: 200 OK, Content: { Headers: { - Content-Length: 225, + Content-Length: 150, Content-Type: application/json; charset=utf-8 }, Value: { Message: Field 'TestField' of type 'double' added successfully to 'MinMaxTestDoubleMinMax' model., - FilePath: {CurrentDirectory}Entities/MinMaxTestDoubleMinMax.cs + FilePath: Entities/MinMaxTestDoubleMinMax.cs } } } \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/FloatMinMax/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/FloatMinMax/model.verified.txt index 5f28270..9282cec 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/FloatMinMax/model.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/FloatMinMax/model.verified.txt @@ -1 +1,20 @@ - \ No newline at end of file +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Dappi.HeadlessCms.Models; +using Dappi.Core.Attributes; +using Dappi.HeadlessCms.Core.Attributes; +using Dappi.Core.Enums; + +namespace Entities +{ + [CcController] + public class MinMaxTestFloatMinMax + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } + + [Range(0.5, 100.5)] + public float? TestField { get; set; } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/FloatMinMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/FloatMinMax/response.verified.txt new file mode 100644 index 0000000..7bbf09b --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/FloatMinMax/response.verified.txt @@ -0,0 +1,13 @@ +{ + Status: 200 OK, + Content: { + Headers: { + Content-Length: 147, + Content-Type: application/json; charset=utf-8 + }, + Value: { + Message: Field 'TestField' of type 'float' added successfully to 'MinMaxTestFloatMinMax' model., + FilePath: Entities/MinMaxTestFloatMinMax.cs + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntEqual/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntEqual/response.verified.txt index 735ab18..e44423a 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntEqual/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntEqual/response.verified.txt @@ -2,12 +2,12 @@ Status: 200 OK, Content: { Headers: { - Content-Length: 214, + Content-Length: 139, Content-Type: application/json; charset=utf-8 }, Value: { Message: Field 'TestField' of type 'int' added successfully to 'MinMaxTestIntEqual' model., - FilePath: {CurrentDirectory}Entities/MinMaxTestIntEqual.cs + FilePath: Entities/MinMaxTestIntEqual.cs } } } \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntMinMax/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntMinMax/model.verified.txt index 5f28270..7502a5b 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntMinMax/model.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntMinMax/model.verified.txt @@ -1 +1,20 @@ - \ No newline at end of file +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Dappi.HeadlessCms.Models; +using Dappi.Core.Attributes; +using Dappi.HeadlessCms.Core.Attributes; +using Dappi.Core.Enums; + +namespace Entities +{ + [CcController] + public class MinMaxTestIntMinMax + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } + + [Range(0, 100)] + public int? TestField { get; set; } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntMinMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntMinMax/response.verified.txt new file mode 100644 index 0000000..658f7f3 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntMinMax/response.verified.txt @@ -0,0 +1,13 @@ +{ + Status: 200 OK, + Content: { + Headers: { + Content-Length: 141, + Content-Type: application/json; charset=utf-8 + }, + Value: { + Message: Field 'TestField' of type 'int' added successfully to 'MinMaxTestIntMinMax' model., + FilePath: Entities/MinMaxTestIntMinMax.cs + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntNegative/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntNegative/response.verified.txt index 9d68684..2bce190 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntNegative/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/IntNegative/response.verified.txt @@ -2,12 +2,12 @@ Status: 200 OK, Content: { Headers: { - Content-Length: 220, + Content-Length: 145, Content-Type: application/json; charset=utf-8 }, Value: { Message: Field 'TestField' of type 'int' added successfully to 'MinMaxTestIntNegative' model., - FilePath: {CurrentDirectory}Entities/MinMaxTestIntNegative.cs + FilePath: Entities/MinMaxTestIntNegative.cs } } } \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMaxOnly/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMaxOnly/model.verified.txt index 5f28270..086d226 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMaxOnly/model.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMaxOnly/model.verified.txt @@ -1 +1,20 @@ - \ No newline at end of file +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Dappi.HeadlessCms.Models; +using Dappi.Core.Attributes; +using Dappi.HeadlessCms.Core.Attributes; +using Dappi.Core.Enums; + +namespace Entities +{ + [CcController] + public class MinMaxTestStringMaxOnly + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } + + [MaxLength(50)] + public string? TestField { get; set; } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMaxOnly/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMaxOnly/response.verified.txt new file mode 100644 index 0000000..0d58d4a --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMaxOnly/response.verified.txt @@ -0,0 +1,13 @@ +{ + Status: 200 OK, + Content: { + Headers: { + Content-Length: 152, + Content-Type: application/json; charset=utf-8 + }, + Value: { + Message: Field 'TestField' of type 'string' added successfully to 'MinMaxTestStringMaxOnly' model., + FilePath: Entities/MinMaxTestStringMaxOnly.cs + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMinMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMinMax/response.verified.txt index e2b0c42..c6162ea 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMinMax/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMinMax/response.verified.txt @@ -2,12 +2,12 @@ Status: 200 OK, Content: { Headers: { - Content-Length: 225, + Content-Length: 150, Content-Type: application/json; charset=utf-8 }, Value: { Message: Field 'TestField' of type 'string' added successfully to 'MinMaxTestStringMinMax' model., - FilePath: {CurrentDirectory}Entities/MinMaxTestStringMinMax.cs + FilePath: Entities/MinMaxTestStringMinMax.cs } } } \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMinOnly/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMinOnly/response.verified.txt index d9e1415..0ddc9c1 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMinOnly/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Accept_Valid_MinMax_Constraints/StringMinOnly/response.verified.txt @@ -2,12 +2,12 @@ Status: 200 OK, Content: { Headers: { - Content-Length: 227, + Content-Length: 152, Content-Type: application/json; charset=utf-8 }, Value: { Message: Field 'TestField' of type 'string' added successfully to 'MinMaxTestStringMinOnly' model., - FilePath: {CurrentDirectory}Entities/MinMaxTestStringMinOnly.cs + FilePath: Entities/MinMaxTestStringMinOnly.cs } } } \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_ManyToMany_Relation_To_Models/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_ManyToMany_Relation_To_Models/response.verified.txt index 5b4580d..66ab6ad 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_ManyToMany_Relation_To_Models/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_ManyToMany_Relation_To_Models/response.verified.txt @@ -2,12 +2,12 @@ Status: 200 OK, Content: { Headers: { - Content-Length: 221, + Content-Length: 141, Content-Type: application/json; charset=utf-8 }, Value: { Message: Field 'TestRelation' of type 'ManyToMany' added successfully to 'TestClassSeven' model., - FilePath: {CurrentDirectory}Entities/TestClassSeven.cs + FilePath: Entities/TestClassSeven.cs } } } \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_ManyToOne_Relation_To_Models/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_ManyToOne_Relation_To_Models/response.verified.txt index 8b0e224..86ce4bd 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_ManyToOne_Relation_To_Models/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_ManyToOne_Relation_To_Models/response.verified.txt @@ -2,12 +2,12 @@ Status: 200 OK, Content: { Headers: { - Content-Length: 218, + Content-Length: 138, Content-Type: application/json; charset=utf-8 }, Value: { Message: Field 'TestRelation' of type 'ManyToOne' added successfully to 'TestClassFive' model., - FilePath: {CurrentDirectory}Entities/TestClassFive.cs + FilePath: Entities/TestClassFive.cs } } } \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_OneToMany_Relation_To_Models/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_OneToMany_Relation_To_Models/response.verified.txt index 0cad769..5c3a2bb 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_OneToMany_Relation_To_Models/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_OneToMany_Relation_To_Models/response.verified.txt @@ -2,12 +2,12 @@ Status: 200 OK, Content: { Headers: { - Content-Length: 220, + Content-Length: 140, Content-Type: application/json; charset=utf-8 }, Value: { Message: Field 'TestRelation' of type 'OneToMany' added successfully to 'TestClassThree' model., - FilePath: {CurrentDirectory}Entities/TestClassThree.cs + FilePath: Entities/TestClassThree.cs } } } \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_OneToOne_Relation_To_Models/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_OneToOne_Relation_To_Models/response.verified.txt index 5a2daac..95322bb 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_OneToOne_Relation_To_Models/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_OneToOne_Relation_To_Models/response.verified.txt @@ -2,12 +2,12 @@ Status: 200 OK, Content: { Headers: { - Content-Length: 215, + Content-Length: 135, Content-Type: application/json; charset=utf-8 }, Value: { Message: Field 'TestRelation' of type 'OneToOne' added successfully to 'TestClassOne' model., - FilePath: {CurrentDirectory}Entities/TestClassOne.cs + FilePath: Entities/TestClassOne.cs } } } \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Optional_Field_To_Model/TestBoolType/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Optional_Field_To_Model/TestBoolType/response.verified.txt index 819dcbf..6b4ab6e 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Optional_Field_To_Model/TestBoolType/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Optional_Field_To_Model/TestBoolType/response.verified.txt @@ -2,12 +2,12 @@ Status: 200 OK, Content: { Headers: { - Content-Length: 211, + Content-Length: 131, Content-Type: application/json; charset=utf-8 }, Value: { Message: Field 'TestBoolType' of type 'bool' added successfully to 'ProductThree' model., - FilePath: {CurrentDirectory}Entities/ProductThree.cs + FilePath: Entities/ProductThree.cs } } } \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Optional_Field_To_Model/TestDateOnlyType/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Optional_Field_To_Model/TestDateOnlyType/response.verified.txt index f1b8c20..647d499 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Optional_Field_To_Model/TestDateOnlyType/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Optional_Field_To_Model/TestDateOnlyType/response.verified.txt @@ -2,12 +2,12 @@ Status: 200 OK, Content: { Headers: { - Content-Length: 219, + Content-Length: 139, Content-Type: application/json; charset=utf-8 }, Value: { Message: Field 'TestDateOnlyType' of type 'DateOnly' added successfully to 'ProductThree' model., - FilePath: {CurrentDirectory}Entities/ProductThree.cs + FilePath: Entities/ProductThree.cs } } } \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Optional_Field_To_Model/TestDateTimeType/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Optional_Field_To_Model/TestDateTimeType/response.verified.txt index 1e81931..e04c55e 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Optional_Field_To_Model/TestDateTimeType/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Optional_Field_To_Model/TestDateTimeType/response.verified.txt @@ -2,12 +2,12 @@ Status: 200 OK, Content: { Headers: { - Content-Length: 219, + Content-Length: 139, Content-Type: application/json; charset=utf-8 }, Value: { Message: Field 'TestDateTimeType' of type 'DateTime' added successfully to 'ProductThree' model., - FilePath: {CurrentDirectory}Entities/ProductThree.cs + FilePath: Entities/ProductThree.cs } } } \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Optional_Field_To_Model/TestIntType/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Optional_Field_To_Model/TestIntType/response.verified.txt index bf280a3..31cf589 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Optional_Field_To_Model/TestIntType/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Optional_Field_To_Model/TestIntType/response.verified.txt @@ -2,12 +2,12 @@ Status: 200 OK, Content: { Headers: { - Content-Length: 209, + Content-Length: 129, Content-Type: application/json; charset=utf-8 }, Value: { Message: Field 'TestIntType' of type 'int' added successfully to 'ProductThree' model., - FilePath: {CurrentDirectory}Entities/ProductThree.cs + FilePath: Entities/ProductThree.cs } } } \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Optional_Field_To_Model/TestStringType/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Optional_Field_To_Model/TestStringType/response.verified.txt index 96e6884..43d0af2 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Optional_Field_To_Model/TestStringType/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Optional_Field_To_Model/TestStringType/response.verified.txt @@ -2,12 +2,12 @@ Status: 200 OK, Content: { Headers: { - Content-Length: 215, + Content-Length: 135, Content-Type: application/json; charset=utf-8 }, Value: { Message: Field 'TestStringType' of type 'string' added successfully to 'ProductThree' model., - FilePath: {CurrentDirectory}Entities/ProductThree.cs + FilePath: Entities/ProductThree.cs } } } \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Required_Field_To_Model/TestBoolType/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Required_Field_To_Model/TestBoolType/response.verified.txt index 140e20b..cc37016 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Required_Field_To_Model/TestBoolType/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Required_Field_To_Model/TestBoolType/response.verified.txt @@ -2,12 +2,12 @@ Status: 200 OK, Content: { Headers: { - Content-Length: 207, + Content-Length: 127, Content-Type: application/json; charset=utf-8 }, Value: { Message: Field 'TestBoolType' of type 'bool' added successfully to 'ProductTwo' model., - FilePath: {CurrentDirectory}Entities/ProductTwo.cs + FilePath: Entities/ProductTwo.cs } } } \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Required_Field_To_Model/TestDateOnlyType/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Required_Field_To_Model/TestDateOnlyType/response.verified.txt index 448474b..4d9a45c 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Required_Field_To_Model/TestDateOnlyType/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Required_Field_To_Model/TestDateOnlyType/response.verified.txt @@ -2,12 +2,12 @@ Status: 200 OK, Content: { Headers: { - Content-Length: 215, + Content-Length: 135, Content-Type: application/json; charset=utf-8 }, Value: { Message: Field 'TestDateOnlyType' of type 'DateOnly' added successfully to 'ProductTwo' model., - FilePath: {CurrentDirectory}Entities/ProductTwo.cs + FilePath: Entities/ProductTwo.cs } } } \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Required_Field_To_Model/TestDateTimeType/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Required_Field_To_Model/TestDateTimeType/response.verified.txt index 74fa01f..eec5810 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Required_Field_To_Model/TestDateTimeType/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Required_Field_To_Model/TestDateTimeType/response.verified.txt @@ -2,12 +2,12 @@ Status: 200 OK, Content: { Headers: { - Content-Length: 215, + Content-Length: 135, Content-Type: application/json; charset=utf-8 }, Value: { Message: Field 'TestDateTimeType' of type 'DateTime' added successfully to 'ProductTwo' model., - FilePath: {CurrentDirectory}Entities/ProductTwo.cs + FilePath: Entities/ProductTwo.cs } } } \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Required_Field_To_Model/TestIntType/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Required_Field_To_Model/TestIntType/response.verified.txt index b481ae1..30f0c07 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Required_Field_To_Model/TestIntType/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Required_Field_To_Model/TestIntType/response.verified.txt @@ -2,12 +2,12 @@ Status: 200 OK, Content: { Headers: { - Content-Length: 205, + Content-Length: 125, Content-Type: application/json; charset=utf-8 }, Value: { Message: Field 'TestIntType' of type 'int' added successfully to 'ProductTwo' model., - FilePath: {CurrentDirectory}Entities/ProductTwo.cs + FilePath: Entities/ProductTwo.cs } } } \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Required_Field_To_Model/TestStringType/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Required_Field_To_Model/TestStringType/response.verified.txt index 62f23ff..3b8d10d 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Required_Field_To_Model/TestStringType/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/AddField_Should_Add_Required_Field_To_Model/TestStringType/response.verified.txt @@ -2,12 +2,12 @@ Status: 200 OK, Content: { Headers: { - Content-Length: 211, + Content-Length: 131, Content-Type: application/json; charset=utf-8 }, Value: { Message: Field 'TestStringType' of type 'string' added successfully to 'ProductTwo' model., - FilePath: {CurrentDirectory}Entities/ProductTwo.cs + FilePath: Entities/ProductTwo.cs } } } \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/123InvalidClass/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/123InvalidClass/response.verified.txt index 5f28270..3618292 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/123InvalidClass/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/123InvalidClass/response.verified.txt @@ -1 +1,10 @@ - \ No newline at end of file +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 22, + Content-Type: text/plain; charset=utf-8 + }, + Value: Model name is invalid. + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Invalid Name/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Invalid Name/response.verified.txt index 5f28270..3618292 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Invalid Name/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Invalid Name/response.verified.txt @@ -1 +1,10 @@ - \ No newline at end of file +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 22, + Content-Type: text/plain; charset=utf-8 + }, + Value: Model name is invalid. + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Invalid@ClassName/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Invalid@ClassName/response.verified.txt index 5f28270..3618292 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Invalid@ClassName/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Invalid@ClassName/response.verified.txt @@ -1 +1,10 @@ - \ No newline at end of file +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 22, + Content-Type: text/plain; charset=utf-8 + }, + Value: Model name is invalid. + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Property@/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Property@/response.verified.txt index 5f28270..3618292 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Property@/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Property@/response.verified.txt @@ -1 +1,10 @@ - \ No newline at end of file +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 22, + Content-Type: text/plain; charset=utf-8 + }, + Value: Model name is invalid. + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/async/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/async/response.verified.txt index 5f28270..3618292 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/async/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/async/response.verified.txt @@ -1 +1,10 @@ - \ No newline at end of file +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 22, + Content-Type: text/plain; charset=utf-8 + }, + Value: Model name is invalid. + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/await/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/await/response.verified.txt index 5f28270..3618292 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/await/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/await/response.verified.txt @@ -1 +1,10 @@ - \ No newline at end of file +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 22, + Content-Type: text/plain; charset=utf-8 + }, + Value: Model name is invalid. + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/class!/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/class!/response.verified.txt index 5f28270..3618292 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/class!/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/class!/response.verified.txt @@ -1 +1,10 @@ - \ No newline at end of file +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 22, + Content-Type: text/plain; charset=utf-8 + }, + Value: Model name is invalid. + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/class/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/class/response.verified.txt index 5f28270..3618292 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/class/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/class/response.verified.txt @@ -1 +1,10 @@ - \ No newline at end of file +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 22, + Content-Type: text/plain; charset=utf-8 + }, + Value: Model name is invalid. + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/int/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/int/response.verified.txt index 5f28270..3618292 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/int/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/int/response.verified.txt @@ -1 +1,10 @@ - \ No newline at end of file +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 22, + Content-Type: text/plain; charset=utf-8 + }, + Value: Model name is invalid. + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/public/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/public/response.verified.txt index 5f28270..3618292 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/public/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/public/response.verified.txt @@ -1 +1,10 @@ - \ No newline at end of file +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 22, + Content-Type: text/plain; charset=utf-8 + }, + Value: Model name is invalid. + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/var/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/var/response.verified.txt index 5f28270..3618292 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/var/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/var/response.verified.txt @@ -1 +1,10 @@ - \ No newline at end of file +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 22, + Content-Type: text/plain; charset=utf-8 + }, + Value: Model name is invalid. + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/void/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/void/response.verified.txt index 5f28270..3618292 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/void/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/void/response.verified.txt @@ -1 +1,10 @@ - \ No newline at end of file +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 22, + Content-Type: text/plain; charset=utf-8 + }, + Value: Model name is invalid. + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/DeleteModel_Should_Delete_Model_File/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/DeleteModel_Should_Delete_Model_File/response.verified.txt index 656a5ec..2667671 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/DeleteModel_Should_Delete_Model_File/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/DeleteModel_Should_Delete_Model_File/response.verified.txt @@ -2,12 +2,12 @@ Status: 200 OK, Content: { Headers: { - Content-Length: 180, + Content-Length: 100, Content-Type: application/json; charset=utf-8 }, Value: { Message: Model 'TestDeleteModel' deleted successfully., - FilePath: {CurrentDirectory}Entities/TestDeleteModel.cs + FilePath: Entities/TestDeleteModel.cs } } } \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/DeleteModel_Should_Delete_Relations_And_References/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/DeleteModel_Should_Delete_Relations_And_References/response.verified.txt index f85b280..91ecf30 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/DeleteModel_Should_Delete_Relations_And_References/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/DeleteModel_Should_Delete_Relations_And_References/response.verified.txt @@ -2,12 +2,12 @@ Status: 200 OK, Content: { Headers: { - Content-Length: 158, + Content-Length: 78, Content-Type: application/json; charset=utf-8 }, Value: { Message: Model 'User' deleted successfully., - FilePath: {CurrentDirectory}Entities/User.cs + FilePath: Entities/User.cs } } } \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/Other_Relations_Should_Not_Be_Deleted/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/Other_Relations_Should_Not_Be_Deleted/response.verified.txt index f85b280..91ecf30 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/Other_Relations_Should_Not_Be_Deleted/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/Other_Relations_Should_Not_Be_Deleted/response.verified.txt @@ -2,12 +2,12 @@ Status: 200 OK, Content: { Headers: { - Content-Length: 158, + Content-Length: 78, Content-Type: application/json; charset=utf-8 }, Value: { Message: Model 'User' deleted successfully., - FilePath: {CurrentDirectory}Entities/User.cs + FilePath: Entities/User.cs } } } \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/DoubleMinMax/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/DoubleMinMax/model.verified.txt index 5f28270..06f2ba0 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/DoubleMinMax/model.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/DoubleMinMax/model.verified.txt @@ -1 +1,20 @@ - \ No newline at end of file +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Dappi.HeadlessCms.Models; +using Dappi.Core.Attributes; +using Dappi.HeadlessCms.Core.Attributes; +using Dappi.Core.Enums; + +namespace Entities +{ + [CcController] + public class UpdateValidMinMaxDoubleMinMax + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } + + [Range(-99.5, 99.5)] + public double? TestField { get; set; } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/DoubleMinMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/DoubleMinMax/response.verified.txt new file mode 100644 index 0000000..eb9297b --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/DoubleMinMax/response.verified.txt @@ -0,0 +1,13 @@ +{ + Status: 200 OK, + Content: { + Headers: { + Content-Length: 155, + Content-Type: application/json; charset=utf-8 + }, + Value: { + Message: Field 'TestField' updated successfully to 'TestField' in 'UpdateValidMinMaxDoubleMinMax' model., + FilePath: UpdateValidMinMaxDoubleMinMax.cs + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/FloatMinMax/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/FloatMinMax/model.verified.txt index 5f28270..db1ce3e 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/FloatMinMax/model.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/FloatMinMax/model.verified.txt @@ -1 +1,20 @@ - \ No newline at end of file +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Dappi.HeadlessCms.Models; +using Dappi.Core.Attributes; +using Dappi.HeadlessCms.Core.Attributes; +using Dappi.Core.Enums; + +namespace Entities +{ + [CcController] + public class UpdateValidMinMaxFloatMinMax + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } + + [Range(0.5, 100.5)] + public float? TestField { get; set; } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/FloatMinMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/FloatMinMax/response.verified.txt new file mode 100644 index 0000000..ef4a777 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/FloatMinMax/response.verified.txt @@ -0,0 +1,13 @@ +{ + Status: 200 OK, + Content: { + Headers: { + Content-Length: 153, + Content-Type: application/json; charset=utf-8 + }, + Value: { + Message: Field 'TestField' updated successfully to 'TestField' in 'UpdateValidMinMaxFloatMinMax' model., + FilePath: UpdateValidMinMaxFloatMinMax.cs + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntEqual/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntEqual/model.verified.txt index 5f28270..90b8ea1 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntEqual/model.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntEqual/model.verified.txt @@ -1 +1,20 @@ - \ No newline at end of file +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Dappi.HeadlessCms.Models; +using Dappi.Core.Attributes; +using Dappi.HeadlessCms.Core.Attributes; +using Dappi.Core.Enums; + +namespace Entities +{ + [CcController] + public class UpdateValidMinMaxIntEqual + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } + + [Range(5, 5)] + public int? TestField { get; set; } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntEqual/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntEqual/response.verified.txt new file mode 100644 index 0000000..b0bd0e7 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntEqual/response.verified.txt @@ -0,0 +1,13 @@ +{ + Status: 200 OK, + Content: { + Headers: { + Content-Length: 147, + Content-Type: application/json; charset=utf-8 + }, + Value: { + Message: Field 'TestField' updated successfully to 'TestField' in 'UpdateValidMinMaxIntEqual' model., + FilePath: UpdateValidMinMaxIntEqual.cs + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntMinMax/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntMinMax/model.verified.txt index 5f28270..e513fc6 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntMinMax/model.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntMinMax/model.verified.txt @@ -1 +1,20 @@ - \ No newline at end of file +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Dappi.HeadlessCms.Models; +using Dappi.Core.Attributes; +using Dappi.HeadlessCms.Core.Attributes; +using Dappi.Core.Enums; + +namespace Entities +{ + [CcController] + public class UpdateValidMinMaxIntMinMax + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } + + [Range(0, 100)] + public int? TestField { get; set; } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntMinMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntMinMax/response.verified.txt new file mode 100644 index 0000000..e027422 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntMinMax/response.verified.txt @@ -0,0 +1,13 @@ +{ + Status: 200 OK, + Content: { + Headers: { + Content-Length: 149, + Content-Type: application/json; charset=utf-8 + }, + Value: { + Message: Field 'TestField' updated successfully to 'TestField' in 'UpdateValidMinMaxIntMinMax' model., + FilePath: UpdateValidMinMaxIntMinMax.cs + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntNegative/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntNegative/model.verified.txt index 5f28270..40fa8bf 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntNegative/model.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntNegative/model.verified.txt @@ -1 +1,20 @@ - \ No newline at end of file +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Dappi.HeadlessCms.Models; +using Dappi.Core.Attributes; +using Dappi.HeadlessCms.Core.Attributes; +using Dappi.Core.Enums; + +namespace Entities +{ + [CcController] + public class UpdateValidMinMaxIntNegative + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } + + [Range(-10, 10)] + public int? TestField { get; set; } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntNegative/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntNegative/response.verified.txt new file mode 100644 index 0000000..f6f6226 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/IntNegative/response.verified.txt @@ -0,0 +1,13 @@ +{ + Status: 200 OK, + Content: { + Headers: { + Content-Length: 153, + Content-Type: application/json; charset=utf-8 + }, + Value: { + Message: Field 'TestField' updated successfully to 'TestField' in 'UpdateValidMinMaxIntNegative' model., + FilePath: UpdateValidMinMaxIntNegative.cs + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMaxOnly/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMaxOnly/model.verified.txt index 5f28270..a17673b 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMaxOnly/model.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMaxOnly/model.verified.txt @@ -1 +1,20 @@ - \ No newline at end of file +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Dappi.HeadlessCms.Models; +using Dappi.Core.Attributes; +using Dappi.HeadlessCms.Core.Attributes; +using Dappi.Core.Enums; + +namespace Entities +{ + [CcController] + public class UpdateValidMinMaxStringMaxOnly + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } + + [MaxLength(50)] + public string? TestField { get; set; } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMaxOnly/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMaxOnly/response.verified.txt new file mode 100644 index 0000000..601ca9d --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMaxOnly/response.verified.txt @@ -0,0 +1,13 @@ +{ + Status: 200 OK, + Content: { + Headers: { + Content-Length: 157, + Content-Type: application/json; charset=utf-8 + }, + Value: { + Message: Field 'TestField' updated successfully to 'TestField' in 'UpdateValidMinMaxStringMaxOnly' model., + FilePath: UpdateValidMinMaxStringMaxOnly.cs + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMinMax/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMinMax/model.verified.txt index 5f28270..58bf8b0 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMinMax/model.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMinMax/model.verified.txt @@ -1 +1,20 @@ - \ No newline at end of file +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Dappi.HeadlessCms.Models; +using Dappi.Core.Attributes; +using Dappi.HeadlessCms.Core.Attributes; +using Dappi.Core.Enums; + +namespace Entities +{ + [CcController] + public class UpdateValidMinMaxStringMinMax + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } + + [Length(0, 10)] + public string? TestField { get; set; } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMinMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMinMax/response.verified.txt new file mode 100644 index 0000000..292ddbe --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMinMax/response.verified.txt @@ -0,0 +1,13 @@ +{ + Status: 200 OK, + Content: { + Headers: { + Content-Length: 155, + Content-Type: application/json; charset=utf-8 + }, + Value: { + Message: Field 'TestField' updated successfully to 'TestField' in 'UpdateValidMinMaxStringMinMax' model., + FilePath: UpdateValidMinMaxStringMinMax.cs + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMinOnly/model.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMinOnly/model.verified.txt index 5f28270..b57a6a6 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMinOnly/model.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMinOnly/model.verified.txt @@ -1 +1,20 @@ - \ No newline at end of file +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Dappi.HeadlessCms.Models; +using Dappi.Core.Attributes; +using Dappi.HeadlessCms.Core.Attributes; +using Dappi.Core.Enums; + +namespace Entities +{ + [CcController] + public class UpdateValidMinMaxStringMinOnly + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } + + [MinLength(0)] + public string? TestField { get; set; } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMinOnly/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMinOnly/response.verified.txt new file mode 100644 index 0000000..48941e0 --- /dev/null +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Accept_Valid_MinMax_Update/StringMinOnly/response.verified.txt @@ -0,0 +1,13 @@ +{ + Status: 200 OK, + Content: { + Headers: { + Content-Length: 157, + Content-Type: application/json; charset=utf-8 + }, + Value: { + Message: Field 'TestField' updated successfully to 'TestField' in 'UpdateValidMinMaxStringMinOnly' model., + FilePath: UpdateValidMinMaxStringMinOnly.cs + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/DoubleMinGreaterThanMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/DoubleMinGreaterThanMax/response.verified.txt index 5f28270..45238ae 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/DoubleMinGreaterThanMax/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/DoubleMinGreaterThanMax/response.verified.txt @@ -1 +1,20 @@ - \ No newline at end of file +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 254, + Content-Type: application/problem+json; charset=utf-8 + }, + Value: { + type: https://tools.ietf.org/html/rfc9110#section-15.5.1, + title: One or more validation errors occurred., + status: 400, + errors: { + : [ + Min value cannot be greater than max value. + ] + }, + traceId: {Scrubbed} + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/FloatMinGreaterThanMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/FloatMinGreaterThanMax/response.verified.txt index 5f28270..45238ae 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/FloatMinGreaterThanMax/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/FloatMinGreaterThanMax/response.verified.txt @@ -1 +1,20 @@ - \ No newline at end of file +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 254, + Content-Type: application/problem+json; charset=utf-8 + }, + Value: { + type: https://tools.ietf.org/html/rfc9110#section-15.5.1, + title: One or more validation errors occurred., + status: 400, + errors: { + : [ + Min value cannot be greater than max value. + ] + }, + traceId: {Scrubbed} + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/IntMinGreaterThanMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/IntMinGreaterThanMax/response.verified.txt index 5f28270..45238ae 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/IntMinGreaterThanMax/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/IntMinGreaterThanMax/response.verified.txt @@ -1 +1,20 @@ - \ No newline at end of file +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 254, + Content-Type: application/problem+json; charset=utf-8 + }, + Value: { + type: https://tools.ietf.org/html/rfc9110#section-15.5.1, + title: One or more validation errors occurred., + status: 400, + errors: { + : [ + Min value cannot be greater than max value. + ] + }, + traceId: {Scrubbed} + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringBothNegative/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringBothNegative/response.verified.txt index 5f28270..b2e2e9e 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringBothNegative/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringBothNegative/response.verified.txt @@ -1 +1,23 @@ - \ No newline at end of file +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 305, + Content-Type: application/problem+json; charset=utf-8 + }, + Value: { + type: https://tools.ietf.org/html/rfc9110#section-15.5.1, + title: One or more validation errors occurred., + status: 400, + errors: { + Max: [ + Max value is invalid for the field type. + ], + Min: [ + Min value is invalid for the field type. + ] + }, + traceId: {Scrubbed} + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringDecimalMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringDecimalMax/response.verified.txt index 5f28270..4c02c84 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringDecimalMax/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringDecimalMax/response.verified.txt @@ -1 +1,20 @@ - \ No newline at end of file +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 254, + Content-Type: application/problem+json; charset=utf-8 + }, + Value: { + type: https://tools.ietf.org/html/rfc9110#section-15.5.1, + title: One or more validation errors occurred., + status: 400, + errors: { + Max: [ + Max value is invalid for the field type. + ] + }, + traceId: {Scrubbed} + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringDecimalMin/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringDecimalMin/response.verified.txt index 5f28270..1e49594 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringDecimalMin/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringDecimalMin/response.verified.txt @@ -1 +1,20 @@ - \ No newline at end of file +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 254, + Content-Type: application/problem+json; charset=utf-8 + }, + Value: { + type: https://tools.ietf.org/html/rfc9110#section-15.5.1, + title: One or more validation errors occurred., + status: 400, + errors: { + Min: [ + Min value is invalid for the field type. + ] + }, + traceId: {Scrubbed} + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringMinGreaterThanMax/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringMinGreaterThanMax/response.verified.txt index 5f28270..45238ae 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringMinGreaterThanMax/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringMinGreaterThanMax/response.verified.txt @@ -1 +1,20 @@ - \ No newline at end of file +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 254, + Content-Type: application/problem+json; charset=utf-8 + }, + Value: { + type: https://tools.ietf.org/html/rfc9110#section-15.5.1, + title: One or more validation errors occurred., + status: 400, + errors: { + : [ + Min value cannot be greater than max value. + ] + }, + traceId: {Scrubbed} + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringNegativeMin/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringNegativeMin/response.verified.txt index 5f28270..1e49594 100644 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringNegativeMin/response.verified.txt +++ b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/UpdateField_Should_Return_BadRequest_For_Invalid_MinMax_Update/StringNegativeMin/response.verified.txt @@ -1 +1,20 @@ - \ No newline at end of file +{ + Status: 400 Bad Request, + Content: { + Headers: { + Content-Length: 254, + Content-Type: application/problem+json; charset=utf-8 + }, + Value: { + type: https://tools.ietf.org/html/rfc9110#section-15.5.1, + title: One or more validation errors occurred., + status: 400, + errors: { + Min: [ + Min value is invalid for the field type. + ] + }, + traceId: {Scrubbed} + } + } +} \ No newline at end of file diff --git a/Dappi.HeadlessCms/Controllers/ModelsController.cs b/Dappi.HeadlessCms/Controllers/ModelsController.cs index e75e4f9..b661fa8 100644 --- a/Dappi.HeadlessCms/Controllers/ModelsController.cs +++ b/Dappi.HeadlessCms/Controllers/ModelsController.cs @@ -137,7 +137,11 @@ public async Task DeleteModel(string modelName) await _contentTypeChangesService.AddContentTypeChangeAsync(modelName, new Dictionary(), ContentTypeState.PendingDelete); - return Ok(new { Message = $"Model '{modelName}' deleted successfully.", FilePath = modelFilePath }); + return Ok(new + { + Message = $"Model '{modelName}' deleted successfully.", + FilePath = Path.GetRelativePath(Directory.GetCurrentDirectory(), modelFilePath) + }); } [HttpPut("{modelName}")] @@ -252,7 +256,7 @@ await _contentTypeChangesService.UpdateContentTypeChangeFieldsAsync(request.Rela { Message = $"Field '{request.FieldName}' of type '{request.FieldType}' added successfully to '{modelName}' model.", - FilePath = modelFilePath + FilePath = Path.GetRelativePath(Directory.GetCurrentDirectory(), modelFilePath) }); } @@ -370,7 +374,7 @@ public async Task UpdateField(string modelName, [FromBody] Update return Ok(new { Message = $"Field '{request.OldFieldName}' updated successfully to '{request.NewFieldName}' in '{modelName}' model.", - FilePath = modelFilePath + FilePath = Path.GetRelativePath(_entitiesFolderPath, modelFilePath) }); } @@ -419,7 +423,7 @@ public async Task DeleteField(string modelName, string fieldName) return Ok(new { Message = $"Field '{fieldName}' deleted successfully from '{modelName}' model.", - FilePath = modelFilePath + FilePath = Path.GetRelativePath(_entitiesFolderPath, modelFilePath) }); } From b4f5018ab2bb0d48e2498c6487e6fa00ba405fde Mon Sep 17 00:00:00 2001 From: Mihail Date: Thu, 29 Jan 2026 12:51:08 +0100 Subject: [PATCH 10/11] Revert the name of the CreateModel_Should_Return_BadRequest_If_Model_Name_Is_Invalid test --- Dappi.HeadlessCms.Tests/Controllers/ModelsControllerTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dappi.HeadlessCms.Tests/Controllers/ModelsControllerTests.cs b/Dappi.HeadlessCms.Tests/Controllers/ModelsControllerTests.cs index 91f788e..93c2cb1 100644 --- a/Dappi.HeadlessCms.Tests/Controllers/ModelsControllerTests.cs +++ b/Dappi.HeadlessCms.Tests/Controllers/ModelsControllerTests.cs @@ -70,7 +70,7 @@ public async Task CreateModel_Should_Return_BadRequest_If_Model_Name_Is_Empty() [Theory] [ClassData(typeof(InvalidPropertyTypesAndClassNames))] - public async Task CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid(string modelName) + public async Task CreateModel_Should_Return_BadRequest_If_Model_Name_Is_Invalid(string modelName) { var auth = await _client.Authorize(); _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {auth?.Token}"); @@ -79,7 +79,7 @@ public async Task CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_I var res = await _client.PostAsJsonAsync(_baseUrl, request); _verifySettings.UseDirectory( - $"{_snapshotPath}/{nameof(CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid)}/{modelName}"); + $"{_snapshotPath}/{nameof(CreateModel_Should_Return_BadRequest_If_Model_Name_Is_Invalid)}/{modelName}"); await Verify(res, _verifySettings).UseFileName("response"); } From 8a481b14dee2861b4c80a45bccd02ec8ae8a3313 Mon Sep 17 00:00:00 2001 From: Mihail Date: Thu, 29 Jan 2026 14:08:35 +0100 Subject: [PATCH 11/11] remove CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid snapshots --- .../123InvalidClass/response.verified.txt | 10 ---------- .../Invalid Name/response.verified.txt | 10 ---------- .../Invalid@ClassName/response.verified.txt | 10 ---------- .../Property@/response.verified.txt | 10 ---------- .../async/response.verified.txt | 10 ---------- .../await/response.verified.txt | 10 ---------- .../class!/response.verified.txt | 10 ---------- .../class/response.verified.txt | 10 ---------- .../int/response.verified.txt | 10 ---------- .../public/response.verified.txt | 10 ---------- .../var/response.verified.txt | 10 ---------- .../void/response.verified.txt | 10 ---------- 12 files changed, 120 deletions(-) delete mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/123InvalidClass/response.verified.txt delete mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Invalid Name/response.verified.txt delete mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Invalid@ClassName/response.verified.txt delete mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Property@/response.verified.txt delete mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/async/response.verified.txt delete mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/await/response.verified.txt delete mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/class!/response.verified.txt delete mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/class/response.verified.txt delete mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/int/response.verified.txt delete mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/public/response.verified.txt delete mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/var/response.verified.txt delete mode 100644 Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/void/response.verified.txt diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/123InvalidClass/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/123InvalidClass/response.verified.txt deleted file mode 100644 index 3618292..0000000 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/123InvalidClass/response.verified.txt +++ /dev/null @@ -1,10 +0,0 @@ -{ - Status: 400 Bad Request, - Content: { - Headers: { - Content-Length: 22, - Content-Type: text/plain; charset=utf-8 - }, - Value: Model name is invalid. - } -} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Invalid Name/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Invalid Name/response.verified.txt deleted file mode 100644 index 3618292..0000000 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Invalid Name/response.verified.txt +++ /dev/null @@ -1,10 +0,0 @@ -{ - Status: 400 Bad Request, - Content: { - Headers: { - Content-Length: 22, - Content-Type: text/plain; charset=utf-8 - }, - Value: Model name is invalid. - } -} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Invalid@ClassName/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Invalid@ClassName/response.verified.txt deleted file mode 100644 index 3618292..0000000 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Invalid@ClassName/response.verified.txt +++ /dev/null @@ -1,10 +0,0 @@ -{ - Status: 400 Bad Request, - Content: { - Headers: { - Content-Length: 22, - Content-Type: text/plain; charset=utf-8 - }, - Value: Model name is invalid. - } -} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Property@/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Property@/response.verified.txt deleted file mode 100644 index 3618292..0000000 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/Property@/response.verified.txt +++ /dev/null @@ -1,10 +0,0 @@ -{ - Status: 400 Bad Request, - Content: { - Headers: { - Content-Length: 22, - Content-Type: text/plain; charset=utf-8 - }, - Value: Model name is invalid. - } -} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/async/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/async/response.verified.txt deleted file mode 100644 index 3618292..0000000 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/async/response.verified.txt +++ /dev/null @@ -1,10 +0,0 @@ -{ - Status: 400 Bad Request, - Content: { - Headers: { - Content-Length: 22, - Content-Type: text/plain; charset=utf-8 - }, - Value: Model name is invalid. - } -} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/await/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/await/response.verified.txt deleted file mode 100644 index 3618292..0000000 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/await/response.verified.txt +++ /dev/null @@ -1,10 +0,0 @@ -{ - Status: 400 Bad Request, - Content: { - Headers: { - Content-Length: 22, - Content-Type: text/plain; charset=utf-8 - }, - Value: Model name is invalid. - } -} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/class!/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/class!/response.verified.txt deleted file mode 100644 index 3618292..0000000 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/class!/response.verified.txt +++ /dev/null @@ -1,10 +0,0 @@ -{ - Status: 400 Bad Request, - Content: { - Headers: { - Content-Length: 22, - Content-Type: text/plain; charset=utf-8 - }, - Value: Model name is invalid. - } -} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/class/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/class/response.verified.txt deleted file mode 100644 index 3618292..0000000 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/class/response.verified.txt +++ /dev/null @@ -1,10 +0,0 @@ -{ - Status: 400 Bad Request, - Content: { - Headers: { - Content-Length: 22, - Content-Type: text/plain; charset=utf-8 - }, - Value: Model name is invalid. - } -} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/int/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/int/response.verified.txt deleted file mode 100644 index 3618292..0000000 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/int/response.verified.txt +++ /dev/null @@ -1,10 +0,0 @@ -{ - Status: 400 Bad Request, - Content: { - Headers: { - Content-Length: 22, - Content-Type: text/plain; charset=utf-8 - }, - Value: Model name is invalid. - } -} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/public/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/public/response.verified.txt deleted file mode 100644 index 3618292..0000000 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/public/response.verified.txt +++ /dev/null @@ -1,10 +0,0 @@ -{ - Status: 400 Bad Request, - Content: { - Headers: { - Content-Length: 22, - Content-Type: text/plain; charset=utf-8 - }, - Value: Model name is invalid. - } -} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/var/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/var/response.verified.txt deleted file mode 100644 index 3618292..0000000 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/var/response.verified.txt +++ /dev/null @@ -1,10 +0,0 @@ -{ - Status: 400 Bad Request, - Content: { - Headers: { - Content-Length: 22, - Content-Type: text/plain; charset=utf-8 - }, - Value: Model name is invalid. - } -} \ No newline at end of file diff --git a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/void/response.verified.txt b/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/void/response.verified.txt deleted file mode 100644 index 3618292..0000000 --- a/Dappi.HeadlessCms.Tests/snapshots/ModelsControllerTests/CreateModel_Should_Return_BadRequest_If_Min_Property_Type_Is_Invalid/void/response.verified.txt +++ /dev/null @@ -1,10 +0,0 @@ -{ - Status: 400 Bad Request, - Content: { - Headers: { - Content-Length: 22, - Content-Type: text/plain; charset=utf-8 - }, - Value: Model name is invalid. - } -} \ No newline at end of file