Код: Выделить всё
public void ResetMileageIfNewDay()
{
var lastUpdate = preferences.Get(_lastUpdateKey, DateTime.MinValue);
var resetTime = DateTime.Now.Date.AddHours(3);
if (lastUpdate.Date < resetTime)
{
preferences.Set(_mileageKey, 0.0);
preferences.Set(_lastUpdateKey, DateTime.Now.Date);
preferences.Set(_lastSentMileageKey, 0.0);
_logger.LogInformation("Mileage reset due to new day at 3AM");
}
}
Код: Выделить всё
[Test]
public void ResetMileageIfNewDay_ShouldReset_WhenLastUpdateBeforeResetTime()
{
var preferencesMock = new Mock();
var lastUpdate = new DateTime(2024, 9, 18, 23, 0, 0);
preferencesMock
.Setup(p => p.Get(It.IsAny(), DateTime.MinValue)) //Error here
.Returns(lastUpdate);
var service = new MileageService(preferencesMock.Object, default, default, default,default);
service.ResetMileageIfNewDay();
preferencesMock.Verify(p => p.Set("LastMileageUpdate", It.IsAny(), It.IsAny()
.ToString("o")), Times.Once);
}
Код: Выделить всё
An expression tree cannot contain a call or invocation that uses optional arguments
В чем проблема? Как передать значение LastUpdate в метод?
Я пытаюсь передать в метод фиктивные значения
Подробнее здесь: https://stackoverflow.com/questions/790 ... s-datetime
Мобильная версия