Skip to content

Commit

Permalink
#3 moving tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Gerbenis committed Oct 1, 2015
1 parent 862d993 commit 78c61d2
Show file tree
Hide file tree
Showing 21 changed files with 251 additions and 250 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static Boolean IsDirtyEntity(this ISession session, Object entity)
}

Object[] currentState = persister.GetPropertyValues(entity, sessionImpl.EntityMode);
Int32[] dirtyProps = oldState.Select((o, i) => ValuesAreEqual(oldState[i], currentState[i]) ? -1 : i).Where(x => x >= 0).ToArray();
Int32[] dirtyProps = oldState.Select((o, i) => ValuesEqual(oldState[i], currentState[i]) ? -1 : i).Where(x => x >= 0).ToArray();

return (dirtyProps != null && dirtyProps.Length > 0);
}
Expand All @@ -48,7 +48,7 @@ public static Boolean IsDirtyEntity(this ISession session, Object entity)
/// <param name="oldValue">The old value.</param>
/// <param name="currentValue">The current value.</param>
/// <returns><c>true</c>, if values are equal, else <c>false</c></returns>
private static bool ValuesAreEqual(object oldValue, object currentValue)
private static bool ValuesEqual(object oldValue, object currentValue)
{
// If property is not loaded, it has no changes
if (!NHibernateUtil.IsInitialized(oldValue))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
using BetterModules.Sample.Module.Models;

using Moq;
using Xunit;

using NUnit.Framework;

namespace BetterModules.Core.Tests.DataAccess.DataContext.EventListeners
{
[TestFixture]
public class EventListenerHelperTests : TestBase
public class EventListenerHelperTests
{
[Test]
[Fact]
public void Should_Update_Creation_Fields_Correctly()
{
var principalProvider = new Mock<IPrincipalProvider>();
Expand All @@ -25,13 +24,13 @@ public void Should_Update_Creation_Fields_Correctly()

EnsureDeletionPropertiesUntouched(entity);

Assert.IsTrue(entity.CreatedOn != DateTime.MinValue);
Assert.IsTrue(entity.ModifiedOn != DateTime.MinValue);
Assert.AreEqual(entity.CreatedByUser, "TestPrincipal");
Assert.AreEqual(entity.ModifiedByUser, "TestPrincipal");
Assert.True(entity.CreatedOn != DateTime.MinValue);
Assert.True(entity.ModifiedOn != DateTime.MinValue);
Assert.Equal(entity.CreatedByUser, "TestPrincipal");
Assert.Equal(entity.ModifiedByUser, "TestPrincipal");
}

[Test]
[Fact]
public void Should_Update_Modification_Fields_Correctly()
{
var principalProvider = new Mock<IPrincipalProvider>();
Expand All @@ -44,11 +43,11 @@ public void Should_Update_Modification_Fields_Correctly()
EnsureDeletionPropertiesUntouched(entity);
EnsureCreationPropertiesUntouched(entity);

Assert.IsTrue(entity.ModifiedOn != DateTime.MinValue);
Assert.AreEqual(entity.ModifiedByUser, "TestPrincipal");
Assert.True(entity.ModifiedOn != DateTime.MinValue);
Assert.Equal(entity.ModifiedByUser, "TestPrincipal");
}

[Test]
[Fact]
public void Should_Update_Deletion_Fields_Correctly()
{
var principalProvider = new Mock<IPrincipalProvider>();
Expand All @@ -61,28 +60,28 @@ public void Should_Update_Deletion_Fields_Correctly()
EnsureCreationPropertiesUntouched(entity);
EnsureModificationPropertiesUntouched(entity);

Assert.IsTrue(entity.IsDeleted);
Assert.IsTrue(entity.DeletedOn != DateTime.MinValue);
Assert.AreEqual(entity.DeletedByUser, "TestPrincipal");
Assert.True(entity.IsDeleted);
Assert.True(entity.DeletedOn != DateTime.MinValue);
Assert.Equal(entity.DeletedByUser, "TestPrincipal");
}

private void EnsureCreationPropertiesUntouched(TestItemModel entity)
{
Assert.AreEqual(entity.CreatedOn, DateTime.MinValue);
Assert.IsNull(entity.CreatedByUser);
Assert.Equal(entity.CreatedOn, DateTime.MinValue);
Assert.Null(entity.CreatedByUser);
}

private void EnsureDeletionPropertiesUntouched(TestItemModel entity)
{
Assert.IsNull(entity.DeletedByUser);
Assert.IsNull(entity.DeletedOn);
Assert.IsFalse(entity.IsDeleted);
Assert.Null(entity.DeletedByUser);
Assert.Null(entity.DeletedOn);
Assert.False(entity.IsDeleted);
}

private void EnsureModificationPropertiesUntouched(TestItemModel entity)
{
Assert.AreEqual(entity.ModifiedOn, DateTime.MinValue);
Assert.IsNull(entity.ModifiedByUser);
Assert.Equal(entity.ModifiedOn, DateTime.MinValue);
Assert.Null(entity.ModifiedByUser);
}

private TestItemModel CreateEntity()
Expand Down
Loading

0 comments on commit 78c61d2

Please sign in to comment.