mardi 26 mai 2015

Mocking out a specific method during a unit test

I'm relatively new to unit testing, and brand new to Moq I have been tasked with writing up some unit tests for some pre-existing code.

I am struggling with the following method, as it makes a call to "model.importing.RubJob", which as the name suggests, kicks of a job.

Obviously, I don't want it to actually DO the job, I just want to know that it's called the method.

How would I go about achieving this (ideally avoiding any code changes):

public ActionResult ImportsAndLoads(ImportsAndLoadsViewModel importsAndLoadsModel)
        {
            Initialise(importsAndLoadsModel);
            LoadData(importsAndLoadsModel);

            if (importsAndLoadsModel.ActionToPerform == "RunJob")
            {
                using (var model = new Model())
                {
                    List<Message> lstMessage;
                    model.importing.RunJob((Jobs)Enum.ToObject(typeof(Jobs), importsAndLoadsModel.SelectedJob), out lstMessage);
                    importsAndLoadsModel.lstMessages = lstMessage;
                }
            }
            return View(importsAndLoadsModel);
        }

Aucun commentaire:

Enregistrer un commentaire