I've seen a few questions on here of people asking for criticism of their unit tests. I haven't seem them get closed, so I'd like to do the same.
I whipped up these tests, which I believe are made more readable by using dynamic, but I was wondering if anyone in the SO community had anything to add.
I know the use of dynamic is for some reason very controversial, and for some reason starts religious wars amongst C# developers. I'm really hoping to avoid that; I'm just trying to write some good tests to help me do my job :)
[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));
}
dynamicin your case?AddTheseItemswould only be longer by the name of your class:new Params { PropNum = "pn1", CAN = "can1", MostRecentFmv = 10 },