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 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.

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.

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.

Altering Tests based on Database Changes & Testing New Interface

I added new entity into existing database migration, and update stored value in database. Due to new entity is added, most unit tests and integration tests failed. When put those tests to debug, It appears that there is database type of exception. Hence, I need refactor existing Test Base by adding value for new entities in order for tests to assert properly.

After that, I get to play around with new interface and get familiar with it implementation. The implementation are the use of Regex, Unit of Measurement for calculation in system. Also, implementation of combo box, search bar, CRUD and data injection from few other MVVM services for functionality in system.

Utilizing EF Core Exception Handling & Debugging CRUD methods

I continued my progress with fixing delete function, which suppose to remove linked data in multiple table across the database. The failure of delete function due to certain entity are set as foreign key of other table. This problem is solved by setting null value for related foreign key in delete function. As the value of foreign key is null, deletion is allowed as how it suppose to behave.

Next, I alter sequence of textbox in View class. To ensure best user experience when they uses hotkey “Tab” to navigates over to next textbox available.

Then, Remove validation made in ViewModel class and implement it in repository class. Allowing EF core throw error whenever unique entity is input multiple time. The error will be catch, hence, prompt dialog box to notify user of application. This way is a better implementation reduce number of code, however it cause few issue in application. Issue such as user unable to create new user after error popped up to indicate similar user id appears in database.

In conjunction, RepositoryActualDbTests class is created to mock my situation. I arrange declaration, execute three seperate input ( 1st input : id = 1, 2nd input : id = 1, 3rd input : id = 2 ) , and assert expected behaviour ( Total of 2 input should be saved input database ). After quite an amount of testing and struggling, the bug is then fixed, however it requires chain fix in code. Therefore, my supervisor advice me to try out a different implementation for my create function by mocking a test.

Validating and Granting Access Rights

For new context and module added last week, I imitate some tests from example code provided and add few new tests. I also create some class to build dummy database to ease unit/integration testing. After going through some tests, I found out error when deleting data. Upon deletion, only data from 1 table is deleted, delete function suppose to remove few linked data across the database.

Before I look through into bugs of deletion, I make new implementation to validate user input in required textbox. If textbox is empty for non-nullable textbox, I create validation for system to prompt warning dialog to notify user. such as below :
if (string.IsNullOrEmpty(Wrapper.Variable))
{
_dialogService.ShowDialog( n, p, r );
return false;
}


Besides, Admin role is added to alter availability of buttons in system. I was been told to make initialization of adminUser as variable. Variable adminUser is set to bool = false initially, and will be implement in feature implementation. If bool adminUser = true, user is an admin user; bool adminUser = false, user is normal user. The reason of adding in admin role is to restrict some functionality of normal user. For normal user, the system will hinder user from edit or delete data in the system. In significant, admin user will be granted privilege to edit and delete.

Implementation of New Context and Module

As I commits previous task, I now proceed to the next task and given duration of 3 weeks. I am required to create certain function of the application, which records details of customer. Thus, I begin my progress by developing UI View in XAML class based on given example. It is to ensure standardized UI across the application.

Next, based on given example, I implement Configuration, Repository class and perform Migration to database in context file; ViewModel, Event, and Parameter class in module file. Besides, I also perform tests for customerRepository and customerViewModel to makesure they work as expected.

There are some mistake that I did during these implementation, which caused failure of saving customer data into database. After going through some repository test, everything ran successful. Then, I found out that I failed to bind my View and ViewModel. After refactoring the codes, I manage to solve my problem.

Implementation Synchronous and Asynchronous Test in TDD

After learning about implementation of integration test, my next task will be testing out concurrency situation, where ID increment behaviour upon user deleting existing data and adding new data at the same time. Test is done by implementing two different task function. The flows of tasks is controlled by using semaphore implementation which is WaitAsync() and Release().

Initially, I implement the asynchronous test by separating add data and delete data into two task. Then I create new semaphore instances of semaLock1 and semaLock2. Hence, I control the tasks using semaphore, start the test by implementing task as user’s control. task Delete start, Meanwhile, task Add will begin and end first before task Delete end. The test was partially successful as I successfully increment the ID. However, I am unable to perform the asynchronous test as the delete function throws out multiple exception, despite I implement try catch blocks.

After a long time of struggle, I seek help from supervisor and we decide to make it simple, and perform the test synchronously. The test is much more simpler, but it is sufficient to proof the behaviour of function as planned.

I also did test of deleting existing data and adding new add after in asynchronous way. Which it only requires me to use same function from last test, to decrement current ID when latest data is deleted, and increment current ID when new data added.

Lastly, what I am able to observe during these tests, is that semaphore provides a good control to manage the flow of codes, but it might put user into infinite loops whenever semaphore is implement wrongly. For example, when there is only two semaLock in my test, semaLock1.WaitAsync() and semaLock2.WaitAsync() would make both task waits for each other.

Integration Test in Development

As I continue with given project, I study about mapping of state machine, so that I am familiar with the sequence of state. As I am clear with the flow of state machine, I then perform few integration test by creating instances along with initialization of ViewModel class, Event class, mocking IDialogService and IRegionManager.

The first integration test start with New button, I ensure the button to do what I expecting it to do. On click, New button should load a view with blank form as I need to let user input new set of data, which then will be saved into the database. Next integration test is Edit button behaviour test, the button should be available as one existing sequence was selected. Edit button allow user to select existing set of data, thus, edit certain data and change should be saved. After testing Edit button, I move on to Delete button, which is tested to make sure existing data in database can be deleted according to logic function from repository class.

As I am performing tests, I learnt to use debugger upon refactoring codes. If there is error in codes during testing, I would breakpoint on line of code and run the debugger to find where is the problem located. Debugger save me a lot of time to identify where I could have done wrong. Beside debugger, sometimes I would also use logger to make sure I get the output I want during testing. I truly having hard time when I perform functionality test on my first button, but debugger and logger come in handy.

Other than integration test, I learnt about idea of semaphore where it is used to provide synchronization of tasks with signaling mechanism. Two operation used in semaphore is wait() and signal() operation. it allows more than one thread to access the crictical section, but does not allow multiple processes to enter. It allow flexible management of resources.