Home
Search

Start | Blogs | Umbraco | Win32 not a valid FileTime

2019-10-15

Umbraco

Umbraco Not a valid Win32 FileTime solution

When unit testing a method using .GetCropUrl(), an exception can be thrown.

Error message:


Argument out of range exception. Not a valid Win32 FileTime

exception is thrown when the method is called in unit tests.

Cause: The extension method uses ToFileTimeUtc() method on the media items property "UpdateDate". By default in unit tests, the property value is DateTime.Min.

Solution: Mock the property UpdateDate on the media item to be, for example. DateTime.Now().


Mock<IPublishedContent> blogPageMock = SetupContentMock(DocumentTypeAlias.BlogPage, blogPageProperty1);
blogPageMock.Setup(x => x.UpdateDate).Returns(DateTime.Now);