我正在尝试使用TDD加速,所以我创建了一个新的S#arp Arch应用程序(v1.6),并且一直在为我的类创建测试。不幸的是,我已经遇到了一个我尚未解决的问题。
我为'User'和'RecordRequest'类创建了一个比较测试。使用NUnit执行测试时,'User'测试通过,而'RecordRequest'则没有。我试图理解为什么一个测试正在通过而另一个测试没有通过。错误消息是:
在SharpArch.Testing.NUnit.SyntaxHelpers.ShouldEqual(Object actual,Object expected)中的e:\ WorkSpaces \ Git \ SharpArchitecture \ Trunk \ src \ SharpArch \ SharpArch.Testing.NUnit \ SyntaxHelpers.cs:第25行 在D:\ Web \ Mvc \ Projects \ Campus Counsel \ IRS \ ISPS \ tests \ ISPS.Tests \ ISPS.Core \ Account \ RecordRequestTests.cs:第23行的Tests.ISPS.Core.Account.RecordRequestTests.CanCompareRecordRequests()中/ p>
'用户'类和测试:
using System;
using System.Security.Principal;
using NHibernate.Validator.Constraints;
using SharpArch.Core.DomainModel;
namespace ISPS.Core.Account
{
public class User : Entity, IPrincipal
{
public static User DefaultUser()
{
return new User
{
Role = Role.Administrator,
IsActive = true,
CreatedOn = DateTime.Now
};
}
[DomainSignature]
[NotNullNotEmpty(Message = "Kerberos must be provided.")]
public virtual string Kerberos { get; set; }
[NotNullNotEmpty(Message = "First name must be provided.")]
public virtual string FirstName { get; set; }
[NotNullNotEmpty(Message = "Last name must be provided.")]
public virtual string LastName { get; set; }
[DomainSignature]
[NotNullNotEmpty(Message = "Email must be provided.")]
public virtual string Email { get; set; }
[NotNull(Message = "Role must be provided.")]
public virtual Role Role { get; set; }
public virtual bool IsActive { get; set; }
public virtual DateTime CreatedOn { get; set; }
public virtual DateTime? ModifiedOn { get; set; }
public virtual bool IsAdministrator { get { return Role.Id == Role.AdministratorId; } }
public virtual bool IsEditor { get { return Role.Id == Role.EditorId; } }
public virtual bool IsGuest { get { return Role.Id == Role.GuestId; } }
public virtual IIdentity Identity
{
get
{
var isAuthenticated = (Role.Name == Role.Administrator.Name);
return new Identity(isAuthenticated, Kerberos);
}
}
public virtual bool IsInRole(string role)
{
return Role.Name == role;
}
}
/// <summary>
/// Simple implementation of IIdentity
/// </summary>
public class Identity : IIdentity
{
public Identity(bool isAuthenticated, string name)
{
IsAuthenticated = isAuthenticated;
Name = name;
}
public string AuthenticationType
{
get { return "Forms"; }
}
public bool IsAuthenticated { get; private set; }
public string Name { get; private set; }
}
}
using System;
using NUnit.Framework;
using SharpArch.Testing.NUnit;
using ISPS.Core.Account;
namespace Tests.ISPS.Core.Account
{
[TestFixture]
public class UserTests
{
[Test]
public void CanCompareUsers()
{
var instance = new User
{
Kerberos = "nchomsky",
FirstName = "Noam",
LastName = "Chomsky",
Email = "nchomsky@gmail.edu",
Role = Role.Administrator,
IsActive = true,
CreatedOn = DateTime.Parse("1/1/1975 10:00 AM"),
ModifiedOn = null
};
var instanceToCompareTo = new User
{
Kerberos = "nchomsky",
FirstName = "Noam",
LastName = "Chomsky",
Email = "nchomsky@gmail.edu",
Role = Role.Administrator,
IsActive = true,
CreatedOn = DateTime.Parse("1/1/1975 10:00 AM"),
ModifiedOn = null
};
instance.ShouldEqual(instanceToCompareTo);
}
}
}
'RecordRequest'类和测试:
using NHibernate.Validator.Constraints;
using SharpArch.Core.DomainModel;
namespace ISPS.Core.Requests
{
public class RecordRequest : Entity
{
public static RecordRequest DefaultRecordRequest()
{
return new RecordRequest();
}
[NotNullNotEmpty(Message = "A description of the documents requested must be provided.")]
public virtual string Description { get; set; }
}
}
using ISPS.Core.Requests;
using NUnit.Framework;
using SharpArch.Testing.NUnit;
namespace Tests.ISPS.Core.Requests
{
[TestFixture]
public class RecordRequestTests
{
[Test]
public void CanCompareRecordRequests()
{
var instance = new RecordRequest
{
Description = "description"
};
var instanceToCompareTo = new RecordRequest
{
Description = "description"
};
instance.ShouldEqual(instanceToCompareTo);
}
}
}
感谢任何帮助!
答案 0 :(得分:0)
尝试在Description属性上添加[DomainSignature]属性。