Fix Overall Bug in Repository and View Model Class

First and foremost, I start the week by removing duplicate integrations tests. Then, fix failure tests on repository test class as all of it failed. It is fix by adding test_server config.xml file to map towards database. However, few tests on UOM (unit of measurement) failed. As the test class is testing actual database tests. Direct initialization is required to ensure function run throw the references, variable able to reach and store directed value.

Next, I have problem with state machine in the system. Upon deletion of selected data, the system would prompt error of state machine. State.DeleteTrigger() is not implemented to go to correct state next. Thus, the only way is to remove State.DeleteTrigger(). By removing State.DeleteTrigger(), the state machine would move from State.SelectedTrigger() to State.DeselectTrigger(), which is logical flow as mapped in State Machine class.

Repository class only handles database code which is CRUD command towards database. Thus, move business logic that wrongly implemented in repository class to Wrapper Service/View Model class. After moving those logic away from repository class, the code in repository is more tidy.

Last but not least, I find it weird that system does not prompt error under a concurrency situation when It suppose to. I ran through the system once and I found out problem occurs at my status checker from last week’s implementation. The value of _selectedStatus is set to SelectedStatus.Normal, which will constantly get latest data to update the list before I save any changes.

if (_selectedStatus == SelectedStatus.Normal)
{
_selectedStatus = SelectedStatus.Selected;
_eventAggregator.GetEvent().Publish(id); //Get Latest Data
}


Hence, database update is smooth as if there is no concurrency situation. But it will make user think they did not make any changes, if both before and after value appears to be the same. To solve this, I define _selectedStatus == SelectedStatus.Selected before I request to save changes upon editing selected data, so that it does not pass through get latest data event.

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.