Refactoring code based on Integration Tests

There is few thing had been done, as shown as below that involve Test-Driven Development (TDD):

As some of my repository integration tests failed, I then refactor/alter my existing implementation of updating database from ReadData to GetData. ReadData in repository class has AsNoTracking(), where entity will not be tracked. When we make changes on the entity and will not be updated anyhow after calling context.SaveChanges(). By changing to GetData which allow entity to be tracked and any changes will be updated upon context.SaveChanges(). It also make sure latest data been retrieve after they are changed.

There is many repository test been done such as should add new, should update, should remove, should throw error, should roll back. I make sure these context integration tests passes and proceed to ViewModel classes tests. Following tests is mainly to make sure my implementation works fine under multiple scenario.

Most existing ViewModel integration tests failed as refactor of initialization is needed. ViewModel tests passed after few initialization, however there is few test involving DialogServiceMock failed to launch action of dialog in ViewModel class upon debugging. Despite that, the particular scenario works well when I run the application. Therefore, I need to figure out the factor behind failure of my test.

Multithreading with EventWaitHandle

For the week, I’ve found the bug caused the pick module thread fails to refresh the sales order data grid view. This is because when the data grid collection had been initialize with new data at outside of the thread, it will no longer able to update the data grid collection and reflect in UI.

Therefore, I’ve implement EventWaitHandle to solve the issue. When user had clicked on the filter sales order check box, it send signal to the thread in order to refresh the sales order data grid view immediately. While the thread will always loop the function at 5 seconds interval by using WaitOne(TimeSpan.FromSeconds(5));

Not only that, I’ve also set the EventResetMode to AutoReset which will always set the event state to false after received signal.

Fix Multiple Bug on Database & EventAggregator

To begin the week, I faced database bug without any error prompted. When updating my data on existing database, UI/ViewModel seems like it saved the latest changes. But when data grid list is refreshed, the edited data will be removed. After perform an integration test and run debug mode, it appears to be attribute is not sync with correct variable. Hence, causing the new set of data are not able to update. Beside that, old set of data is removed due to implementation to remove existing set of data after they are edited.

Next, when two or more user is using the application, concurrency situation will occurs. Hence, a test is performed to solve this situation. Updating data list might fail whenever the data on database and ViewModel selected data is differ. After test is done, I implemented a dialog box to notify the user when their data changes failed. Despite that, context is not reload to latest data list, thus, the error dialog kept prompt as I try to update new data. Therefore, I implemented a reload function in repository class to make sure latest data is reloaded whenever data update is failed through error handling.

Other than that, I found a bug in my implementation, everything works fine until I close the window and reopen it. By doing that, It would prompt error of “Invalid SelectedId” or “Object reference not set to an instance of an object” when I try to edit/delete selected data. It appears to be an issue of event aggregator been subscribed twice. By adding a dispose( ) function and Unsubscribe event upon closing the window, the issue is solved.

Implementation of Pick History View

For this week, a new feature which is the pick history view is implemented for the pick module. As what it named, it is used to view the pick history for specific line item. On line item selected, it will parse the line item id through publishing the event. While the pick history view model will subscribe the event and load the pick history with the selected line item id to filter the pick history that belongs to the line item.

Furthermore, I’ve also implemented the filtration of sales order by its pick status. Two checkbox is added to the view for user to select the type they wish to filter the sales order in different scenarios.

Lastly, I’ve conducted the integration tests for pick module in order to test out the concurrency situation will prevent the data to be entered into database and will rollback the transaction.

Implementation of Percentage and Tiny Integer

Adding in new button to new class that derive specific calculation. Value in new class consist of percentage, which then been used in calculation of existing ViewModel classes. This class would appear as data grid combo box in main WPF application.

While I am at it, I faced an issue where class name is similar in other module. I am unable to add in new data to correct database table. All the data I saved in current module appears in database table of existing module. After some tests, I found out that both module crosslinked. I manage to make it function properly refactor class name and region name of new module.

Then, I was required to implement new attribute “IsReady” with tinyint(1) in config. It is use to signal other module that It is ready to be used. In ViewModel, I implemented a dialog to ask whether user want selected data ready to be used; under same button, it undergoes same process to undo the changes made. Button text would change based value of attribute in database:

i – (Repo) If bool IsReady = true || 1 (value in database)
(VM) button text shows “Undo Ready to Use”

ii – (Repo) If bool IsReady= false || 0 (value in database)
(VM) button text shows “Ready to Use”

The button alter between (i) and (ii) whenever IsReady is successfully updated to the database.

New feature on Pick module

For this week I’ve implement a new feature on the pick module which is to filter the line item by the current user floor. When the current user is in charge of floor 1, by selecting the checkbox, it will refresh the line item data grid view and display the line item that contains the item that located at the same floor.

In order to implement it, new aggregate of Location and Floor is created. Therefore, each Item will contains a Location that indicate their respective IDs. While each Location will contains a Items list that include all the Items in the same Location.

At last, I’ve add warning dialog that alert user that they have unsaved pick. For example, when user had picked but not saved, it will pop dialog when user is try to select the view floor only checkbox, select other sales order and select other line item.

Calculation in System and Malfunction of Buttons

Some calculation is needed in current system we are working on. Thus, I had to implement Regex for few text input. Allowing only numeric and special symbol to be used, restricts all alphabetic and any other symbol . With implementation of Regex, undefined result for calculation can be avoided.

Next, I need to allow calculation result to be 0 based on given example. Therefore, I added a check box within data grid of DetailView, hence, control my calculation result. Then, functionality is altered within DetailViewModel as we are maintaining MVVM implementation. As the check box is checked, it will set the result to 0; it will be actual result otherwise.

There is still some malfunction for state of my refresh button. Other buttons would become disable to be clicked after refresh button is triggered. I shall refactor my code to fix this issue, to ensure smooth user experience. Few unit tests is coded check if refresh button acts as intended.

User action validation on Pick Module

After the color indicator for pick module had been completed, for this week, I’ve implement the features that will alert user when they did not save their pick.

In order to implement the feature, I’ve used the data grid SelectionChanged event. This event will be fire when the selected item in the data grid had been changed. Therefore, I’ve retrieve the RemovedItems from the SelectionChangedEventArgs and compared its pickQuantity with database. If the pickQuantity is same with the database, it allow user to proceed with another row, reset to previous row if it is not same with database and prompt error dialog.

However, I’ve faced problem when the selected item is reset to previous item, but the focus is pointed on another row. Therefore, the PreviewLostKeyboardFocus event is used to solve the problem. It fired when the user attempt to leave the textbox focus. When the event is fired, it will work the same as the SelectionChanged event which compare the value of pickQuantity with database to verify whether user had modify the value. If the pickQuantity had been modified, it will reset the focus back to the previous textbox by using OldFocus.Focus();

Combo Box Implementation & Dependencies Issue

I create an implementation of “Terms”, which means setting a fixed or limited period for something. Implementation is based on previous implementation as example. In this implementation, I learnt that we can code a grid list in combo box other than normal list.

Next, I was told to alter an entity from 2 decimal places input to 3 decimal places input. It has to be alter to match certain Unit of Measurement.

Major issue that I faced is the project dependencies is directly linked to one of my project dll file. This has restrict me from debugging due to built system ignored current code I am working on. After going through possible problems, the system does not works as how it suppose to be. In the end, the problem solved by moving the dll file into “Projects” child under dependencies.

Lastly, after the dependencies issue being solved, I now face new problem in the module I am working on. The module does not save certain entity into the database. Therefore, I will need perform multiple test to figure out the problem.

Color Indicator for Pick Module

For this week, I’ve coded out the basic functionalities of the pick module which is the pick and pick all functions. While the pick function refer to when the user had enter the amount to pick, a pick data will be generate which contains the line item ID that picked, picked quantity and the user ID that perform the pick.

Before the pick is saved into database, it need to update with the stock quantity database table which increment the amount of stock and decrement in the stock quantity. For the pick all function it perform the same with the pick function with just the pick quantity is set to the line item quantity on button clicked.

After that, I’ve add in with the color indicator function which alert the user on the sales order list on which order is completely picked while which haven’t. Different line items will be indicated with their respective unique colors.

The color indicator is been called in the LoadingRow event which fired when the datagridview is generated and inserting the row into it. It read the current row cell which is the sales order first, and retrieve all the line items inside the sales order. The color indicator determine the color to set by comparing all the pick quantity with the line item quantity, when the pick quantity is equal to line item quantity, the variable picked++.

Lastly, if the picked amount is equal with the line item list count, it means all the line item inside this sales order is picked, with correct colour indicator.