From 555191bf9960516ab91be12f98a478f1ad32150a Mon Sep 17 00:00:00 2001 From: Youssef Fahmy Date: Thu, 30 Apr 2026 14:10:38 +0200 Subject: [PATCH 1/4] Update MoqVersion to latest --- eng/Versions.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/Versions.props b/eng/Versions.props index 0dc354210d65..f0082d7d90cd 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -159,7 +159,7 @@ $(MessagePackVersion) 1.2.0 $(ModelContextProtocolVersion) - 4.10.0 + 4.20.72 0.11.2 2.2.1 1.0.2 From cd9ce289ee29113f8995fd75c8d36475d29038ae Mon Sep 17 00:00:00 2001 From: Youssef Fahmy Date: Thu, 30 Apr 2026 14:25:09 +0200 Subject: [PATCH 2/4] Update Versions.props --- eng/Versions.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/Versions.props b/eng/Versions.props index f0082d7d90cd..c33d84408a46 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -138,7 +138,7 @@ 1.11.4 0.9.9 0.13.0 - 4.2.1 + 5.2.1 2.3.0 6.0.0 2.15.0 From b178af71dcd1abbbbe587295bc23db02aa0c94db Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Fri, 1 May 2026 19:12:01 +0200 Subject: [PATCH 3/4] Fix test due to bad nullability annotations in Moq --- .../Validation/DefaultObjectValidatorTests.cs | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Mvc/Mvc.Core/test/ModelBinding/Validation/DefaultObjectValidatorTests.cs b/src/Mvc/Mvc.Core/test/ModelBinding/Validation/DefaultObjectValidatorTests.cs index f9cc5ea0e7ab..f77076cc5268 100644 --- a/src/Mvc/Mvc.Core/test/ModelBinding/Validation/DefaultObjectValidatorTests.cs +++ b/src/Mvc/Mvc.Core/test/ModelBinding/Validation/DefaultObjectValidatorTests.cs @@ -591,19 +591,10 @@ public void Validate_ComplexType_IValidatableObject_CanUseRequestServices() var validator = CreateValidator(); - var model = new Mock(); - model - .Setup(x => x.Validate(It.IsAny())) - .Callback((ValidationContext context) => - { - var receivedService = context.GetService(); - Assert.Equal(service.Object, receivedService); - receivedService.DoSomething(); - }) - .Returns(new List()); + var model = new MockedValidatableObject(service.Object); // Act - validator.Validate(actionContext, validationState, prefix: null, model: model.Object); + validator.Validate(actionContext, validationState, prefix: null, model: model); // Assert service.Verify(); @@ -1687,4 +1678,20 @@ public DepthObject Instance } } } + + private sealed class MockedValidatableObject : IValidatableObject + { + private readonly IExampleService _exampleService; + + public MockedValidatableObject(IExampleService exampleService) + => _exampleService = exampleService; + + public IEnumerable Validate(ValidationContext validationContext) + { + var receivedService = validationContext.GetService(); + Assert.Equal(_exampleService, receivedService); + + return new List(); + } + } } From b06d6e4131660a5baf141e80f295cf2881a0dd42 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 4 May 2026 09:29:58 +0200 Subject: [PATCH 4/4] Fix test --- .../test/ModelBinding/Validation/DefaultObjectValidatorTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mvc/Mvc.Core/test/ModelBinding/Validation/DefaultObjectValidatorTests.cs b/src/Mvc/Mvc.Core/test/ModelBinding/Validation/DefaultObjectValidatorTests.cs index f77076cc5268..2bf92b4fb7c2 100644 --- a/src/Mvc/Mvc.Core/test/ModelBinding/Validation/DefaultObjectValidatorTests.cs +++ b/src/Mvc/Mvc.Core/test/ModelBinding/Validation/DefaultObjectValidatorTests.cs @@ -1690,7 +1690,7 @@ public IEnumerable Validate(ValidationContext validationContex { var receivedService = validationContext.GetService(); Assert.Equal(_exampleService, receivedService); - + receivedService.DoSomething(); return new List(); } }