-
-
Notifications
You must be signed in to change notification settings - Fork 794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Worthwhile to add in Quickstart? #230
Comments
👍 sounds good. Should that be part of the current quickstart wiki or a On Wed, Dec 23, 2015 at 11:27 AM Seth Dorris notifications@github.com
|
@sethdorris I agree, coming into mocking for the first time has not been easy for me either. I am even familiar with lambda expressions, etc, so it is more the concept of what a mock is, can/cannot do, and how it works. If I did not have someone in the office to help I would have had a great deal more trouble. @kzu Good timing ;). IMHO it could be a part of quickstart. |
@kzu I thought a bit more about it and I came up with a sample layout. If this is not a valid use of Moq please correct me. The
|
So This is kind of where I am heading... Before I get deeper, anyone have any suggestions? Would you prefer I just finish it and we can make adjustments as necessary (especially to styling :P) The beginner's guide to Mocking (using Moq)Obivously there is always more than one solution for writing unit tests / mocking. In this guide I will show you how to Mock using a test class with properties that contain the Classes I want to mock and my Repository. This guide will show you how to write Setup and Teardown helper methods for your Test Class.. but more on that later. Table of ContentsAssumptions AssumptionsIn order to really understand what is happening, you probably should be familiar with the following concepts:
Why does one need to Mock?Mocking is used when you need to test your application's interaction with the database. This will ensure that your test methods do not inject data into your database when the test methods are run. Explore Full Example** Let's explore the following code as a whole and then we can break it down bit by bit **
Step OneCreate Test Class with Private Data Members Containing Your Mocks and Repo.Let's take a look at the first part of the code you saw earlier:
In the line of code As a reminder, I have not Mocked anything at this point. I've merely created private data members that will hold my Mocks. Second StepCreate Setup Helper MethodLet's take a look at this bit of code:
What this does:the This seems simple enough right? I am still setting up my environment so that I can actually write my tests. I've now mocked my DbContext class So why did you pass in This is because I have MOCKED my context. MOQ API reads - In other words using |
@sethdorris Sorry for the slow response, holiday break ;). I started going through your example.
Screenshot 1Screenshot 2 |
The build errors are due to the usage of MSTest. I'd switch to xunit, since Also, what do you guys think about making this part of the Wiki? Or maybe On Mon, Dec 28, 2015 at 1:18 PM TJSoftware notifications@github.com wrote:
|
@kzu I think that this needs to be on the Wiki, it does not need to be part of the quick start necessarily, perhaps a new wiki page, but part of the quick start makes sense as well. When I took a look at moq.github.io I did not see any areas with tutorials, just a twitter feed and a couple of old articles. I like the idea of more resources, however I am currently not maintaining the code so I tend to say only code in one place. I will defer to you on moq.github.io. |
Yeah, the website is basically moqthis.com, provided by github pages The goal was to have a nice homepage there, like http://autofac.org/, which I'm all for getting 99.99% inspiration from Autofac, and I'm sure Nick will On Mon, Dec 28, 2015 at 2:07 PM TJSoftware notifications@github.com wrote:
|
So do you guys want me to edit my guide to use XUnit then? What additional changes do you want to see in the write up itself? I do appreciate the feedback gentlemen. |
@sethdorris Outside of placing all classes ( |
👍 On Mon, Dec 28, 2015 at 2:56 PM TJSoftware notifications@github.com wrote:
|
Thanks gents. I will work on those changes.. would you prefer to see a draft of the completed write up in here ? |
Sure thing. Maybe a proper PR would make it easier to comment on specific On Mon, Dec 28, 2015 at 3:09 PM Seth Dorris notifications@github.com
|
I hope to have the edits made and up by Saturday night. |
Sorry it's been a while since I have updated this however, I was looking at moving to using xunit for this, and the reason why I chose to stick with MS unit test was due to its [TestInitialize] tag.. @TJSoftware I do not get build errors when using MS unit test with MOQ... I would LIKE to keep using MS Unit test, as I BELIEVE replicating the TestInitialize feature in xUnit is a lot more work.... can we stick with using MS Unit Test? |
NP, I know how busy life gets.
You can use whatever unit testing you like, however, please keep in mind this comment from kzu.
That is why it is helpful for others to work with xUnit as Moq will work with xUnit. I have been focused on some other learning for the time being. I will try to improve on my simple example by adding some comments on my understanding of how this works. Perhaps we can start with a simple generic example first then build up to a real world example. I do not expect to have any work on this till the weekend (or later). |
@TJSoftware I haven't experienced any issue with MS Test with Moq.. Totally understand, this guide, as we both are well aware, is not something that is pressing.. and I can only get around to it every now since my free time is limited. |
@sethdorris, @TJSoftware - how shall we go on with this? You may have seen that I closed the PR, mostly because I feel such content should go to the wiki and not into the readme... and it's also been dormant for a long time. I would suggest that if you want to continue working on this, start a new wiki section titled "User contributions" or similar, then put your article as a page under it. As the wiki is collaboratively edited, the content doesn't have to be perfect right from the start, I'd reserve discussions here for major debatable points. If you do continue with this, I'd like to add a couple of points for your consideration:
I am closing this issue for now, assuming that you guys are busy elsewhere. If you want to resume work on this, feel free to start editing in the wiki, and if there's need for discussion, I'm happy to reopen this issue. |
Suggestion for Adding to QuickStart Guide
A Beginners Guide to Mocking and why
Proposed Table of Contents
1. Use Cases
A. Context Mocking
B. Repo Mocking
C. DBSets Mocking
2. Setting up your Mocks
A. Mock Context
B. Mock Repo
C. Mock Sets
3. Test Setup and Cleanup
-Why and how
...etc
Would implementing a beginners guide to mocking be something that should be done, as I found it difficult to know where to begin for mocking and what I needed to mock when I first started mocking.
The moq docs are good, but I think geared more towards users with mocking experience?
If this would be something perceived as value added, it is something that I could work on..?
The text was updated successfully, but these errors were encountered: