vendredi 4 décembre 2020

Testing Void Methods calling other Void Methods using NUnit and Moq

I am currently attempting to test the below code using NUnit and running into major problems as they are both void methods, one calling the other with the second calling another two methods. I was attempting to test the occurrences of the different methods being called but not sure if this is feasible which multiple void methods.

public class ApplicationResponseService : IApplicationResponseService
   {
       private readonly ITenantLookUpService _lookUpService;
       private readonly IConfigurationManagement _configurationManagement;
 
       public ApplicationResponseService(ITenantLookUpService lookUpService, IConfigurationManagement configurationManagement)
       {
           _lookUpService = lookUpService;
           _configurationManagement = configurationManagement;
       }

       public async void IterateTenants()
       {
           var allTenants = await _lookUpService.GetAllTenants();
           var connectionName =
               _configurationManagement.getConfig()[ConfigurationKeys.CONNECTION_LOOKUP_NAME];

                       foreach (var tenant in allTenants)
           {
               var tenantConnections = await _lookUpService.GetTenantDetails(tenant.OrganisationId);
               {tenantConnections.Connections.Count} connections for {tenant.OrganisationId}");
               processResponses(tenantConnections);
           }
       }

       public async void processResponses(TenantConnectionDetails tenantDetails)
       {
           var organisationId = tenantDetails.OrgId;
           var connection = _lookUpService.GetTenantConnectionDetails(tenantDetails.Connections, _configurationManagement.getConfig()[ConfigurationKeys.CONNECTION_LOOKUP_NAME]);
           var onlineConnection = _lookUpService.GetTenantConnectionDetails(tenantDetails.Connections, _configurationManagement.getConfig()[ConfigurationKeys.CONNECTION_NAME]);

          
           var responseToProcess = await collectResponses(organisationId, connection);

           foreach (var response in responseToProcess.LoanAppResponse)
           {
               var message = response.WholeTransferSuccessful ? formatSuccessResponse(response) : formatFailureResponse(response);

               message.OrganisationId = organisationId;
               message.ConnectionName = onlineConnection;

               EncryptAndSend(message, tenantDetails);
               deleteResponses(response, connection, organisationId);
           }
       }

I was attempting to go down the route of Mocking the class in general. Then calling the IterateTenants method and checking if ProcessTenants had any occurrences but unfortunately this was a dead-end.

Any insight or direction would be greatly appreciated!

Aucun commentaire:

Enregistrer un commentaire