Why I can't Fake-Mock "System" in .net core 6.0(VS Enterprise 2022), I don't know what happened?
I was trying to use "using System.Fakes; " , But it alert "missing an assemly reference" after following
https://video2.skills-academy.com/en-us/visualstudio/test/isolating-code-under-test-with-microsoft-fakes?view=vs-2022&tabs=csharp
but I can see "System.fakes" file in my "Fakes" folder?
Please provide a working example in .net core for my question.
My code as below:
using System.Fakes;
[TestClass]
public class MockDateTimeTest{
[TestMethod]
public async void TestTodayIsLastDateOfYear(){
// Arrange
// Actbool result = false;
using (ShimsContext.Create()){
ShimDateTime.NowGet = () => new DateTime(2013, 12, 31);
result = DateTimeHelper.IsTodayLastDateOfYear();
}
// Assert
Assert.IsTrue(result);
}
}
public static class DateTimeHelper{
public static bool IsTodayLastDateOfYear()
{DateTime today = DateTime.Now;
if (today.Month == 12 && today.Day == 31)
return true;elsereturn false;
}
}
Let me know if you can use "using System.Fakes" in .net core successfully and please answer me as soon as possible.
Thanks in advance.