From a5c1c17802d39268beba6e450c8c422712fc9f00 Mon Sep 17 00:00:00 2001 From: Seif Attar Date: Sun, 13 Nov 2011 14:55:19 +0000 Subject: [PATCH] Added specs for issue 21 and issue 14 --- Solutions/SharpArch.Specifications/App.config | 22 ++++++ .../AssemblyContext.cs | 3 + .../HasUniqueDomainSignatureSpecs.cs | 74 +++++++++++++++++++ .../SharpArch.Specifications/TestEntities.cs | 19 +++++ .../sqlite-nhibernate-config.xml | 1 + 5 files changed, 119 insertions(+) diff --git a/Solutions/SharpArch.Specifications/App.config b/Solutions/SharpArch.Specifications/App.config index 2cf3b1a4c..a71176a9a 100644 --- a/Solutions/SharpArch.Specifications/App.config +++ b/Solutions/SharpArch.Specifications/App.config @@ -1,5 +1,27 @@  + +
+ + + + + + + + + + + + + + + + + + diff --git a/Solutions/SharpArch.Specifications/AssemblyContext.cs b/Solutions/SharpArch.Specifications/AssemblyContext.cs index 62e57afb6..d3f36232d 100644 --- a/Solutions/SharpArch.Specifications/AssemblyContext.cs +++ b/Solutions/SharpArch.Specifications/AssemblyContext.cs @@ -1,5 +1,7 @@ namespace SharpArch.Specifications { + using System; + using Machine.Specifications; using global::SharpArch.Testing.NUnit.NHibernate; @@ -8,6 +10,7 @@ public class AssemblyContext : IAssemblyContext { public void OnAssemblyStart() { + log4net.Config.XmlConfigurator.Configure(); RepositoryTestsHelper.InitializeNHibernateSession(); } diff --git a/Solutions/SharpArch.Specifications/NHibernate/HasUniqueDomainSignatureSpecs.cs b/Solutions/SharpArch.Specifications/NHibernate/HasUniqueDomainSignatureSpecs.cs index 8fd64d4dd..4025ba12a 100644 --- a/Solutions/SharpArch.Specifications/NHibernate/HasUniqueDomainSignatureSpecs.cs +++ b/Solutions/SharpArch.Specifications/NHibernate/HasUniqueDomainSignatureSpecs.cs @@ -131,5 +131,79 @@ public class when_validating_an_entity_with_the_wrong_validator_type : specifica It should_throw_a_precondition_exception = () => result.ShouldBeOfType(typeof(PreconditionException)); } + + [Subject(typeof(HasUniqueDomainSignatureAttribute))] + public class when_validating_a_unique_entity_that_has_another_entity_as_part_of_domain_signature : specification_for_has_unique_domain_signature_validator + { + static Song song; + static bool result; + + private Establish context = () => + { + var tigerlillies = new Band() { BandName = "The Tiger Lillies", DateFormed = DateTime.Now }; + NHibernateSession.Current.Save(tigerlillies); + RepositoryTestsHelper.FlushSessionAndEvict(tigerlillies); + song = new Song() { Performer = tigerlillies, SongTitle = "Souvenirs" }; + }; + + Because of = () => result = song.IsValid(); + + It should_say_the_entity_is_valid = () => result.ShouldBeTrue(); + } + + [Subject(typeof(HasUniqueDomainSignatureAttribute))] + public class when_validating_a_unique_entity_that_has_a_null_value_domain_signature_property : specification_for_has_unique_domain_signature_validator + { + static Song song; + static bool result; + + private Establish context = () => + { + song = new Song() { SongTitle = "Souvenirs" }; + }; + + Because of = () => result = song.IsValid(); + + It should_say_the_entity_is_valid = () => result.ShouldBeTrue(); + } + + + [Subject(typeof(HasUniqueDomainSignatureAttribute))] + public class when_validating_a_duplicate_entity_that_has_another_entity_as_part_of_domain_signature : specification_for_has_unique_domain_signature_validator + { + static Song duplicateSong; + static bool result; + + private Establish context = () => + { + var tragicRoundabout = new Band() { BandName = "Tragic Roundabout", DateFormed = DateTime.Now }; + NHibernateSession.Current.Save(tragicRoundabout); + var song = new Song() { Performer = tragicRoundabout, SongTitle = "Prince Geek" }; + NHibernateSession.Current.Save(song); + duplicateSong = new Song() { Performer = tragicRoundabout, SongTitle = "Prince Geek" }; + }; + + Because of = () => result = duplicateSong.IsValid(); + + It should_say_the_entity_is_invalid = () => result.ShouldBeFalse(); + } + + [Subject(typeof(HasUniqueDomainSignatureAttribute))] + public class when_validating_a_duplicate_entity_that_has_a_null_value_domain_signature_property : specification_for_has_unique_domain_signature_validator + { + static Song duplicateSong; + static bool result; + + private Establish context = () => + { + var song = new Song() { SongTitle = "Souvenirs" }; + NHibernateSession.Current.Save(song); + duplicateSong = new Song() { SongTitle = "Souvenirs" }; + }; + + Because of = () => result = duplicateSong.IsValid(); + + It should_say_the_entity_is_valid = () => result.ShouldBeFalse(); + } } } \ No newline at end of file diff --git a/Solutions/SharpArch.Specifications/TestEntities.cs b/Solutions/SharpArch.Specifications/TestEntities.cs index 89c71896b..f8b02ae37 100644 --- a/Solutions/SharpArch.Specifications/TestEntities.cs +++ b/Solutions/SharpArch.Specifications/TestEntities.cs @@ -92,4 +92,23 @@ public EntityWithAnotherEntityAsPartOfDomainSignature() [DomainSignature] public virtual EntityWithAllPropertiesPartOfDomainSignature Property2 { get; set; } } + + + [HasUniqueDomainSignature] + public class Song : Entity + { + [DomainSignature] + public virtual string SongTitle { get; set; } + + [DomainSignature] + public virtual Band Performer { get; set; } + } + + [HasUniqueDomainSignature] + public class Band : Entity + { + [DomainSignature] + public virtual string BandName { get; set; } + public virtual DateTime DateFormed { get; set; } + } } \ No newline at end of file diff --git a/Solutions/SharpArch.Tests/sqlite-nhibernate-config.xml b/Solutions/SharpArch.Tests/sqlite-nhibernate-config.xml index 86c049330..4c5c2eedd 100644 --- a/Solutions/SharpArch.Tests/sqlite-nhibernate-config.xml +++ b/Solutions/SharpArch.Tests/sqlite-nhibernate-config.xml @@ -12,5 +12,6 @@ Data Source=db.dat;Version=3;New=True; on_close + true \ No newline at end of file