question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fill with Mock Local

See original GitHub issue

I am exploring Moq and kicking the tires on the extension here. Actually, I’ve had it installed forever and am now finally checking it out. 😁

Everything looks handy. Thank you for taking the time to develop it.

The one thing I noticed is that the Fill with Mocks command seems to create outer instances that are placed in the containing class.

In my case, I would prefer these to be local to the test function.

So instead of this:

	public sealed class Tests
	{
		Mock<IPromote> _previous;
		Mock<IPromoted> _promoted;

		[Fact]
		public async Task Verify()
		{
			_previous = new Mock<IPromote>();
			_promoted = new Mock<IPromoted>();
			var sut = new StateAwarePromote(_previous.Object, _promoted.Object);
		}
	}

It creates this:

	public sealed class Tests
	{
		[Fact]
		public async Task Verify()
		{
			var previous = new Mock<IPromote>();
			var promoted = new Mock<IPromoted>();
			var sut = new StateAwarePromote(previous.Object, promoted.Object);
		}
	}

Would it be possible to create a command that does this?

Thank you for any consideration and for making this cool extension!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
lconstancommented, Jul 21, 2020

Yes indeed, 2 commands would be better. The idea with the existing one is that you use it from the Setup method; that’s why it creates fields.

I am going to create 2 commands, 1 for fields and 1 for local variables 👍

1reaction
lconstancommented, Jul 29, 2020

I’m closing this as it will be available in the next release of the plugin. Thanks !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Mockito to mock a local variable of a method
What I need is to set the dateTime to some specific date while it is being tested. Is there a way I can...
Read more >
Mockito mock examples
Mockito mocking framework provides different ways to mock a class. Let's look at different methods through which we can mock a class and ......
Read more >
Stubbing and Mocking with Mockito and JUnit
Learn how to create true unit tests by mocking all external dependencies in your JUnit classes with the help of Mockito.
Read more >
Mocking local variables within the method-under-test
In order to circumvent using a physical database, I mock "helper.LoadFromDB" in my unit test. The delegate I use in the "DoInstead" method ......
Read more >
Mockito's Mock Methods
In this tutorial, we'll illustrate the various uses of the standard static mock methods of the Mockito API.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found