This error occurs whenever I use
CheckList
or
CheckComponentList
.

My tests involving lists always fail <#error>!
Code

My domain entities implementing IEntity and Id always generated by domain!

public interface IEntity { Guid Id { get; } }
public class Email : IEntity
{
    public virtual Guid Id { get; protected set; }
    public virtual string Address { get; set; }
    public virtual string FieldName { get; set; }

    public Email()
    {
        Id = Guid.NewGuid();
    }
}
public class Person : IEntity
{
    public virtual Guid Id { get; protected set; }
    public virtual string Name { get; set; }
    public virtual string Nickname { get; set; }
    public virtual DateTime CreateAt { get; protected set; }
    public virtual ICollection<Email> Emails { get; protected set; }

    public Person()
    {
        Id = Guid.NewGuid();
        Emails = new List<Email>();
        CreateAt = DateTime.Now;
    }
}

My test is quite simple:

[TestMethod]
public void Person_can_have_0_or_more_emails()
{
    // Arrange

    // Act
    new PersistenceSpecification<Person>(_session)
            .CheckProperty(p => p.Name, "Mike")
            .CheckProperty(p => p.Nickname, "mke")
            .CheckList(p => p.Emails, new List<Email>(){
                    new Email { Address = "addr...@company.com",
FieldName = "Work" }
                    ,new Email { Address = "m...@gmail.com", FieldName =
"Personal" }
                    ,new Email { Address = "sec...@live.com",
FieldName = "Secret" }
                }.ToList() , new EntityComparer())
            .VerifyTheMappings(); // Assert
}

EntityComparer is used to differentiate between domain objects:

public class EntityComparer : IEqualityComparer
{
    public int GetHashCode(object obj)
    {
        if (obj == null)
            return 0;
        if (!(obj is IEntity))
            return obj.GetHashCode();

        return ((IEntity)obj).Id.GetHashCode();
    }

    public new bool Equals(object x, object y)
    {
        if (x == null || y == null)
            return false;
        if (!(x is IEntity) || !(y is IEntity))
            return false;

        var ex = (IEntity)x;
        var ey = (IEntity)y;
        return ex.Id != Guid.Empty && ey.Id != Guid.Empty && ex.Id == ey.Id;
    }
}

Full code 
here<https://bitbucket.org/ridermansb/illustrateproblems/src/c5cd7cee4ec4c40dc628b4eaa6613d1daa050c31/CheckListTestProblem?at=default>
.
Error

 Expected 'CheckListTestProblem.Domain.Email' but got
'CheckListTestProblem.Domain.Email' at position 0

*Result StackTrace:*

 at FluentNHibernate.Testing.Values.List2.AssertGenericListMatches(IEnumerable
actualEnumerable, IEnumerable1 expectedEnumerable)
at FluentNHibernate.Testing.Values.List2.CheckValue(Object target) at
FluentNHibernate.Testing.PersistenceSpecification1.<>c*DisplayClass2.b*
1(Property1 p) at System.Collections.Generic.List1.ForEach(Action1 action)
at FluentNHibernate.Testing.PersistenceSpecification1.VerifyTheMappings(T
first)
at FluentNHibernate.Testing.PersistenceSpecification`1.VerifyTheMappings()
at CheckListTestProblem.Test.PersonTest.Person_can_have_0_or_more_emails()
in {...}\CheckListTestProblem\CheckListTestProblem.Test\PersonTest.cs:line
60

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fluent-nhibernate+unsubscr...@googlegroups.com.
To post to this group, send email to fluent-nhibernate@googlegroups.com.
Visit this group at http://groups.google.com/group/fluent-nhibernate.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to