Develop the Business Service Tier
Explore how to develop the business service tier by implementing core operations such as find, create, edit, and remove in a one-to-one unidirectional relationship. Understand the role of mappers converting between entities and data access objects, and learn how the service manages identifiers internally without exposing them to the user interface.
We'll cover the following...
We will begin working with the business service tier, seeing as the data access tier has been developed and is ready for integration.
“Find all records” operation
First, let’s look at the test for the find all records operation. Since this is the first function being tested, the other operations are still not developed and only the find all records operation can be tested with zero records returned when the table is empty.
Look at how to code the matching method in the business service. The data access tier uses entities, and the business service tier uses data access objects. So there exists a mapper that transforms a data transfer object to an entity and vice-versa.
Mappers
The mapper typically has two significant operations, that transform a data access object to its equivalent entity and vice-versa. One thing to observe here is that the Shipping identifier is created every time the Book is updated or added. As we have mentioned before, the management of the Shipping entity identifier will be done internally by the service. The user interface team will only pass the data values, like city field, in the Shipping entity, but is not bothered about the identifier of the Shipping entity.
Create operation
We will discuss the create test operation next. This creates an instance of the entity and checks if the count is one with the fetch all records operation.
The create method in the business service tier accepts a data access object, converts it to the equivalent entity, and then delegates to the data access tier to save it to the database.
Row identifier operation
We will define the following test operation as finding a row with a given identifier.
The similar business service operation to find a row with a given identifier will now be discussed. Yet again the same order is followed, contact the data access tier and converse with the mapper.
Remove operation
The remove test operation is next which accepts a given identifier and removes the equivalent row from the database. The test method first creates one instance, removes the same instance, and checks to see if there are zero results in the database.
The equivalent business service method is defined afterwards, which accepts an identifier and removes the matching instance from the database through the data access tier operation.
Edit operation
The last test operation is the edit which creates an instance, edits the city, and then checks if the edit was effective.
The equivalent operation of the business service is the edit operation which makes the call to the data access update method after talking with the mapper method. Please note that the edit operation does not have the identifier of the Shipping entity and generates a new instance.
In the next lesson, we’ll develop the presentation tier.