我在这里看到了一些人询问他们的单元测试的批评。我没有看到它们被关闭,所以我也想这样做。
我编写了这些测试,我认为使用动态(dynamic)可以使其更易读,但我想知道Stack Overflow社区是否有任何补充建议。
我知道使用动态(dynamic)在某种程度上是非常有争议的,并且会在C#开发人员之间引发宗教战。但我真的希望避免这种情况;我只是想撰写一些好的测试来帮助我完成我的工作 :)
我编写了这些测试,我认为使用动态(dynamic)可以使其更易读,但我想知道Stack Overflow社区是否有任何补充建议。
我知道使用动态(dynamic)在某种程度上是非常有争议的,并且会在C#开发人员之间引发宗教战。但我真的希望避免这种情况;我只是想撰写一些好的测试来帮助我完成我的工作 :)
[TestMethod]
public void TestAllocation() {
SearchView.StubPropertyNumValueThenSetUpSearchView<WellDetail>("TX", Property.WorkingInterestTaxSubtypeId);
Presenter.SetUpPhaseAndFmvValues(Phase.PhaseIdForForRenderAppraiser, 1000);
AddTheseItems(
new { PropNum = "pn1", CAN = "can1", MostRecentFmv = 10 },
new { PropNum = "pn1", CAN = "can1", MostRecentFmv = 10 },
new { PropNum = "pn1", CAN = "can1", MostRecentFmv = 10 },
new { PropNum = "pn1", CAN = "can1", MostRecentFmv = 10 },
new { PropNum = "pn1", CAN = "can2", MostRecentFmv = 40 },
new { PropNum = "pn1", CAN = "can2", MostRecentFmv = 40 },
new { PropNum = "pn1", CAN = "can2", MostRecentFmv = 40 },
new { PropNum = "pn2", CAN = "can1", MostRecentFmv = 50 },
new { PropNum = "pn2", CAN = "can1", MostRecentFmv = 50 });
Presenter.Process(SearchView, ItemsToProcess);
AssertTheseItemsExist(
new { NumberOfTimes = 4, PropNum = "pn1", CAN = "can1", FmvCalculated = 100 },
new { NumberOfTimes = 3, PropNum = "pn1", CAN = "can2", FmvCalculated = 400 },
new { NumberOfTimes = 2, PropNum = "pn2", CAN = "can1", FmvCalculated = 500 });
}
private void AddTheseItems(params dynamic[] MassUpdateDtos) {
foreach(dynamic item in MassUpdateDtos)
ItemsToProcess.Add(new MassFMVUpdateDTO(new WellDetail() { PropertyNum = item.PropNum, CountyAccountNum = item.CAN }, new FMVHistory(), 0, item.MostRecentFmv));
}
private void AssertTheseItemsExist(params dynamic[] uniqueTargets) {
foreach (dynamic target in uniqueTargets)
Assert.AreEqual(target.NumberOfTimes, ItemsToProcess.Count(f => f.PropertyNum == target.PropNum && f.CountyAccountNum == target.CAN && f.FMV == target.FmvCalculated));
}
AddTheseItems
只需要加上类名即可变长:new Params { PropNum = "pn1", CAN = "can1", MostRecentFmv = 10 },
- Daniel Hilgarth