From b889c398c7f3a64b1a7baf4f0ca3b797c7cb50f8 Mon Sep 17 00:00:00 2001 From: Rockford Lhotka Date: Wed, 26 Mar 2025 16:05:14 -0700 Subject: [PATCH 01/12] #4492 Allow disabling scan for data annotations attributes --- .../Csla.test/BizRules/BusinessRuleTests.cs | 72 +++++++++++++++++++ Source/Csla/ApplicationContext.cs | 13 +++- .../Csla/Configuration/Fluent/CslaOptions.cs | 16 +++++ Source/Csla/Core/BusinessBase.cs | 3 +- 4 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 Source/Csla.test/BizRules/BusinessRuleTests.cs diff --git a/Source/Csla.test/BizRules/BusinessRuleTests.cs b/Source/Csla.test/BizRules/BusinessRuleTests.cs new file mode 100644 index 0000000000..3b3bda67e1 --- /dev/null +++ b/Source/Csla.test/BizRules/BusinessRuleTests.cs @@ -0,0 +1,72 @@ +//----------------------------------------------------------------------- +// +// Copyright (c) Marimer LLC. All rights reserved. +// Website: https://cslanet.com +// +// no summary +//----------------------------------------------------------------------- +using System.ComponentModel.DataAnnotations; +using Csla.Configuration; +using Csla.TestHelpers; +using FluentAssertions; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Csla.Test.BizRules +{ + [TestClass] + public class BusinessRuleTests + { + private static TestDIContext _testDIContext; + + [ClassInitialize] + public static void ClassInitialize(TestContext context) + { + _testDIContext = TestDIContextFactory.CreateDefaultContext(); + } + + [TestInitialize] + public void Initialize() + { + TestResults.Reinitialise(); + } + + [TestMethod] + public void DefaultDataAnnotationsScan() + { + var portal = _testDIContext.ServiceProvider.GetRequiredService>(); + var obj = portal.Create(); + obj.Name = ""; + obj.IsValid.Should().BeFalse(); + } + + [TestMethod] + public void DisableDataAnnotationsScan() + { + var options = _testDIContext.ServiceProvider.GetRequiredService(); + options.ScanForDataAnnotations(false); + + var portal = _testDIContext.ServiceProvider.GetRequiredService>(); + var obj = portal.Create(); + obj.Name = ""; + obj.IsValid.Should().BeTrue(); + } + } + + public class TestBusinessRule : BusinessBase + { + public static readonly PropertyInfo NameProperty = RegisterProperty(nameof(Name)); + [Required] + public string Name + { + get => GetProperty(NameProperty); + set => SetProperty(NameProperty, value); + } + + [Create] + private void Create() + { + BusinessRules.CheckRules(); + } + } +} diff --git a/Source/Csla/ApplicationContext.cs b/Source/Csla/ApplicationContext.cs index aa00aef5ec..0cfbf25dbb 100644 --- a/Source/Csla/ApplicationContext.cs +++ b/Source/Csla/ApplicationContext.cs @@ -13,6 +13,7 @@ using System.ComponentModel; using Csla.Server; using System.Diagnostics.CodeAnalysis; +using Csla.Configuration; namespace Csla { @@ -26,12 +27,19 @@ public class ApplicationContext /// Creates a new instance of the type /// /// - public ApplicationContext(ApplicationContextAccessor applicationContextAccessor) + /// + public ApplicationContext(ApplicationContextAccessor applicationContextAccessor, CslaOptions options) { ApplicationContextAccessor = applicationContextAccessor; ApplicationContextAccessor.GetContextManager().ApplicationContext = this; + Options = options; } + /// + /// Holds configuration options for the CSLA framework. + /// + public CslaOptions Options { get; } + internal ApplicationContextAccessor ApplicationContextAccessor { get; set; } /// @@ -196,8 +204,7 @@ public PropertyChangedModes PropertyChangedMode { if (!_propertyChangedModeSet) { - var options = GetRequiredService(); - _propertyChangedMode = options.BindingOptions.PropertyChangedMode; + _propertyChangedMode = Options.BindingOptions.PropertyChangedMode; _propertyChangedModeSet = true; } return _propertyChangedMode; diff --git a/Source/Csla/Configuration/Fluent/CslaOptions.cs b/Source/Csla/Configuration/Fluent/CslaOptions.cs index 56ba7c16e7..6ad4b1b3ab 100644 --- a/Source/Csla/Configuration/Fluent/CslaOptions.cs +++ b/Source/Csla/Configuration/Fluent/CslaOptions.cs @@ -64,6 +64,22 @@ public CslaOptions RegisterPropertyInfoFactory< return this; } + /// + /// Indicates whether the data annotations scan is disabled. + /// + public bool ScanDataAnnotations { get; private set; } = true; + + /// + /// Configures the scanning for data annotations based on the provided flag. + /// + /// Indicates whether to disable the scanning for data annotations. + /// Returns the current instance of CoreOptions. + public CslaOptions ScanForDataAnnotations(bool flag) + { + ScanDataAnnotations = flag; + return this; + } + /// /// Gets the SecurityOptions instance. /// diff --git a/Source/Csla/Core/BusinessBase.cs b/Source/Csla/Core/BusinessBase.cs index ab4c2c5b75..aa36dec951 100644 --- a/Source/Csla/Core/BusinessBase.cs +++ b/Source/Csla/Core/BusinessBase.cs @@ -1158,7 +1158,8 @@ void IHostRules.AllRulesComplete() /// protected virtual void AddBusinessRules() { - BusinessRules.AddDataAnnotations(); + if (ApplicationContext.Options.ScanDataAnnotations) + BusinessRules.AddDataAnnotations(); } /// From 0ca2c3a433a6538822b89d0d0b59d137a43e32b2 Mon Sep 17 00:00:00 2001 From: Rockford Lhotka Date: Wed, 26 Mar 2025 16:18:13 -0700 Subject: [PATCH 02/12] Fix test broken due to rule caching --- .../Csla.test/BizRules/BusinessRuleTests.cs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Source/Csla.test/BizRules/BusinessRuleTests.cs b/Source/Csla.test/BizRules/BusinessRuleTests.cs index 3b3bda67e1..6482f5b343 100644 --- a/Source/Csla.test/BizRules/BusinessRuleTests.cs +++ b/Source/Csla.test/BizRules/BusinessRuleTests.cs @@ -46,7 +46,8 @@ public void DisableDataAnnotationsScan() var options = _testDIContext.ServiceProvider.GetRequiredService(); options.ScanForDataAnnotations(false); - var portal = _testDIContext.ServiceProvider.GetRequiredService>(); + // use different type to avoid caching + var portal = _testDIContext.ServiceProvider.GetRequiredService>(); var obj = portal.Create(); obj.Name = ""; obj.IsValid.Should().BeTrue(); @@ -69,4 +70,21 @@ private void Create() BusinessRules.CheckRules(); } } + + public class TestBusinessRule2 : BusinessBase + { + public static readonly PropertyInfo NameProperty = RegisterProperty(nameof(Name)); + [Required] + public string Name + { + get => GetProperty(NameProperty); + set => SetProperty(NameProperty, value); + } + + [Create] + private void Create() + { + BusinessRules.CheckRules(); + } + } } From 0f26fbbeec650331d617d4f0225cda53915f740c Mon Sep 17 00:00:00 2001 From: Rockford Lhotka Date: Wed, 26 Mar 2025 16:42:49 -0700 Subject: [PATCH 03/12] Fix comments --- Source/Csla/Configuration/Fluent/CoreOptions.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Csla/Configuration/Fluent/CoreOptions.cs b/Source/Csla/Configuration/Fluent/CoreOptions.cs index 53d2300141..c9dca2e1a9 100644 --- a/Source/Csla/Configuration/Fluent/CoreOptions.cs +++ b/Source/Csla/Configuration/Fluent/CoreOptions.cs @@ -1,15 +1,15 @@ //----------------------------------------------------------------------- -// +// // Copyright (c) Marimer LLC. All rights reserved. // Website: https://cslanet.com // -// Options for data binding +// Internal class used to configure CSLA .NET //----------------------------------------------------------------------- namespace Csla.Configuration { /// - /// Options for data binding + /// Internal class used to configure CSLA .NET /// public class CoreOptions; } From aa301d3372de70674e53237abfade92a4bb08053 Mon Sep 17 00:00:00 2001 From: Rockford Lhotka Date: Fri, 28 Mar 2025 10:24:21 -0700 Subject: [PATCH 04/12] #4615 Ensure ApplicationContext isn't null during initialization --- Source/Csla.test/Basic/BasicTests.cs | 3 +- Source/Csla.test/Basic/CollectionTests.cs | 3 +- Source/Csla.test/Basic/RootList.cs | 15 +++--- .../Csla.test/BizRules/BusinessRuleTests.cs | 2 +- .../ChildInterfaceTests.cs | 48 +++++++++++++++++-- Source/Csla.test/Nullable/NullableObject.cs | 7 +-- Source/Csla/BusinessBindingListBase.cs | 2 + Source/Csla/BusinessListBase.cs | 2 + Source/Csla/Core/BusinessBase.cs | 2 + Source/Csla/DynamicBindingListBase.cs | 2 + Source/Csla/DynamicListBase.cs | 24 +++++----- 11 files changed, 79 insertions(+), 31 deletions(-) diff --git a/Source/Csla.test/Basic/BasicTests.cs b/Source/Csla.test/Basic/BasicTests.cs index db7cd55737..0760fd26e2 100644 --- a/Source/Csla.test/Basic/BasicTests.cs +++ b/Source/Csla.test/Basic/BasicTests.cs @@ -384,7 +384,8 @@ public void DeletedListTestWithCancel() public void SuppressListChangedEventsDoNotRaiseCollectionChanged() { bool changed = false; - var obj = new RootList(); + var portal = _testDIContext.CreateDataPortal(); + var obj = portal.Create(); obj.ListChanged += (_, _) => { changed = true; diff --git a/Source/Csla.test/Basic/CollectionTests.cs b/Source/Csla.test/Basic/CollectionTests.cs index c1abb47c84..c755d6dcb9 100644 --- a/Source/Csla.test/Basic/CollectionTests.cs +++ b/Source/Csla.test/Basic/CollectionTests.cs @@ -42,7 +42,8 @@ public void SetLast() [TestMethod] public void RootListGetRuleDescriptions() { - RootList list = new RootList(); + var portal = _testDIContext.CreateDataPortal(); + var list = portal.Create(); RootListChild child = list.AddNew(); string[] rules = child.GetRuleDescriptions(); } diff --git a/Source/Csla.test/Basic/RootList.cs b/Source/Csla.test/Basic/RootList.cs index baa72d4d57..1bec5124e2 100644 --- a/Source/Csla.test/Basic/RootList.cs +++ b/Source/Csla.test/Basic/RootList.cs @@ -11,19 +11,20 @@ namespace Csla.Test.Basic [Serializable] public class RootList : BusinessBindingListBase { - public RootList() - { - AllowEdit = true; - AllowNew = true; - AllowRemove = true; - } - protected override object AddNewCore() { RootListChild child = new RootListChild(); Add(child); return child; } + + [Create] + private void Create() + { + AllowNew = true; + AllowEdit = true; + AllowRemove = true; + } } [Serializable] diff --git a/Source/Csla.test/BizRules/BusinessRuleTests.cs b/Source/Csla.test/BizRules/BusinessRuleTests.cs index 6482f5b343..efeea49cc0 100644 --- a/Source/Csla.test/BizRules/BusinessRuleTests.cs +++ b/Source/Csla.test/BizRules/BusinessRuleTests.cs @@ -1,5 +1,5 @@ //----------------------------------------------------------------------- -// +// // Copyright (c) Marimer LLC. All rights reserved. // Website: https://cslanet.com // diff --git a/Source/Csla.test/ChildrenByInterface/ChildInterfaceTests.cs b/Source/Csla.test/ChildrenByInterface/ChildInterfaceTests.cs index 42a1750579..04994f3d30 100644 --- a/Source/Csla.test/ChildrenByInterface/ChildInterfaceTests.cs +++ b/Source/Csla.test/ChildrenByInterface/ChildInterfaceTests.cs @@ -6,6 +6,7 @@ // no summary //----------------------------------------------------------------------- +using Csla.TestHelpers; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Csla.Test.ChildrenByInterface @@ -13,15 +14,33 @@ namespace Csla.Test.ChildrenByInterface [TestClass] public class ChildInterfaceTests { + private static TestDIContext _testDIContext; + + [ClassInitialize] + public static void ClassInitialize(TestContext context) + { + _testDIContext = TestDIContextFactory.CreateDefaultContext(); + } + + [TestInitialize] + public void Initialize() + { + TestResults.Reinitialise(); + } + [TestMethod] public void AddItems() { - ItemList list = + var portal = _testDIContext.CreateDataPortal(); + var child1Portal = _testDIContext.CreateDataPortal(); + var child2Portal = _testDIContext.CreateDataPortal(); + var list = portal.Create(); + list.AddRange( [ - new Item1(), - new Item2() + child1Portal.Create(), + child2Portal.Create() - ]; + ]); Assert.IsTrue(list[0] is Item1, "First element should be Item1"); Assert.IsTrue(list[1] is Item2, "Second element should be Item2"); @@ -42,6 +61,11 @@ protected override object GetIdValue() { return 0; } + + [Create] + private void Create() + { + } } [Serializable] @@ -56,8 +80,22 @@ protected override object GetIdValue() { return 0; } + + [Create] + private void Create() + { + } } [Serializable] - public class ItemList : BusinessBindingListBase; + public class ItemList : BusinessBindingListBase + { + [Create] + private void Create() + { + AllowNew = true; + AllowEdit = true; + AllowRemove = true; + } + } } \ No newline at end of file diff --git a/Source/Csla.test/Nullable/NullableObject.cs b/Source/Csla.test/Nullable/NullableObject.cs index 5863faadcb..04ac4876e6 100644 --- a/Source/Csla.test/Nullable/NullableObject.cs +++ b/Source/Csla.test/Nullable/NullableObject.cs @@ -73,11 +73,7 @@ public static void DeleteNullableObject(string name, IDataPortal dataPortal.Delete(new Criteria(name)); } - public NullableObject() - { - AddBusinessRules(); - } - + [Create] private void DataPortal_Create(object criteria) { Criteria crit = (Criteria)(criteria); @@ -86,6 +82,7 @@ private void DataPortal_Create(object criteria) TestResults.Add("NullableObject", "Created"); } + [Fetch] protected void DataPortal_Fetch(object criteria) { Criteria crit = (Criteria)(criteria); diff --git a/Source/Csla/BusinessBindingListBase.cs b/Source/Csla/BusinessBindingListBase.cs index 8502275793..66e27179a1 100644 --- a/Source/Csla/BusinessBindingListBase.cs +++ b/Source/Csla/BusinessBindingListBase.cs @@ -55,6 +55,8 @@ ApplicationContext IUseApplicationContext.ApplicationContext set { ApplicationContext = value; + if (ApplicationContext == null) + throw new InvalidOperationException("ApplicationContext == null"); InitializeIdentity(); Initialize(); AllowNew = true; diff --git a/Source/Csla/BusinessListBase.cs b/Source/Csla/BusinessListBase.cs index c5e049b1a0..6a58a30a04 100644 --- a/Source/Csla/BusinessListBase.cs +++ b/Source/Csla/BusinessListBase.cs @@ -62,6 +62,8 @@ ApplicationContext IUseApplicationContext.ApplicationContext set { ApplicationContext = value; + if (ApplicationContext == null) + throw new InvalidOperationException("ApplicationContext == null"); InitializeIdentity(); Initialize(); AllowNew = true; diff --git a/Source/Csla/Core/BusinessBase.cs b/Source/Csla/Core/BusinessBase.cs index aa36dec951..285b3608f9 100644 --- a/Source/Csla/Core/BusinessBase.cs +++ b/Source/Csla/Core/BusinessBase.cs @@ -64,6 +64,8 @@ protected BusinessBase() /// protected override void OnApplicationContextSet() { + if (ApplicationContext == null) + throw new InvalidOperationException("ApplicationContext == null"); InitializeIdentity(); Initialize(); InitializeBusinessRules(); diff --git a/Source/Csla/DynamicBindingListBase.cs b/Source/Csla/DynamicBindingListBase.cs index 544dfe571f..1d1bf8408a 100644 --- a/Source/Csla/DynamicBindingListBase.cs +++ b/Source/Csla/DynamicBindingListBase.cs @@ -70,6 +70,8 @@ ApplicationContext IUseApplicationContext.ApplicationContext set { ApplicationContext = value; + if (ApplicationContext == null) + throw new InvalidOperationException("ApplicationContext == null"); InitializeIdentity(); Initialize(); AllowNew = true; diff --git a/Source/Csla/DynamicListBase.cs b/Source/Csla/DynamicListBase.cs index 2352320160..1dcfd4128f 100644 --- a/Source/Csla/DynamicListBase.cs +++ b/Source/Csla/DynamicListBase.cs @@ -57,21 +57,23 @@ public abstract class DynamicListBase< IUseApplicationContext where T : IEditableBusinessObject, IUndoableObject, ISavable, IMobileObject, IBusinessObject { - /// - /// Creates an instance of the type. - /// - public DynamicListBase() - { - InitializeIdentity(); - Initialize(); - AllowNew = true; - } - /// /// Gets the current ApplicationContext /// protected ApplicationContext ApplicationContext { get; private set; } - ApplicationContext IUseApplicationContext.ApplicationContext { get => ApplicationContext; set => ApplicationContext = value; } + ApplicationContext IUseApplicationContext.ApplicationContext + { + get => ApplicationContext; + set + { + ApplicationContext = value; + if (ApplicationContext == null) + throw new InvalidOperationException("ApplicationContext == null"); + InitializeIdentity(); + Initialize(); + AllowNew = true; + } + } #region Initialize From 0285c4c98d810e37bf6ea5bcd73bc75353a9ea96 Mon Sep 17 00:00:00 2001 From: Rockford Lhotka Date: Fri, 28 Mar 2025 10:36:45 -0700 Subject: [PATCH 05/12] Fix broken test --- Source/csla.netcore.test/Basic/BasicTests.cs | 6 ++++-- Source/csla.netcore.test/Basic/RootList.cs | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Source/csla.netcore.test/Basic/BasicTests.cs b/Source/csla.netcore.test/Basic/BasicTests.cs index 1fd965cf31..9f0eb24228 100644 --- a/Source/csla.netcore.test/Basic/BasicTests.cs +++ b/Source/csla.netcore.test/Basic/BasicTests.cs @@ -367,12 +367,14 @@ public void SuppressListChangedEventsDoNotRaiseCollectionChanged() TestResults.Reinitialise(); bool changed = false; - var obj = new RootList(); + var portal = _testDIContext.CreateDataPortal(); + var childPortal = _testDIContext.CreateDataPortal(); + var obj = portal.Create(); obj.ListChanged += (_, _) => { changed = true; }; - var child = new RootListChild(); // object is marked as child + var child = childPortal.Create(); // object is marked as child Assert.IsTrue(obj.RaiseListChangedEvents); using (obj.SuppressListChangedEvents) diff --git a/Source/csla.netcore.test/Basic/RootList.cs b/Source/csla.netcore.test/Basic/RootList.cs index 9b2dd02eb8..517bb68338 100644 --- a/Source/csla.netcore.test/Basic/RootList.cs +++ b/Source/csla.netcore.test/Basic/RootList.cs @@ -42,7 +42,8 @@ public string[] GetRuleDescriptions() return result; } - public RootListChild() + [Create] + private void Create() { MarkAsChild(); } From 92adaeac23dd0b29013bf7957bb8ac5ef8a7da92 Mon Sep 17 00:00:00 2001 From: Rockford lhotka Date: Sun, 30 Mar 2025 15:19:31 -0500 Subject: [PATCH 06/12] Add missing test config --- Source/Csla.Windows.Tests/test.runsettings | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Source/Csla.Windows.Tests/test.runsettings diff --git a/Source/Csla.Windows.Tests/test.runsettings b/Source/Csla.Windows.Tests/test.runsettings new file mode 100644 index 0000000000..878ea11ef8 --- /dev/null +++ b/Source/Csla.Windows.Tests/test.runsettings @@ -0,0 +1,6 @@ + + + + 1 + + \ No newline at end of file From 4ec927997dad39682c749b3090a0b65cf1d36132 Mon Sep 17 00:00:00 2001 From: Rockford lhotka Date: Sun, 30 Mar 2025 15:19:51 -0500 Subject: [PATCH 07/12] #4492 Make Options property internal --- Source/Csla/ApplicationContext.cs | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/Source/Csla/ApplicationContext.cs b/Source/Csla/ApplicationContext.cs index 0cfbf25dbb..d9ea520d9f 100644 --- a/Source/Csla/ApplicationContext.cs +++ b/Source/Csla/ApplicationContext.cs @@ -33,12 +33,10 @@ public ApplicationContext(ApplicationContextAccessor applicationContextAccessor, ApplicationContextAccessor = applicationContextAccessor; ApplicationContextAccessor.GetContextManager().ApplicationContext = this; Options = options; + PropertyChangedMode = Options.BindingOptions.PropertyChangedMode; } - /// - /// Holds configuration options for the CSLA framework. - /// - public CslaOptions Options { get; } + internal CslaOptions Options { get; } internal ApplicationContextAccessor ApplicationContextAccessor { get; set; } @@ -191,25 +189,11 @@ public enum ExecutionLocations Server } - private PropertyChangedModes _propertyChangedMode; - private bool _propertyChangedModeSet; - /// /// Gets or sets a value specifying how CSLA .NET should /// raise PropertyChanged events. /// - public PropertyChangedModes PropertyChangedMode - { - get - { - if (!_propertyChangedModeSet) - { - _propertyChangedMode = Options.BindingOptions.PropertyChangedMode; - _propertyChangedModeSet = true; - } - return _propertyChangedMode; - } - } + public PropertyChangedModes PropertyChangedMode { get; } /// /// Enum representing the way in which CSLA .NET From 551ffc524d3883ae9896ad4ca8d64bba1ebc349c Mon Sep 17 00:00:00 2001 From: Rockford Lhotka Date: Thu, 15 May 2025 15:41:24 -0500 Subject: [PATCH 08/12] #4492 Revert breaking change --- Source/Csla/ApplicationContext.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Source/Csla/ApplicationContext.cs b/Source/Csla/ApplicationContext.cs index d9ea520d9f..1091af6789 100644 --- a/Source/Csla/ApplicationContext.cs +++ b/Source/Csla/ApplicationContext.cs @@ -27,12 +27,11 @@ public class ApplicationContext /// Creates a new instance of the type /// /// - /// - public ApplicationContext(ApplicationContextAccessor applicationContextAccessor, CslaOptions options) + public ApplicationContext(ApplicationContextAccessor applicationContextAccessor) { ApplicationContextAccessor = applicationContextAccessor; ApplicationContextAccessor.GetContextManager().ApplicationContext = this; - Options = options; + Options = GetRequiredService(); PropertyChangedMode = Options.BindingOptions.PropertyChangedMode; } From 47c8467254364a68e862ffaa24726a7494c27a56 Mon Sep 17 00:00:00 2001 From: Rockford Lhotka Date: Thu, 15 May 2025 15:43:37 -0500 Subject: [PATCH 09/12] #4492 Fix comment --- Source/Csla/Configuration/Fluent/CslaOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Csla/Configuration/Fluent/CslaOptions.cs b/Source/Csla/Configuration/Fluent/CslaOptions.cs index 6ad4b1b3ab..b8be7c81b6 100644 --- a/Source/Csla/Configuration/Fluent/CslaOptions.cs +++ b/Source/Csla/Configuration/Fluent/CslaOptions.cs @@ -65,7 +65,7 @@ public CslaOptions RegisterPropertyInfoFactory< } /// - /// Indicates whether the data annotations scan is disabled. + /// Indicates whether the data annotations scan is enabled. /// public bool ScanDataAnnotations { get; private set; } = true; From 40c3f176727b29c36bb748485ee49d7a71efc0a4 Mon Sep 17 00:00:00 2001 From: Rockford Lhotka Date: Thu, 15 May 2025 15:53:49 -0500 Subject: [PATCH 10/12] #4492 Don't cache options object --- Source/Csla/ApplicationContext.cs | 6 ++---- Source/Csla/Core/BusinessBase.cs | 3 ++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Source/Csla/ApplicationContext.cs b/Source/Csla/ApplicationContext.cs index 1091af6789..3d58cf06ad 100644 --- a/Source/Csla/ApplicationContext.cs +++ b/Source/Csla/ApplicationContext.cs @@ -31,12 +31,10 @@ public ApplicationContext(ApplicationContextAccessor applicationContextAccessor) { ApplicationContextAccessor = applicationContextAccessor; ApplicationContextAccessor.GetContextManager().ApplicationContext = this; - Options = GetRequiredService(); - PropertyChangedMode = Options.BindingOptions.PropertyChangedMode; + var options = GetRequiredService(); + PropertyChangedMode = options.BindingOptions.PropertyChangedMode; } - internal CslaOptions Options { get; } - internal ApplicationContextAccessor ApplicationContextAccessor { get; set; } /// diff --git a/Source/Csla/Core/BusinessBase.cs b/Source/Csla/Core/BusinessBase.cs index 214cfddb9d..384d7c709f 100644 --- a/Source/Csla/Core/BusinessBase.cs +++ b/Source/Csla/Core/BusinessBase.cs @@ -1160,7 +1160,8 @@ void IHostRules.AllRulesComplete() /// protected virtual void AddBusinessRules() { - if (ApplicationContext.Options.ScanDataAnnotations) + var options = ApplicationContext.GetRequiredService(); + if (options.ScanDataAnnotations) BusinessRules.AddDataAnnotations(); } From 03d9e810d00208611b2827cd3b96f0c1644fbcf2 Mon Sep 17 00:00:00 2001 From: Rockford Lhotka Date: Thu, 15 May 2025 15:54:11 -0500 Subject: [PATCH 11/12] Suppress warnings about async --- Source/Csla.test/DataPortal/AsynchDataPortalTest.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Source/Csla.test/DataPortal/AsynchDataPortalTest.cs b/Source/Csla.test/DataPortal/AsynchDataPortalTest.cs index 04a3555baf..46f123d29f 100644 --- a/Source/Csla.test/DataPortal/AsynchDataPortalTest.cs +++ b/Source/Csla.test/DataPortal/AsynchDataPortalTest.cs @@ -99,6 +99,7 @@ public async Task CreateAsync_WithCriteria() [TestMethod] public void CreateAsync_WithException() { +#pragma warning disable MSTEST0040 // Do not assert inside 'async void' contexts var lck = new AutoResetEvent(false); new Action(async () => { @@ -119,6 +120,7 @@ public void CreateAsync_WithException() } }).Invoke(); lck.WaitOne(); +#pragma warning restore MSTEST0040 // Do not assert inside 'async void' contexts } [TestMethod] @@ -166,6 +168,7 @@ public async Task FetchAsync_WithCriteria() [TestMethod] public void FetchAsync_WithException() { +#pragma warning disable MSTEST0040 // Do not assert inside 'async void' contexts var lck = new AutoResetEvent(false); new Action(async () => { @@ -186,6 +189,7 @@ public void FetchAsync_WithException() } }).Invoke(); lck.WaitOne(); +#pragma warning restore MSTEST0040 // Do not assert inside 'async void' contexts } [TestMethod] @@ -226,6 +230,7 @@ public async Task SaveAsync() [TestMethod] public async Task SaveAsyncWithException() { +#pragma warning disable MSTEST0040 // Do not assert inside 'async void' contexts var context = GetContext(); await context.Assert.Try(async () => { @@ -257,6 +262,7 @@ await context.Assert.Try(async () => context.Assert.Success(); }); context.Complete(); +#pragma warning restore MSTEST0040 // Do not assert inside 'async void' contexts } #endif @@ -287,6 +293,7 @@ public async Task ExecuteAsync() [TestMethod] public void ExecuteAsyncWithException() { +#pragma warning disable MSTEST0040 // Do not assert inside 'async void' contexts var lck = new AutoResetEvent(false); new Action(async () => { @@ -308,6 +315,7 @@ public void ExecuteAsyncWithException() } }).Invoke(); lck.WaitOne(); +#pragma warning restore MSTEST0040 // Do not assert inside 'async void' contexts } #endregion From badc0d6181c8ef09d7d700822b8d88f9aa592ada Mon Sep 17 00:00:00 2001 From: Rockford Lhotka Date: Thu, 15 May 2025 16:25:21 -0500 Subject: [PATCH 12/12] #4492 Skip test on CI server --- Source/Csla.test/BizRules/BusinessRuleTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Csla.test/BizRules/BusinessRuleTests.cs b/Source/Csla.test/BizRules/BusinessRuleTests.cs index efeea49cc0..bf3b95567c 100644 --- a/Source/Csla.test/BizRules/BusinessRuleTests.cs +++ b/Source/Csla.test/BizRules/BusinessRuleTests.cs @@ -41,6 +41,7 @@ public void DefaultDataAnnotationsScan() } [TestMethod] + [TestCategory("SkipOnCIServer")] public void DisableDataAnnotationsScan() { var options = _testDIContext.ServiceProvider.GetRequiredService();