Smocks
Smocks copied to clipboard
Smocks is a library for mocking the normally unmockable. It can mock static and non-virtual methods and properties, amongst others.
## Test Code ``` [Test()] public async Task EmailConfirmation_Page_Test() { // given Smock.Run(async context => { EmailTestPageModel _testConfirmation = new EmailTestPageModel(userManager, _emailSender.Object); _testConfirmation.PageContext = MockHelpers.CreatePageContext(NSG_Helpers.User_Name2, "User", "/Register/", "/Account"); context.Setup(() =>...
Hi I try to use Smock like this ``` Smock.Run(context => { context.Setup(() => DateTime.Now).Returns(DateTime.Now.AddDays(1)); context.Setup(() => DateTime.UtcNow).Returns(DateTime.UtcNow.AddDays(1)); Task myTask = Add(); myTask.RunSynchronously(); }); ``` Then I get a null...
Sometimes Smocks randomly fails all `Run` calls and never recovers again. Changing the static method names in the `Setup` calls makes it works again for a while until it breaks...
Smocks always throws this exception when I try to run the test, even I already installed Mono.Cecil 0.10.-beta.
Unfortunately, this code `Smock.Run(context =>{ context.Setup(() => DateTime.Now).Returns(new DateTime(2000, 1, 1)); Assert.AreEqual(DateTime.Now, new DateTime(2000, 1, 1));});` throws following exception if executed in .net core mstest project: `Mono.Cecil.AssemblyResolutionException: Failed to resolve...
I've always had issues with generic methods when using smock for mocking. This solved some of it. Granted not done the most elegant of ways. Would love your ideas for...
I'am trying to run this test: ` [TestMethod] public void Test_MockStaticMethod_MethodMocked() { DateTime now = Smock.Run(context => { context.Setup(() => DateTime.Now).Returns(new DateTime(2000, 1, 1)); return DateTime.Now; }); Assert.AreEqual(now, DateTime.Now); }...
I am getting System.InvalidOperationException: 'Sequence contains more than one element' StackTrace: ``` at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source) at Smocks.IL.Resolvers.MethodResolver.FindMethod(IEnumerable`1 candidates, String name, TypeReference[] parameterTypes, Boolean isGeneric, GenericBindingContext bindingContext) at Smocks.IL.Resolvers.MethodResolver.Resolve(MethodReference methodReference, GenericBindingContext...
I would like to use Smocks from powershell. The problem I have is that Smocks throws an error if a method is not defined in a class or the method.DeclaringType...
``` context.Setup( () => Utilities.ApplyDivisors( It.IsAny(), It.IsAny() ) ) .Returns( ( a, b ) => { return a; } ); ``` When executing a Static method that calls ApplyDivisors I...