S#arp Arch 和 TDD
我正在尝试加快 TDD 的步伐,因此我创建了一个新的 S#arp Arch 应用程序 (v1.6),并一直在为我的课程创建测试。不幸的是,我已经遇到了一个尚未解决的问题。
我已经为“User”和“RecordRequest”类创建了比较测试。当使用 NUnit 执行测试时,“User”测试通过,而“RecordRequest”则未通过。我试图理解为什么一个测试通过而另一个测试没有通过。错误消息是:
在 e:\WorkSpaces\Git\SharpArchitecture\Trunk\src\SharpArch\SharpArch.Testing.NUnit\SyntaxHelpers.cs 中的 SharpArch.Testing.NUnit.SyntaxHelpers.ShouldEqual(实际对象,预期对象):第 25 行 在 D:\Web\Mvc\Projects\Campus Counsel\IRS\ISPS\tests\ISPS.Tests\ISPS.Core\Account\RecordRequestTests.cs 中的 Tests.ISPS.Core.Account.RecordRequestTests.CanCompareRecordRequests():第 23 行
'用户'类和测试:
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 = "[email protected]",
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 = "[email protected]",
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);
}
}
}
感谢任何帮助!
I'm trying to get up to speed with TDD so I've created a new S#arp Arch application (v1.6) and have been walking through creating tests for my classes. Unfortunately I've already run in to an issue I've yet to resolve.
I've created a comparison test for both a 'User' and 'RecordRequest' class. When executing the tests with NUnit the 'User' test passes whereas the 'RecordRequest' does not. I'm trying to understand why one test is passing and the other is not. The error message is:
at SharpArch.Testing.NUnit.SyntaxHelpers.ShouldEqual(Object actual, Object expected) in e:\WorkSpaces\Git\SharpArchitecture\Trunk\src\SharpArch\SharpArch.Testing.NUnit\SyntaxHelpers.cs:line 25
at Tests.ISPS.Core.Account.RecordRequestTests.CanCompareRecordRequests() in D:\Web\Mvc\Projects\Campus Counsel\IRS\ISPS\tests\ISPS.Tests\ISPS.Core\Account\RecordRequestTests.cs:line 23
'User' class and test:
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 = "[email protected]",
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 = "[email protected]",
Role = Role.Administrator,
IsActive = true,
CreatedOn = DateTime.Parse("1/1/1975 10:00 AM"),
ModifiedOn = null
};
instance.ShouldEqual(instanceToCompareTo);
}
}
}
'RecordRequest' class and test:
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);
}
}
}
Any assistance is appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在 Description 属性上添加 [DomainSignature] 属性。
Try adding [DomainSignature] attribute on Description property.