Skip to content

Commit

Permalink
Merge branch 'release/3.0.0' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
craigfowler committed Aug 21, 2020
2 parents 9bbff47 + 3bca2b6 commit 478ec72
Show file tree
Hide file tree
Showing 36 changed files with 395 additions and 165 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ packages/*/*
*.csproj.user
Tests/*/TestResults/
*.DotSettings.user
Tests/**/*.db
2 changes: 1 addition & 1 deletion CSF.Entities/CSF.Entities.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Authors>craigfowler</Authors>
<Title>Entity &amp; identity types</Title>
<Description>Interfaces &amp; base types to describe ORM-mapped entities and their identities.</Description>
<ReleaseVersion>2.0.3</ReleaseVersion>
<ReleaseVersion>3.0.0</ReleaseVersion>
<Version>$(ReleaseVersion)</Version>
<PackageVersion>$(ReleaseVersion)</PackageVersion>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
14 changes: 13 additions & 1 deletion CSF.Entities/Entity`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,19 @@ public override string ToString()
object IEntity.IdentityValue
{
get { return IdentityValue; }
set { IdentityValue = (TIdentity) value; }
set { IdentityValue = ToIdentityType(value); }
}

/// <summary>
/// Converts a specified <paramref name="value"/> to the <typeparamref name="TIdentity"/> type.
/// </summary>
/// <returns>The converted value.</returns>
/// <param name="value">The value to convert.</param>
TIdentity ToIdentityType(object value)
{
var formatter = System.Globalization.CultureInfo.InvariantCulture;
var converted = Convert.ChangeType(value, typeof(TIdentity), formatter);
return (TIdentity)converted;
}

Type IEntity.IdentityType => typeof(TIdentity);
Expand Down
2 changes: 1 addition & 1 deletion CSF.ORM.Entities/CSF.ORM.Entities.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<Authors>craigfowler</Authors>
<Title>ORM abstractions: Entity integration</Title>
<Description>An integration between CSF.ORM and CSF.Entities, providing convenience functionality for projects which use both.</Description>
<ReleaseVersion>2.0.3</ReleaseVersion>
<ReleaseVersion>3.0.0</ReleaseVersion>
<Version>$(ReleaseVersion)</Version>
<PackageVersion>$(ReleaseVersion)</PackageVersion>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
2 changes: 1 addition & 1 deletion CSF.ORM.NHibernate.Common/CSF.ORM.NHibernate.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<PropertyGroup>
<IsPackable>false</IsPackable>
<ReleaseVersion>2.0.3</ReleaseVersion>
<ReleaseVersion>3.0.0</ReleaseVersion>
<Version>$(ReleaseVersion)</Version>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\CSF-Software-OSS.snk</AssemblyOriginatorKeyFile>
Expand Down
12 changes: 9 additions & 3 deletions CSF.ORM.NHibernate.Common/SessionAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ public class SessionAdapter : IDataConnection, IGetsTransaction, IHasNativeImple
/// Gets the native implementation which provides the service's functionality.
/// </summary>
/// <value>The native implementation.</value>
public object NativeImplementation => session;
public object NativeImplementation => session;

/// <summary>
/// Gets a value indicating whether a transaction is currently active, created by this provider.
/// </summary>
/// <value><c>true</c> if is transaction is active; otherwise, <c>false</c>.</value>
public bool IsTransactionActive => HasExistingTransaction;

/// <summary>
/// Gets a persister object from the current connection.
Expand Down Expand Up @@ -91,8 +97,8 @@ public ITransaction GetTransaction()
return provider.GetTransaction(session);
}

bool HasExistingTransaction => session.Transaction?.IsActive == true;

bool HasExistingTransaction => session.Transaction?.IsActive == true;

#region IDisposable Support
bool disposedValue;

Expand Down
2 changes: 1 addition & 1 deletion CSF.ORM.NHibernate4/CSF.ORM.NHibernate4.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Authors>craigfowler</Authors>
<Title>ORM abstractions: Implementation for NHibernate 4</Title>
<Description>Implementation of the ORM abstractions for users of NHibernate version 4.x.</Description>
<ReleaseVersion>2.0.3</ReleaseVersion>
<ReleaseVersion>3.0.0</ReleaseVersion>
<Version>$(ReleaseVersion)</Version>
<PackageVersion>$(ReleaseVersion)</PackageVersion>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
4 changes: 2 additions & 2 deletions CSF.ORM.NHibernate4/TransactionAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void Commit()
/// <summary>
/// Commit this transaction to the back-end using an asynchronous API, where available.
/// </summary>
public void CommitAsync() => Task.Run(() => Commit());
public Task CommitAsync() => Task.Run(() => Commit());

/// <summary>
/// Rollback this instance.
Expand All @@ -78,7 +78,7 @@ public void Rollback()
/// <summary>
/// Roll the transaction back and abort changes using an asynchronous API, where available.
/// </summary>
public void RollbackAsync() => Task.Run(() => Rollback());
public Task RollbackAsync() => Task.Run(() => Rollback());

#region IDisposable Support
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion CSF.ORM.NHibernate5/CSF.ORM.NHibernate5.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Authors>craigfowler</Authors>
<Title>ORM abstractions: Implementation for NHibernate 5</Title>
<Description>Implementation of the ORM abstractions for users of NHibernate version 5.x.</Description>
<ReleaseVersion>2.0.3</ReleaseVersion>
<ReleaseVersion>3.0.0</ReleaseVersion>
<Version>$(ReleaseVersion)</Version>
<PackageVersion>$(ReleaseVersion)</PackageVersion>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
13 changes: 7 additions & 6 deletions CSF.ORM.NHibernate5/TransactionAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using nh = NHibernate;

namespace CSF.ORM.NHibernate
Expand Down Expand Up @@ -57,14 +58,15 @@ public void Commit()
/// <summary>
/// Commit this transaction to the back-end using an asynchronous API, where available.
/// </summary>
public void CommitAsync()
public Task CommitAsync()
{
AssertNotFinalised();

if (mayCommitAndDispose)
transaction.CommitAsync();
return transaction.CommitAsync();

IsFinal = true;
return Task.CompletedTask;
}

/// <summary>
Expand All @@ -84,17 +86,16 @@ public void Rollback()
/// <summary>
/// Roll the transaction back and abort changes using an asynchronous API, where available.
/// </summary>
public void RollbackAsync()
public Task RollbackAsync()
{
if (transaction.WasRolledBack || IsFinal || disposedValue)
{
IsFinal = true;
return;
return Task.CompletedTask;
}

transaction.RollbackAsync();

IsFinal = true;
return transaction.RollbackAsync();
}

void AssertNotFinalised()
Expand Down
2 changes: 1 addition & 1 deletion CSF.ORM.sln
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,6 @@ Global
$0.NameConventionPolicy = $4
$4.Rules = $5
$5.NamingRule = $25
version = 2.0.3
version = 3.0.0
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion CSF.ORM/CSF.ORM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Authors>craigfowler</Authors>
<Title>ORM abstractions</Title>
<Description>Types which relate to the usage of an ORM, so that a business logic project does not need to depend upon the ORM directly.</Description>
<ReleaseVersion>2.0.3</ReleaseVersion>
<ReleaseVersion>3.0.0</ReleaseVersion>
<Version>$(ReleaseVersion)</Version>
<PackageVersion>$(ReleaseVersion)</PackageVersion>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
6 changes: 6 additions & 0 deletions CSF.ORM/IGetsTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ namespace CSF.ORM
/// </summary>
public interface IGetsTransaction
{
/// <summary>
/// Gets a value indicating whether a transaction is currently active, created by this provider.
/// </summary>
/// <value><c>true</c> if is transaction is active; otherwise, <c>false</c>.</value>
bool IsTransactionActive { get; }

/// <summary>
/// Attempts to get a new transaction, perhaps starting a new one.
/// </summary>
Expand Down
6 changes: 4 additions & 2 deletions CSF.ORM/ITransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Threading.Tasks;

namespace CSF.ORM
{
/// <summary>
Expand All @@ -44,11 +46,11 @@ public interface ITransaction : IDisposable
/// <summary>
/// Commit this transaction to the back-end using an asynchronous API, where available.
/// </summary>
void CommitAsync();
Task CommitAsync();

/// <summary>
/// Roll the transaction back and abort changes using an asynchronous API, where available.
/// </summary>
void RollbackAsync();
Task RollbackAsync();
}
}
4 changes: 2 additions & 2 deletions CSF.ORM/InMemory/NoOpTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void Commit()
/// <summary>
/// Commit this transaction to the back-end using an asynchronous API, where available.
/// </summary>
public void CommitAsync() => Task.Run(() => Commit());
public Task CommitAsync() => Task.Run(() => Commit());

/// <summary>
/// Rollback this instance.
Expand All @@ -83,7 +83,7 @@ public void Rollback()
/// <summary>
/// Roll the transaction back and abort changes using an asynchronous API, where available.
/// </summary>
public void RollbackAsync() => Task.Run(() => Rollback());
public Task RollbackAsync() => Task.Run(() => Rollback());

/// <summary>
/// Releases all resource used by the <see cref="NoOpTransaction"/> object.
Expand Down
6 changes: 6 additions & 0 deletions CSF.ORM/InMemory/NoOpTransactionCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public class NoOpTransactionCreator : IGetsTransaction
{
readonly bool throwOnRollback;

/// <summary>
/// Gets a value indicating whether a transaction is currently active, this implementation always returns <c>false</c>.
/// </summary>
/// <value>Always <c>false</c>.</value>
public bool IsTransactionActive => false;

/// <summary>
/// Begins the transaction.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PackageId>CSF.PersistenceTester</PackageId>
<Title>ORM persistence tester</Title>
<Description>A utility for testing object/entity persistence when using an ORM.</Description>
<ReleaseVersion>2.0.3</ReleaseVersion>
<ReleaseVersion>3.0.0</ReleaseVersion>
<Version>$(ReleaseVersion)</Version>
<PackageVersion>$(ReleaseVersion)</PackageVersion>
<SonarQubeTestProject>false</SonarQubeTestProject>
Expand All @@ -43,7 +43,7 @@
<Folder Include="Impl\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CSF.EqualityRules" Version="1.0.0" />
<PackageReference Include="CSF.EqualityRules" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\CSF.ORM\CSF.ORM.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using CSF.EqualityRules;
using CSF.ORM;

namespace CSF.PersistenceTester.Impl
Expand Down Expand Up @@ -97,6 +98,7 @@ PersistenceTestResult TryCompare()
return new PersistenceTestResult(typeof(T)) { SavedObjectNotFound = true };

var equalityResult = spec.EqualityRule.GetEqualityResult(spec.Entity, retrieved);
EnsureEqualityResultMayBeReportedUpon(equalityResult);

return new PersistenceTestResult(typeof(T))
{
Expand All @@ -116,6 +118,30 @@ PersistenceTestResult TryCompare()
}
}

/// <summary>
/// If either the persisted value or the retrieved value are NHibernate proxies, then we probably won't
/// be able to use <see cref="Object.ToString()"/> later-on, once the connection has been terminated.
/// This method ensures that both values can be converted to string now, while we still have the connection.
/// </summary>
/// <param name="equalityResult">An equality result.</param>
void EnsureEqualityResultMayBeReportedUpon(EqualityResult equalityResult)
{
foreach(var item in equalityResult.RuleResults)
{
try { item.ValueA?.ToString(); }
catch(Exception e)
{
throw new PersistenceTestingException($"An exception was raised when pre-converting the persisted value {item.Name} to string.", e);
}

try { item.ValueB?.ToString(); }
catch (Exception e)
{
throw new PersistenceTestingException($"An exception was raised when pre-converting the retrieved value {item.Name} to string.", e);
}
}
}

/// <summary>
/// Initializes a new instance of the <see cref="PersistenceTester{T}"/> class.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// PersistenceTestingException.cs
//
// Author:
// Craig Fowler <craig@csf-dev.com>
//
// Copyright (c) 2020 Craig Fowler
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace CSF.PersistenceTester
{
/// <summary>
/// An exception raised when a persistence test fails with an exception.
/// </summary>
[System.Serializable]
public class PersistenceTestingException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="PersistenceTestingException"/> class
/// </summary>
public PersistenceTestingException()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="PersistenceTestingException"/> class
/// </summary>
/// <param name="message">A <see cref="T:System.String"/> that describes the exception. </param>
public PersistenceTestingException(string message) : base(message)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="PersistenceTestingException"/> class
/// </summary>
/// <param name="message">A <see cref="T:System.String"/> that describes the exception. </param>
/// <param name="inner">The exception that is the cause of the current exception. </param>
public PersistenceTestingException(string message, Exception inner) : base(message, inner)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="PersistenceTestingException"/> class
/// </summary>
/// <param name="context">The contextual information about the source or destination.</param>
/// <param name="info">The object that holds the serialized object data.</param>
protected PersistenceTestingException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PackageId>CSF.PersistenceTester.NUnit</PackageId>
<Title>ORM persistence tester: NUnit integration</Title>
<Description>An integration for the ORM persistence tester and NUnit 3.x. Provides an NUnit constraint for asserting that the test passed.</Description>
<ReleaseVersion>2.0.3</ReleaseVersion>
<ReleaseVersion>3.0.0</ReleaseVersion>
<Version>$(ReleaseVersion)</Version>
<PackageVersion>$(ReleaseVersion)</PackageVersion>
<SonarQubeTestProject>false</SonarQubeTestProject>
Expand All @@ -40,7 +40,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NUnit" Version="[3.6.0,4.0.0)" />
<PackageReference Include="CSF.EqualityRules" Version="1.0.0" />
<PackageReference Include="CSF.EqualityRules" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Runtime" Condition="$(TargetFramework.StartsWith('net4'))" />
Expand Down
Loading

0 comments on commit 478ec72

Please sign in to comment.