How to test logic which is dependent on current date

前端 未结 8 1425
名媛妹妹
名媛妹妹 2020-12-20 16:52

I have this method which is dependent on current date. It checks if today is Sun, Mon, Tue or Wed, then it gives 5 days of lead time for arrival of shipped items. If its Thu

8条回答
  •  無奈伤痛
    2020-12-20 17:05

    You could pass in a delegate that returns DateTime.Now during normal execution, and then in your test pass in another delegate that returns a fixed date, and assert your result based on that.

提交回复
热议问题