Suppose I have the following class
public class Residue { public int Id {get;set;} public int WarehouseId {get;set;} public int MaterialAssetId {get;set;} public virtual ICollection<ResidueHistory> Histories {get;set;} public Residue() { this.Histories = new List<ResidueHistory>(); } } I need to add a method that will recalculate the balances from the date passed as a parameter.
I add a new method to the class body.
public void RecalculateResidueSince(DateTime since) { throw new NotImplementedException(); } The first test that I decided to implement is the way out of the method if the Histories property is empty;
Added to the solution a new project UnitTest:
[TestClass] public class TestOfResidueMethods { [TestMethod] public void Test_RecalculateResidueForEmptyHistory() { var residue = new Residue(); residue.RecalculateResidueSince(DateTime.Now); } } and then I have a stupor and what to do next in the test method, if it was a function then I would check what happened as a result with what I expect.
Tell me how to test and whether to write such tests for such methods?
UPD:
After writing this method, I modified the test method as follows:
public void RecalculateResidueSince(DateTime since) { if(!this.Histories.Any()) return; } those. if in fact there are no residuals then do nothing accordingly, but I won’t figure out how to check it in the test
Historiescollection, but at the current stage I have two possible options: ifHistoriesdoes not contain data, then you just need to exit the method without doing anything otherwise throw an exception. I don’t need an exception here because there can be no residues - BaldHistoriesis an internal implementation detail, then there is no need to check the effects on it. And if part of the official facade of the class, then the opposite is necessary. - VladD