我有一个视图,它实现了一个接口。
我正在尝试对此进行单元测试,但它变得很无聊......
声明是:
public interface IView : IBaseView
{
TextBox ClientId { get; set; }
TextBox ClientName { get; set; }
Button SaveClient { get; set; }
Button NextClient { get; set; }
Button PreviousClient { get; set; }
Button DiscardChanges {get;set;}
bool ReadOnly { get; set; }
ListBox MyLittleList { get; set; }
}
[Test]
public void FirstSteps()
{
var sessionFactory = Substitute.For<ISessionFactory>();
var session = Substitute.For<ISession>();
var statelessSession = Substitute.For<IStatelessSession>();
sessionFactory.OpenSession().Returns(session);
sessionFactory.OpenStatelessSession().Returns(statelessSession);
var view = Substitute.For<IView>();
view.ClientId = new System.Windows.Forms.TextBox();
view.ClientName = new System.Windows.Forms.TextBox();
view.DiscardChanges = new System.Windows.Forms.Button();
view.MyLittleList = new System.Windows.Forms.ListBox();
view.NextClient = new System.Windows.Forms.Button();
view.PreviousClient = new System.Windows.Forms.Button();
view.ReadOnly = false;
view.SaveClient = new System.Windows.Forms.Button();
}
有没有一种观点让我动态地做到这一点?
将 View 传递给一个方法,该方法将验证那里有什么并自动调用构造函数并设置它?