Skip to content

Commit

Permalink
Merge branch '3395-tests' of https://github.com/rockfordlhotka/csla i…
Browse files Browse the repository at this point in the history
…nto 3395-tests

# Conflicts:
#	Source/Csla.test/AppContext/AppContextTests.cs
  • Loading branch information
rockfordlhotka committed Dec 21, 2023
2 parents d4fd623 + 84af0a8 commit 9988a06
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 135 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>
67 changes: 41 additions & 26 deletions Source/Csla.test/AppContext/AppContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,33 @@ public void SimpleTest()
[TestMethod()]
public void ClientContext()
{
IDataPortal<ClientContextGetter> dataPortal = _testDIContext.CreateDataPortal<ClientContextGetter>();
IDataPortal<Basic.Root> dataPortal = _testDIContext.CreateDataPortal<Basic.Root>();
ApplicationContext applicationContext = _testDIContext.CreateTestApplicationContext();

applicationContext.ClientContext.Add("value", "client context data");
Assert.AreEqual("client context data", applicationContext.ClientContext["value"], "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");

var obj = dataPortal.Fetch();
Assert.AreEqual("client context data", obj.ClientContextValue, "value didn't come back from server");
TestResults.Reinitialise();
root = root.Save();

Assert.IsNotNull(root, "Root object should not be null");
Assert.AreEqual("Inserted", TestResults.GetResult("Root"), "Object not inserted");
Assert.AreEqual("saved", root.Data, "Root data should be 'saved'");
Assert.AreEqual(false, root.IsNew, "Object should not be new");
Assert.AreEqual(false, root.IsDeleted, "Object should not be deleted");
Assert.AreEqual(false, root.IsDirty, "Object should not be dirty");

//TODO: Is there a modern equivalent of this?
//Assert.AreEqual("client context data", Csla.ApplicationContext.ClientContext["clientcontext"], "Client context data lost");
Assert.AreEqual("client context data", TestResults.GetResult("clientcontext"), "Global context data lost");
Assert.AreEqual("new global value", TestResults.GetResult("globalcontext"), "New global value lost");
}

#endregion
Expand Down Expand Up @@ -140,8 +159,6 @@ public void FailFetchContext()

#endregion

#region FailUpdateContext

[TestMethod()]
public void FailUpdateContext()
{
Expand All @@ -162,14 +179,29 @@ public void FailUpdateContext()
Assert.AreEqual("Fail create", ex.GetBaseException().Message, "Base exception message incorrect");
Assert.IsTrue(ex.Message.StartsWith("DataPortal.Create failed"), "Exception message incorrect");
}

root.Data = "boom";
try
{
root = root.Save();

Assert.Fail("Insert exception didn't occur");
}
catch (DataPortalException ex)
{
root = (ExceptionRoot)ex.BusinessObject;
Assert.AreEqual("Fail insert", ex.GetBaseException().Message, "Base exception message incorrect");
Assert.IsTrue(ex.Message.StartsWith("DataPortal.Update failed"), "Exception message incorrect");
}

Assert.AreEqual("boom", root.Data, "Business object not returned");
Assert.AreEqual("create", TestResults.GetResult("create"), "GlobalContext not preserved");
}
finally
{
}
}

#endregion

#region FailDeleteContext

[TestMethod()]
Expand Down Expand Up @@ -203,21 +235,4 @@ private Basic.Root GetRoot(string data)
}

}

[Serializable]
public class ClientContextGetter : BusinessBase<ClientContextGetter>
{
public static readonly PropertyInfo<string> ClientContextValueProperty = RegisterProperty<string>(nameof(ClientContextValue));
public string ClientContextValue
{
get => GetProperty(ClientContextValueProperty);
set => SetProperty(ClientContextValueProperty, value);
}

[Fetch]
private void Fetch()
{
ClientContextValue = ApplicationContext.ClientContext["value"].ToString();
}
}
}
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 9988a06

Please sign in to comment.