I found a weird behavior of PersistenceSpecification testing
components with IEquatable implemented (when using hbm mappings).

Is it this the normal? do I miss something? Lastly tested on Fluent
NHibernate r432

Thanks for your help!!!

I did a simple test to show my point:

public class Password : IEquatable<Password>
    {
        readonly string password;

        protected Password() {}

        public Password(string password)
        {
            this.password = password;
        }

        public bool Equals(Password other)
        {
            return password.Equals(other.password);
        }
    }

    public class User
    {
        public int Id { get; protected set; }
        public Password Password { get; protected set; }
    }

    public class DbContext
    {
        protected ISessionSource SessionSource;

        public DbContext()
        {
            var configuration =
                   FluentNHibernate.Cfg.Fluently.Configure().Database
(SQLiteConfiguration.Standard.UsingFile("test.db")).Mappings(
                    x => x.HbmMappings.AddFromAssemblyOf<User>());

            SessionSource = new SessionSource(configuration);
        }
    }

    public class UserMappingFacts : DbContext
    {
        public UserMappingFacts()
        {
            SessionSource.BuildSchema();
        }

        [Fact] // Pass as expected
        public void Password_must_be_equal_with_same_password()
        {
            var password_one = new Password("password");
            var password_two = new Password("password");
            var password_three = new Password("other.password");

            Assert.Equal(password_one, password_two);
            Assert.NotEqual(password_one, password_three);
        }

        [Fact] // Fails!!!
        public void User_is_well_mapped()
        {
            new PersistenceSpecification<User>(SessionSource)
                .CheckProperty(x => x.Password, new Password
("password"))
                .VerifyTheMappings();
        }
    }

///// HBM file
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-
lazy="false" assembly="ClassLibrary2" namespace="ClassLibrary2">
  <class name="User">
    <id name="Id">
      <generator class="native" />
    </id>
    <component name="Password">
      <property name="password" access="field" not-null="true" />
    </component>
  </class>
</hibernate-mapping>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to