{"action":"created","issue":{"url":"https://api.github.com/repos/voat/voat/issues/595","labels_url":"https://api.github.com/repos/voat/voat/issues/595/labels{/name}","comments_url":"https://api.github.com/repos/voat/voat/issues/595/comments","events_url":"https://api.github.com/repos/voat/voat/issues/595/events","html_url":"https://github.com/voat/voat/pull/595","id":93062975,"number":595,"title":"Unit Testing POC","user":{"login":"bob3695","id":708254,"avatar_url":"https://avatars.githubusercontent.com/u/708254?v=3","gravatar_id":"","url":"https://api.github.com/users/bob3695","html_url":"https://github.com/bob3695","followers_url":"https://api.github.com/users/bob3695/followers","following_url":"https://api.github.com/users/bob3695/following{/other_user}","gists_url":"https://api.github.com/users/bob3695/gists{/gist_id}","starred_url":"https://api.github.com/users/bob3695/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bob3695/subscriptions","organizations_url":"https://api.github.com/users/bob3695/orgs","repos_url":"https://api.github.com/users/bob3695/repos","events_url":"https://api.github.com/users/bob3695/events{/privacy}","received_events_url":"https://api.github.com/users/bob3695/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2015-07-05T00:55:46Z","updated_at":"2015-07-12T05:30:31Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/voat/voat/pulls/595","html_url":"https://github.com/voat/voat/pull/595","diff_url":"https://github.com/voat/voat/pull/595.diff","patch_url":"https://github.com/voat/voat/pull/595.patch"},"body":"The purpose of these unit tests are to establish a baseline of the \"working\" state. One of the biggest challenges when it comes to refactoring a large(-ish) codebase with little to no testing is the ever pressing question of \"Did I break it?\". Obviously only two tests won't give enough confidence to answer \"YES!\" to that question but its a start. If the concept is accepted I can write more tests fairly quickly so we can go into refactoring with a lot more confidence.\r\n\r\n# Technologies Introduced\r\n* xUnit\r\n * Reason: Its a lot more robust testing framework then MSTest... and Microsoft themselves are switching to it see MSBuild github issues.\r\n* Moq\r\n * Reason: Needed to mock some stuff for the arranging of the tests. Moq is always a good option\r\n* AutoFixture\r\n * Reason: Arranging tests is terrible... This allows for defining certain data to come in automatically.\r\n* Effort\r\n * Reason: Unit Test the database!\r\n\r\n# Core changes\r\n* Add a constructor to HomeController\r\n * Reason: Since the project doesn't have any DI setup yet I needed to open a way to pass in the database object instead of creating one\r\n* Add a constructor to whoaverseEntities\r\n * Reason: I needed to pass in a DbConnection so it connects to Effort instead of an actual database\r\n\r\n# Known limitations (without further core changes)\r\n* Currently the two tests are testing for when a user is not logged in. Without making some changes to the actual code I can't test the logged in flow because Utils.User.SubscriptionCount(User.Identity.Name) creates its own whoaverseEntities. Need to figure out a way to pass in that db there as well with minimal impact\r\n\r\n# Overview of how the tests work\r\n* Each test has a VoatTest attribute which setups up AutoFixture so it creates the whoaverseEntities object correctly\r\n* AutoFixture auto populates data into all the fields of all the other parameters on the test.\r\n* Some manipulation occurs to get the data to fix the requirements of the database. \r\n* Adds all the data to the \"in-memory\" database\r\n* Creates a HomeController and setups a Controller Context (currently only for a logged out user)\r\n* Calls the index method, pulls the model off of the result and validates it contains the number of messages it has on it\r\n\r\n# Future plans (if this PR is deemed as the way the project wants to go with Unit Testing)\r\n* Add more tests so that we are not just validating the count but the actual content (this would also expand on these as well to check that)\r\n* Refactor SubscriptionCount method to allow for unit testing so the Index method is fully testable.\r\n* Craft tests for each of the other methods that have a lot of business logic in the action.\r\n\r\nWhat are the teams thoughts on these tests?"},"comment":{"url":"https://api.github.com/repos/voat/voat/issues/comments/120689300","html_url":"https://github.com/voat/voat/pull/595#issuecomment-120689300","issue_url":"https://api.github.com/repos/voat/voat/issues/595","id":120689300,"user":{"login":"Romoku","id":507083,"avatar_url":"https://avatars.githubusercontent.com/u/507083?v=3","gravatar_id":"","url":"https://api.github.com/users/Romoku","html_url":"https://github.com/Romoku","followers_url":"https://api.github.com/users/Romoku/followers","following_url":"https://api.github.com/users/Romoku/following{/other_user}","gists_url":"https://api.github.com/users/Romoku/gists{/gist_id}","starred_url":"https://api.github.com/users/Romoku/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Romoku/subscriptions","organizations_url":"https://api.github.com/users/Romoku/orgs","repos_url":"https://api.github.com/users/Romoku/repos","events_url":"https://api.github.com/users/Romoku/events{/privacy}","received_events_url":"https://api.github.com/users/Romoku/received_events","type":"User","site_admin":false},"created_at":"2015-07-12T05:30:31Z","updated_at":"2015-07-12T05:30:31Z","body":"I merged this into my fork. The unit tests look good."}}