For this week, I was able to implement the logic of regenerating original quantities of previous ItemHistory that were currently not computed and stored 0 as an original quantity.
Started off by using DbContext in ViewModel to get all list of histories then proceeded to use a foreach loop, where each row of history was subjected to a function that computed its original quantities, eventually saved the updated history to database using SaveAsync().
Once the logic was coded, it was time to test it. Added a test-case for previous histories original values calculation, as it was 0 previously. Faced issue with DateTime, as I was using DateTime.now(), so using OrderBy() didn’t actually ordered the rows. As this feature is considered a service of ItemHistory, it became clear that there needed to be a separate file to test it, so a HistoryServiceTest was formed.
Next, Mr.Peter decided to put the code to the test, and we discovered a bug in the algorithm that caused a source history to go unnoticed. Mr.Peter made me fix the code and showed me a better way to test. Moreover, another bug was discovered that allowed previous non-computed rows of history to take their value in current history, so the condition was changed to skip non-computed rows. Once all bugs were fixed the logic looked promising.
Finally, began Code review with Mr.Peter. Discussed on one more condition to use item status while calculating original values of ItemHistory. Added Status to History and added a test-case to check if the correct StatusId was being assigned on creation of ItemHistory.
This marked the end of my 3-month internship with Tong Hin.
