Skip to content

Commit

Permalink
Merge pull request #3626 from rockfordlhotka/v8-work
Browse files Browse the repository at this point in the history
Updates to unit tests
  • Loading branch information
rockfordlhotka authored Dec 21, 2023
2 parents 3ea6545 + d75773c commit d643150
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 264 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
6 changes: 0 additions & 6 deletions Source/Csla.test/Basic/GrandChild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,5 @@ internal void Update(IDbTransaction tr)
MarkOld();
}
}

protected override void OnDeserialized(System.Runtime.Serialization.StreamingContext context)
{
base.OnDeserialized(context);
TestResults.Add("GCDeserialized", "GC Deserialized");
}
}
}
9 changes: 3 additions & 6 deletions 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 All @@ -119,11 +121,6 @@ protected void DataPortal_Delete(object criteria)
TestResults.Add("Root", "Deleted");
}

protected override void OnDeserialized(System.Runtime.Serialization.StreamingContext context)
{
TestResults.Add("Deserialized", "root Deserialized");
}

protected override void DataPortal_OnDataPortalInvoke(DataPortalEventArgs e)
{
TestResults.Add("dpinvoke", TestResults.GetResult("global"));
Expand Down
24 changes: 12 additions & 12 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 @@ -70,14 +70,14 @@
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="System.Data.Common" Version="4.3.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
<PackageReference Include="System.Resources.Extensions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.1" />
<PackageReference Include="System.ComponentModel.Annotations" Version="6.0.0-preview.4.21253.7" />
<PackageReference Include="System.Resources.Extensions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<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="5.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 0 additions & 6 deletions Source/Csla.test/RollBack/RollbackRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,5 @@ protected void DataPortal_Delete(object criteria)
//we would delete here
TestResults.AddOrOverwrite("Root", "Deleted");
}

protected override void OnDeserialized(System.Runtime.Serialization.StreamingContext context)
{
base.OnDeserialized(context);
TestResults.AddOrOverwrite("Deserialized", "root Deserialized");
}
}
}
7 changes: 0 additions & 7 deletions Source/Csla.test/Serialization/SerializationRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ public string Data
set { SetProperty(DataProperty, ref _data, value); }
}

protected override void OnDeserialized(System.Runtime.Serialization.StreamingContext context)
{
base.OnDeserialized(context);
TestResults.AddOrOverwrite("Deserialized", "true");
Console.WriteLine("OnDeserialized");
}

public static SerializationRoot NewSerializationRoot(IDataPortal<SerializationRoot> dataPortal)
{
return dataPortal.Create();
Expand Down
7 changes: 0 additions & 7 deletions Source/Csla.test/ValidationRules/HasChildren.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ protected override void Initialize()
this.ChildChanged += new EventHandler<ChildChangedEventArgs>(HasChildren_ChildChanged);
}

protected override void OnDeserialized(StreamingContext context)
{
base.OnDeserialized(context);
ChildList.ListChanged += new System.ComponentModel.ListChangedEventHandler(ChildList_ListChanged);
this.ChildChanged += new EventHandler<ChildChangedEventArgs>(HasChildren_ChildChanged);
}

void ChildList_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
{
//ValidationRules.CheckRules(ChildListProperty);
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
Loading

0 comments on commit d643150

Please sign in to comment.