Skip to content

Commit

Permalink
Merge branch 'main' into 3395-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rockfordlhotka authored Dec 21, 2023
2 parents c2be04b + d643150 commit 84af0a8
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 226 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

<ItemGroup>
<ProjectReference Include="..\..\..\Csla.TestHelpers\Csla.TestHelpers.csproj" />
<ProjectReference Include="..\Csla.Generators.CSharp.TestObjects\Csla.Generators.CSharp.TestObjects.csproj" />
</ItemGroup>

</Project>
121 changes: 4 additions & 117 deletions Source/Csla.test/AppContext/AppContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,67 +59,6 @@ public void SimpleTest()

#endregion

[TestMethod()]
public void ApplicationContextProperties()
{
// TODO: Is there any equivalent for this test in Csla 6?
//ApplicationContext.DataPortalProxy = null;
//Assert.AreEqual("Local", ApplicationContext.DataPortalProxy);
//Assert.AreEqual("Client", ApplicationContext.ExecutionLocation.ToString());
}

#region TestAppContext across different Threads

// TODO: Is this test relevant anymore? I can't work out how to do this test
[TestMethod]
public void TestAppContextAcrossDifferentThreads()
{
List<AppContextThread> AppContextThreadList = new List<AppContextThread>();
List<Thread> ThreadList = new List<Thread>();

for (int x = 0; x < 10; x++)
{
AppContextThread act = new AppContextThread("Thread: " + x);
AppContextThreadList.Add(act);

Thread t = new Thread(new ThreadStart(act.Run));
t.Name = "Thread: " + x;
t.Start();
ThreadList.Add(t);
}

Exception ex = null;
try
{
foreach (AppContextThread act in AppContextThreadList)
{
//We are accessing the Client/GlobalContext via this thread, therefore
//it should be removed.
Assert.AreEqual(true, act.Removed);
}
//We are now accessing the shared value. If any other thread
//loses its Client/GlobalContext this will turn to true
//Assert.AreEqual(false, AppContextThread.StaticRemoved);
}
catch (Exception e)
{
ex = e;
}
finally
{
foreach (AppContextThread act in AppContextThreadList)
act.Stop();

foreach (Thread t in ThreadList)
{
t.Join();
}
}
if (ex != null) throw ex;
}

#endregion

#region ClientContext

/// <summary>
Expand All @@ -135,15 +74,17 @@ public void ClientContext()
IDataPortal<Basic.Root> dataPortal = _testDIContext.CreateDataPortal<Basic.Root>();
ApplicationContext applicationContext = _testDIContext.CreateTestApplicationContext();

applicationContext.ClientContext.Add("clientcontext", "client context data");
Assert.AreEqual("client context data", applicationContext.ClientContext["clientcontext"], "Matching data not retrieved");
var testContext = "client context data";
applicationContext.ClientContext.Add("clientcontext", testContext);
Assert.AreEqual(testContext, applicationContext.ClientContext["clientcontext"], "Matching data not retrieved");

Basic.Root root = dataPortal.Create(new Basic.Root.Criteria());
root.Data = "saved";
Assert.AreEqual("saved", root.Data, "Root data should be 'saved'");
Assert.AreEqual(true, root.IsDirty, "Object should be dirty");
Assert.AreEqual(true, root.IsValid, "Object should be valid");

TestResults.Reinitialise();
root = root.Save();

Assert.IsNotNull(root, "Root object should not be null");
Expand All @@ -161,56 +102,6 @@ public void ClientContext()

#endregion

#region Dataportal Events

// TODO: Is this test relevant any more? These event handlers don't seem to be exposed
/// <summary>
/// Test the dataportal events
/// </summary>
/// <remarks>
/// How does the GlobalContext get the keys "dpinvoke" and "dpinvokecomplete"?
///
/// In the vb version of this test it calls RemoveHandler in VB. Unfortunately removing handlers aren't quite
/// that easy in C# I had to declare EventHandlers that could be added and removed. Also I found out that the
/// VB library does not seem to contain the DataPortalInvokeEventHandler object so I put a conditional compile
/// flag around this method and set a warning message.
/// </remarks>
[TestMethod()]
public void DataPortalEvents()
{
IDataPortal<Basic.Root> dataPortal = _testDIContext.CreateDataPortal<Basic.Root>();

TestResults.Add("global", "global");

//dataPortal.DataPortalInvoke += new Action<DataPortalEventArgs>(OnDataPortaInvoke);
//dataPortal.DataPortalInvokeComplete += new Action<DataPortalEventArgs>(OnDataPortalInvokeComplete);

Basic.Root root = dataPortal.Fetch(new Basic.Root.Criteria("testing"));

//dataPortal.DataPortalInvoke -= new Action<DataPortalEventArgs>(OnDataPortaInvoke);
//dataPortal.DataPortalInvokeComplete -= new Action<DataPortalEventArgs>(OnDataPortalInvokeComplete);

//Populated in the handlers below
Assert.AreEqual("global", TestResults.GetResult("ClientInvoke"), "Client invoke incorrect");
Assert.AreEqual("global", TestResults.GetResult("ClientInvokeComplete"), "Client invoke complete");

//populated in the Root Dataportal handlers.
Assert.AreEqual("global", TestResults.GetResult("dpinvoke"), "Server invoke incorrect");
Assert.AreEqual("global", TestResults.GetResult("dpinvokecomplete"), "Server invoke compelte incorrect");
}

private void OnDataPortaInvoke(DataPortalEventArgs e)
{
TestResults.Add("ClientInvoke", TestResults.GetResult("global"));
}

private void OnDataPortalInvokeComplete(DataPortalEventArgs e)
{
TestResults.Add("ClientInvokeComplete", TestResults.GetResult("global"));
}

#endregion

#region FailCreateContext

/// <summary>
Expand Down Expand Up @@ -268,8 +159,6 @@ public void FailFetchContext()

#endregion

#region FailUpdateContext

[TestMethod()]
public void FailUpdateContext()
{
Expand Down Expand Up @@ -313,8 +202,6 @@ public void FailUpdateContext()
}
}

#endregion

#region FailDeleteContext

[TestMethod()]
Expand Down
14 changes: 6 additions & 8 deletions Source/Csla.test/AppContext/ExceptionRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;

namespace Csla.Test.AppContext
{
Expand Down Expand Up @@ -51,9 +49,9 @@ public Criteria(string Data)
}
}

protected void DataPortal_Fetch(object criteria)
[Fetch]
protected void DataPortal_Fetch(Criteria crit)
{
Criteria crit = criteria as Criteria;
this._Data = crit.Data;
this.MarkOld();

Expand All @@ -62,9 +60,9 @@ protected void DataPortal_Fetch(object criteria)
throw new ApplicationException("Fail fetch");
}

private void DataPortal_Create(object criteria)
[Create]
private void DataPortal_Create(Criteria crit)
{
Criteria crit = criteria as Criteria;
this._Data = crit.Data;

TestResults.Add("Root", "Created");
Expand All @@ -82,15 +80,15 @@ protected void DataPortal_Insert()
}

[Update]
protected void DataPortal_Update()
protected void DataPortal_Update()
{
TestResults.AddOrOverwrite("Root", "Updated");
TestResults.AddOrOverwrite("create", "create");
throw new ApplicationException("Fail update");
}

[Delete]
protected void DataPortal_Delete(object criteria)
protected void DataPortal_Delete(object criteria)
{
TestResults.AddOrOverwrite("Root", "Deleted");
TestResults.AddOrOverwrite("create", "create");
Expand Down
4 changes: 3 additions & 1 deletion Source/Csla.test/Basic/Root.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public Criteria(string data)
}
}

[Create]
private void DataPortal_Create(object criteria, [Inject] IDataPortal<Children> childrenDataPortal)
{
Criteria crit = (Criteria)(criteria);
Expand All @@ -74,6 +75,7 @@ private void DataPortal_Create(object criteria, [Inject] IDataPortal<Children> c
TestResults.Add("Root", "Created");
}

[Fetch]
protected void DataPortal_Fetch(object criteria, [Inject] IDataPortal<Children> childrenDataPortal)
{
Criteria crit = (Criteria)(criteria);
Expand Down Expand Up @@ -101,7 +103,7 @@ protected void DataPortal_Insert()
}

[Update]
protected void DataPortal_Update()
protected void DataPortal_Update()
{
//we would update here
TestResults.Add("Root", "Updated");
Expand Down
10 changes: 5 additions & 5 deletions Source/Csla.test/Csla.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<IsPackable>false</IsPackable>
<SignAssembly>true</SignAssembly>
Expand All @@ -11,11 +11,11 @@
<RunSettingsFilePath>$(MSBuildProjectDirectory)\test.runsettings</RunSettingsFilePath>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0|AnyCPU'">
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0|AnyCPU'">
<DefineConstants>$(DefineConstants)TRACE;MSTEST</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0|AnyCPU'">
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0|AnyCPU'">
<DefineConstants>$(DefineConstants)TRACE;MSTEST</DefineConstants>
</PropertyGroup>

Expand Down Expand Up @@ -77,7 +77,7 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="8.0.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="6.0.0-preview.4.21253.7" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions Source/Csla/Rules/BusinessRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ orderby r.Priority
if (CascadeOnDirtyProperties)
doCascade = firstResult.DirtyProperties.Any(p => p == item.Name);
firstResult.AffectedProperties.AddRange(CheckRulesForProperty(item, doCascade,
executionContext | RuleContextModes.AsAffectedPoperty));
executionContext | RuleContextModes.AsAffectedProperty));
}
}

Expand Down Expand Up @@ -625,7 +625,7 @@ internal static bool CanRunRule(ApplicationContext applicationContext, IBusiness

bool canRun = true;

if ((contextMode & RuleContextModes.AsAffectedPoperty) > 0)
if ((contextMode & RuleContextModes.AsAffectedProperty) > 0)
canRun &= (rule.RunMode & RunModes.DenyAsAffectedProperty) == 0;

if ((rule.RunMode & RunModes.DenyOnServerSidePortal) > 0)
Expand Down Expand Up @@ -695,7 +695,7 @@ where dirtyProperties.Contains(r.Name)
if (CascadeOnDirtyProperties)
doCascade = primaryResult.DirtyProperties.Any(p => p == item.Name);
primaryResult.AffectedProperties.AddRange(CheckRulesForProperty(item, doCascade,
executionMode | RuleContextModes.AsAffectedPoperty));
executionMode | RuleContextModes.AsAffectedProperty));
}
}

Expand Down Expand Up @@ -764,7 +764,7 @@ private RunRulesResult RunRules(IEnumerable<IBusinessRuleBase> rules, bool casca
var doCascade = false;
if (CascadeOnDirtyProperties && (r.DirtyProperties != null))
doCascade = r.DirtyProperties.Any(p => p.Name == item.Name);
affected.AddRange(CheckRulesForProperty(item, doCascade, r.ExecuteContext | RuleContextModes.AsAffectedPoperty));
affected.AddRange(CheckRulesForProperty(item, doCascade, r.ExecuteContext | RuleContextModes.AsAffectedProperty));
}

// mark each property as not busy
Expand Down
4 changes: 2 additions & 2 deletions Source/Csla/Rules/RuleContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public enum RuleContextModes
/// <summary>
/// Include cascaded calls by AffectedProperties
/// </summary>
AsAffectedPoperty = 8,
AsAffectedProperty = 8,
}

/// <summary>
Expand Down Expand Up @@ -168,7 +168,7 @@ public void ExecuteRule(IBusinessRuleBase innerRule)
[EditorBrowsable(EditorBrowsableState.Never)]
public bool IsCascadeContext
{
get { return (ExecuteContext & RuleContextModes.AsAffectedPoperty) > 0; }
get { return (ExecuteContext & RuleContextModes.AsAffectedProperty) > 0; }
}

/// <summary>
Expand Down
Loading

0 comments on commit 84af0a8

Please sign in to comment.