Skip to content

Commit

Permalink
Added specs for issue 21 and issue 14
Browse files Browse the repository at this point in the history
  • Loading branch information
seif committed Nov 13, 2011
1 parent 3119327 commit a5c1c17
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Solutions/SharpArch.Specifications/App.config
@@ -1,5 +1,27 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>
<log4net>
<appender name="console"
type="log4net.Appender.ConsoleAppender, log4net">
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern"
value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
<logger name="NHibernate">
<level value="WARN" />
</logger>
<logger name="NHibernate.SQL">
<level value="DEBUG" />
</logger>
<root>
<priority value="DEBUG" />
<appender-ref ref="console" />
</root>
</log4net>
<appSettings>
<add key="nhibernate.mapping.assembly" value="SharpArch.Specifications"/>
</appSettings>
Expand Down
3 changes: 3 additions & 0 deletions Solutions/SharpArch.Specifications/AssemblyContext.cs
@@ -1,5 +1,7 @@
namespace SharpArch.Specifications
{
using System;

using Machine.Specifications;

using global::SharpArch.Testing.NUnit.NHibernate;
Expand All @@ -8,6 +10,7 @@ public class AssemblyContext : IAssemblyContext
{
public void OnAssemblyStart()
{
log4net.Config.XmlConfigurator.Configure();
RepositoryTestsHelper.InitializeNHibernateSession();
}

Expand Down
Expand Up @@ -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();
}
}
}
19 changes: 19 additions & 0 deletions Solutions/SharpArch.Specifications/TestEntities.cs
Expand Up @@ -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; }
}
}
1 change: 1 addition & 0 deletions Solutions/SharpArch.Tests/sqlite-nhibernate-config.xml
Expand Up @@ -12,5 +12,6 @@
Data Source=db.dat;Version=3;New=True;
</property>
<property name="connection.release_mode">on_close</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>

0 comments on commit a5c1c17

Please sign in to comment.