Common Git Problems

The past week , I have been working on refactoring fields/methods namings for consistency in the Tong Hin application .

As I refactor the codebase , git is able to handle the new changes automatically , but it will not fit for every ideal scenario . The changes I have made caused breaking changes , some may include deleting or modifying a required field or method . Large refactors and major feature additions are good , but remember that basic communication is needed in a team before changing any fields/methods as some of them are used in separated projects and may cause merge conflicts.

Another mistake that i made was using git push –force way too often than should , and not realizing it will generate problems to everyone else . To prevent this , try not to reset or rewrite history in a branch that someone that might have already pulled without understanding the consequences .

Lastly , always remember to merge a pull request from another working branch . Even git offers powerful tools to resolve changes , but conflicts will most likely happen in a team environment when two separated branches have made edits in the same file .

That is all for this week .

First month in Tong Hin !

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 .

Remove File from Git Repository History

As I my implementation goes on, I push few commit upon my progress to bitbucket origin/develop branch. However, there is files/class that I want to remove from previous commits. After search up the internet, I get to know that git rm "filesname" command in new commit will not completely remove it from previous commits. Thus, after referring to my supervisor, I get to known there is a way to remove those files, which is by rebase and rewrite history of commit.

Beside, fix IsReady happens to have bug when I close and reopen the form. Given that I faced this situation quite often, I know that the bug is due to event aggregator is not unsubscribed during OnCloseDialog(). Thus, I just add a unsubscribe function and dispose the event for IsReady‘s view model class.

Lastly, I also add try catch statement and dialog when updating/creating data. This, is to notify user if there is error when updating changes onto database. I also add in new logic for IsCancelled in my repository class.

Implement WrapperService class & Retrieving Other Modules

Adding new attribute “isCancelled” to my ongoing project code. It is a simple checkbox with type of tinyint(1) and logic is validate in boolean. After adding the checkbox, I proceed with fixing initialization on various test class to ensure all tests pass the assertion.

Next, Implement WrapperService to manage multiple transaction for my current module. To support my implementation, I need to reference some context from multiple modules. Therefore I need to retrieve latest implemented modules that is needed in my WrapperService class.

As I am currently working on the project in a group of three. Each of us will works on our own modules. However, there is time we need to use element/attribute from other modules. Hence, we use git to retrieve and merged commits to keep my code at latest version. Sometimes it can be hard, combining latest code from origin git repository and ongoing code might cause few issues. Issue such as refactored variable name, overloading and missing function situation might occurs. Thus, I will need to refactor those code and discuss on which function to be maintain/removed.



Introduction to Materials Needed for Development

In this week, I’ve go through the resources that required for the project before getting started with the development. For the first, I’ve learnt the usage of git repository by going through some tutorials. It’s used for tracking changes made on source code during development with multiple programmers. Not only that, I’ve also learnt on how to interact with the git repository by using Bitbucket and Sourcetree such as push and pull.

Furthermore, I’ve also get myself familiar with Test Driven Development (TDD) concept which is the development approach that emphasize on testing and refactoring the functions repeatedly. Instead of just getting familiar with the concepts, I’ve also try on its exercise files in order to learn on how to implement and apply the concepts into the project.

Moreover, I’ve learnt the Prism Library for WPF which is the framework that helps to create application that have loosely coupled components. In the course, I’ve learnt how to implement the features such as delegate command, custom dialogs, event aggregator and others as well.

Lastly, after I’ve went through these materials that required for the project, I had been given the task for developing the user module which is the login and create account page. I’ve started the development from creating the repository, set up the config for the model class and create the database that run by Docker which can connect to the database without it install locally.

Implementation of Test Driven Development (TDD) and Benefits in C#

First and foremost, I learnt about C# fundamental as previously I have no experience in compiling codes using C# language. Before I start, I learnt that I requires Microsoft Visual Studio/Visual Studio Code as IDE to compile C# language and .NET Core framework as it can fully support C#. I learnt about C# syntax, generics, access modifier, arrays, looping, nullable, performing unit testing, deriving base class, defining interface and etc.

Next, I able to understand the concept of Test Driven Development (TDD), as I learnt that TDD is a great approach in software development, where it requires one repeatedly testing and refactoring particular function of code before including them into source code of project. Next, I also able to experiment and figure out how to apply TDD on C# compiler (Visual Studio) using xUnit. I noticed TDD has a lot of benefits including shorter debug cycle which saves time, produce cleaner code hence increase code quality, reduce unnecessary code, allows easy and safe refactoring.

Additional :
I am able to learn about git repository. After going through lab tutorials and several experimenting on git, I learnt that git repository is a version control system that allows us to tracks changes in source code during software development. Other than that, git repository assist in coordinating works among programmers. Furthermore, I also learn to remotely link local repository with online repository using bitbucket, to ease the storing source code of certain project online in future.