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.

Development of User Module

For the second week, I’ve continue with the development of user module that being assigned in last week. For last week’s progression, the user context had been developed and configured. Therefore, I’ve started to develop the UI for both login and registration view.

While the process of developing the view model for both views, I had face the problem on the PasswordBox UI element which blocks the binding from view model. After I referred the sample code and search for solutions, I’ve learnt and able to handle the parameter passing of PasswordBox elements to view model.

Not only that, I’ve also setup some unit tests for all view models that I’ve created. However, I was not able to use the [Fact] attribute for the unit tests since the unit tests will require UI element to run the unit test for the login and registration view model. Therefore, instead of [Fact] attribute, I’ve used the [StaFact] attribute which allowed the tests to run with the UI elements.

Lastly, I’ve being assigned with new task which is to develop a new view that allow user to modify their display name and password as well.

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.

Introduction to Materials Needed for Development

In this week, I’ve go through the resources that required for the project before getting started with the development. For the first, I’ve learnt the usage of git repository by going through some tutorials. It’s used for tracking changes made on source code during development with multiple programmers. Not only that, I’ve also learnt on how to interact with the git repository by using Bitbucket and Sourcetree such as push and pull.

Furthermore, I’ve also get myself familiar with Test Driven Development (TDD) concept which is the development approach that emphasize on testing and refactoring the functions repeatedly. Instead of just getting familiar with the concepts, I’ve also try on its exercise files in order to learn on how to implement and apply the concepts into the project.

Moreover, I’ve learnt the Prism Library for WPF which is the framework that helps to create application that have loosely coupled components. In the course, I’ve learnt how to implement the features such as delegate command, custom dialogs, event aggregator and others as well.

Lastly, after I’ve went through these materials that required for the project, I had been given the task for developing the user module which is the login and create account page. I’ve started the development from creating the repository, set up the config for the model class and create the database that run by Docker which can connect to the database without it install locally.

Button Behaviour, Concurrency Situation and Sourcetree

To begin with the week, I continued from last part I left off previous week. I did some research and some trials to allow the application to store data into two attributes from one input. It is troublesome for me at first, but I managed it after half day of experimenting and with the guidance of supervisor.

After I figured out storing data, I then started to plan on how I should proceed my task as below:
1. Read and compare two value from columns of database.
2. Statement for decision making algorithm.
3. Call existing functions to control behaviour of delete button.
4. Delete selected row when button is Enabled.
5. Pop ups dialog box for confirmation as delete button clicked.
6. Pop ups Error message whenever selected row is unable to be deleted.

Next, I begin with some testing based on existing code, hence, start my implementation. First of all, I learnt that AsNoTracking( ) in Entity Framework is useful when reading data from database. It is said so, AsNoTracking queries are quicker to execute compared to tracking queries. I understood that, I should use it whenever I don’t need to update retrieved data. However, I retrieved the data using tracking query, and perform test using logger to make sure I implementing it correctly. I proceed with comparing and if-else logic to decide behaviour of button.

After that, I implement a dialog box confirmation upon user’s delete command. Also, when logic allows deletion of selected data, it will completely remove it from database table. When logic forbid deletion of data, error message is invoked to inform user stating “Unable to delete data as it has been used”.

Apart from given task, I also learnt about idea of concurrency when things happen at the same time in a system. There is situation whenever two or more user adding new data with the same ID at the same time. Hence, there are some few example codes, for me to go through in order to handle such situation.

Lastly, I get in touch on using Sourcetree, A GUI software that is simplified to interact with git repositories. I learnt to use Sourcetree to stash and apply my version of codes of my project file. Besides, I also learnt how to solve conflicts when a group project is combined in Sourcetree. I could not agree less that Sourcetree provides idea of git and good features that support team implementation.

Getting Started with Small Portion of Project Source Code

As I went through some learning material that will be use in upcoming project, I am given an introduction towards an on-going project beginning with understanding the business logic behind the project.

After I was given the source code, I learnt about Docker, a set of platform that uses OS-Level virtualization to deliver software in packages called as containers. It allows me to run an image of database and connect to it without having the database install locally. In order to connect to the database of the project, I need to invoke an command in Docker to start the image before I can run the project smoothly, then, connect to database using Docker’s IP address and port.

As I done with connecting to database, I begin to play around and perform some unit testing. Then, I was taught how to drop certain column, perform migration process between project and database after add in a new column to store new set of data.

Lastly, I was given a task to disable a button click over certain condition. I felt hard and still unable to complete my given task. I believe it is still due to me lack of experience and knowledge, but I still working on it until I manage to complete the task given.

Get to Know About Prism Library for WPF

I acknowledged that Prism is great framework that support MVVM (Model View View Model) design pattern. First of all, I am introduced to few terms based on the course I followed on some courses and tutorials (Title : Introduction to Prism for WPF).

Next, I learnt how to perform view injection to allow certain text to be displayed when i run the the program. It is performed simply just by linking instance of region to specific region called as ” NAME” in XAML file. Other than that, I also followed some step to implement View Model Locator and construct property to allow connection between View(XAML file) and View Model(CS file) in prism.

Beside that, I came across to know about delegate command, where it is used to implement ICommand without require an event handler. Delegate command can invoke method defined in ViewModel and let u control the properties on view from ViewModel. Hence, I played around with ICommand provided by prism that bind UI gesture to particular action/event. Along side of that, I also try out composite command, where it is able to invoke multiple view on one touch and IEventAggregator, which is a good implementation when you have lots of objects that are potential event sources.

Lastly, I understood the purpose of Dialog in prism library as it is used to notify user of current system progress or asking for user’s confirmation upon an action. In dialog, it is divided into two type, where one is block interaction with the rest of the application (modal) and one is to allow user to still interact with the other part of application (non-modal).

Conclusion, I do have to admit spend quite some time understanding how prism library works as I am still weak in programming knowledge, but thanks to guidance from my supervisor and going through it several times, I managed to get a grab on my understanding.