I have some code that I wrote that is meant to export/transfer some objects. I need to write a unit test to make sure it works as expected, but testing is new to me and I am looking for a little help! Normally, we use selenium but in this case the code can't be run that way because the objects can't ACTUALLY be transferred in our dev environment (it would cause a whole mess of issues).
public void Execute()
{
AutomaticCompletedAppsTransferCriteria criteriaSettings = MbSettings.GetCompletedAppsTransferCriteria();
System.Timers.Timer transferTimer = new System.Timers.Timer();
transferTimer.Interval = TimeSpan.FromMinutes(30).TotalMinutes;
transferTimer.Start();
bool isTransferred = false;
if (criteriaSettings.ShouldTransfer) //If option is set in system settings to automatically transfer completed apps
{
using (currentSession)
{
isTransferred = BeginTransferCompletedApps(criteriaSettings);
}
}
}
private bool BeginTransferCompletedApps(AutomaticCompletedAppsTransferCriteria criteriaSettings)
{
DatabaseDateConverter dateTimeConverter = new DatabaseDateConverter();
TimeZoneConverter timeZoneConverter = new TimeZoneConverter();
DateTime? transferTime = DateTime.Now.Date.AddSeconds(double.Parse(criteriaSettings.TransferTime)); //Time set in system settings
DateTime currentTimeInCustomerTimeZone;
DateTime.TryParse(timeZoneConverter.ConvertToOutputValue(criteriaSettings.TransferTimeZone), out currentTimeInCustomerTimeZone); //Get current time based on timezone set in system settings
if (transferTime.Value.TimeOfDay <= currentTimeInCustomerTimeZone.TimeOfDay)
{
List<string> completedList = Settings.GetNumbersForTransfer();
Transfer(completedList);
return true;
}
return false;
}
private void Transfer(List<string> completedList)
{
if (completedList.Count > 0)
{
List<TransferredInfo> transferredList = new List<TransferredInfo>();
string newMbNumber = string.Empty;
UserInfo currentUser = UserInfo.GetUserInfo();
foreach (string number in completedList)
{
try
{
TransferObject objectToTransfer = ObjectRepository.GetTransferObject(number);
TransferObject.MarkForTransferToImportQueue(objectToTransfer , currentUser);
TransferObject.Write(objectToTransfer );
newMbLoanNumber = TransferObject.AutoImportToMb(objectToTransfer , currentUser);
transferredLoanList.Add(new TransferredInfo { WebNumber = number, MbNumber = newMbNumber, Message = "Transferred" });
}
catch (TransferException ex)
{
transferredList.Add(new TransferredInfo { WebNumber = number, MbNumber = string.Empty, Message = "Sent to queue. Duplicate social security number." });
}
finally
{
MailHelper.SendAutomaticCompletedAppsNotificationEmail(transferredList);
}
}
}
}
The most important lines that need to be tested are:
TransferObject objectToTransfer = ObjectRepository.GetTransferObject(number);
TransferObject.MarkForTransferToImportQueue(objectToTransfer , currentUser);
TransferObject.Write(objectToTransfer);
newMbLoanNumber=TransferObject.AutoImportToMb(objectToTransfer , currentUser);
The only calls that return anything I can use are TransferObject.AutoImportToMb(...), which returns a string of a new object number (identifier).
Here's my unit test code so far, but I'm not even sure if I need to use Shims for this:
[TestMethod()]
public void ExecuteTest()
{
using (ShimsContext.Create())
{
AutomaticCompletedAppsTransferCriteria criteria = MbSettings.GetCompletedAppsTransferCriteria();
List<string> transferLoanList = MbSettings.GetLoanNumbersForAutomaticTransfer();
CompletedAppsTransferTask task = new CompletedAppsTransferTask();
task.Execute();
}
}
Aucun commentaire:
Enregistrer un commentaire