Testing / UI week

For the past week , I have been creating integration tests on my task (create short code with sequence generators) . I also did some fixes on the UI and set textboxes to “ReadOnly” during view mode .

Also , excited to be part of the launching of Tong Hin’s App to be used in the real world soon . The more that I’ve worked with my supervisor , I found out that code is easy to write , but it’s challenging to write good code . Reminds me that if I want to improve as a programmer I need to go back to basics and develop good habits . Therefore , always remember to :-

  1. KISS (Keep it simple, stupid) , never write code that is too “clever” . Use meaningful variable names so that it’s easy to read and know exactly what is going on .
  2. Clean / Refactor code at all cost , making it more efficient and keep the result same at the end .
  3. Document your code , write comments on functions , variables , entity relationships etc to make it easier to understand when revisiting your code after months .

Will progress slowly by doing these mini steps . So that’s it , see you next week !

Coding week

For this week , I did my first two-phase commit (2PC) in my next task . When adding a new item into database, multiple databases are used . That is where 2PC is implemented , because there is more than one database involved. The terms committing and rollback is often used in 2PC, committing is when updating a record to a database. A rollback is the operation of restoring a database to a previous state by canceling a specific transaction or transaction set .

During this process , I also learned the difference between repository and service in the project. Repository is to create methods for CRUD and services is used to write methods for the business logic. This was very useful to me because back then in my academy, I mixed my business logic and CRUD in the same folder, caused a lot of confusion to my trainer and myself. I believe now that I know about services the project structure in the future will be much cleaner.

That is about it for last week , I also did some HotFixes on the UI of my first task (Convert WinForm to WPF MVVM project) to increase the font-size and layout, and recreated the container in my docker to setup for my second task.

For next week, I will move on to create the integration test for my second task ( auto increment for sequence count for short code).

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 .

Week 3 in Tong Hin !

For my 3rd week in Tong Hin, I was able to create many more functions in my current task (converting project Windows Form to WPF MVVM prism application). This App is created to add users , hash and salt the password for created users and save them into database.

Currently the App is able to generate new users , update salt , reset password , show data in grid , refresh and delete user . Functions can also work with validation (username & password validations etc) . I am also able to add success / warning dialogs into the App . Most of the functions went smoothly except my entire App was unable to run for 2 times which creates panic sometimes (fixed with the help of my supervisor). The remaining function for me to fix is password (which is the hardest function among all because prism doesn’t allow to password bindings directly in the PasswordBox) and add ComboBox to the FloorsInCharge in the update user function .

Currently , I’m doing a lot of research about using Git , Source Tree (committing code and writing commit messages) generally the basic necessities a software engineer needs throughout their programming life .

My supervisor also suggested me to look up on clean code , single instance vs singleton and two-phase commit transaction which is my goal for the next week since there is only hands-on coding last week and I believe understanding the theories in programming is also equally important than the practical hands-on part .

Finally , quite intense of the first 3 weeks but glad that there is progress better than none . That is all so see you next week ! =D