For this week , I have completed my first task (converting WPF to MVVM project) . I am finally able to move on to creating the unit tests for the completed task . For the unit tests , one of the important NuGet package used is Moq . Moq is a mocking framework for C#/.NET. It is used in unit testing to isolate your class under test from its dependencies and ensure that the proper methods on the dependent objects are being called.
For Moq : Setup , Verify & Callback is the most common command . The “Setup” command mocks a method and “Return” the specified value called . “Verify” marks the expectation of the mock and you can verify how many times it is called with Times.Once or Times.Never . A callback is a piece of code that is passed into to a method parameter to be executed from within that method. When using Moq to create test doubles, you can supply callback code that is executed when an expectation is met.
Before completing the first task , codes have to be pushed into the branch. With lack of experience using git , I committed 4-5 of my commits into the wrong branch resulting in having to create a new feature in the branch . To fix this , my supervisor taught me how to cherry pick ( git cherry-pick [commit reference] ) , picking a commit from a branch and applying it to another to undo changes.
Another scenario that happened this week is pushing the commit into the wrong branch . https://dev.to/moshe/remove-accidentally-pushed-file-from-a-git-repository-history-in-4-simple-steps-18cg (will link the solution provided by my supervisor here if mistakes happens again) . Reminder : check if in correct branch in git history before git push, git pull if in incorrect branch.
Lastly , I learned about the ternary operator (which is a substitute for if..else statement used a lot in my academy back then) and is much shorter version . For example , Condition ? Expression1 : Expression2 ; if the statement is true , the statement will return Expression1 and return Expression2 if false . It is called a ternary operator because the operator takes 3 operands . That is all for this week .
