Friday, February 3, 2012

boilerplate for command processor command tests


using System;

using System.Web.Mvc;

using OurApp.Core.Entities;

using OurApp.Web.UI.CommandProcessing;

using OurApp.Web.UI.CommandProcessing.Commands;

using OurApp.Web.UI.Models.InputModels.Orders;

using Microsoft.VisualStudio.TestTools.UnitTesting;

   

namespace OurApp.Tests.Unit.UI.CommandProcessing.Commands

{

   [TestClass]

   public class OrderCommandTestsTemplate : CommandTestBase

   {

      [TestMethod]

      public void boiler_plate_testing_skeleton_sample()

      {

         //input model

         var inputModel = new OrderInputModel();

         

         //output model

         var order = new Order();

         

         //mock your behaviors

         MocksRegistry.OrderRepositoryMock.Setup(x => x.Save(order));

         

         Func<ActionResult> success = () => new ViewResult();

         Func<ActionResult> fail = () => new ViewResult();

         

         //build target

         var command = new EditOrderCommand(inputModel,

               new Actions(null).OnSuccess(success).OnFailure(fail));

         

         //excersise sut

         command.Process();

         

         //expectations

         Assert.IsFalse(inputModel.Processed);

      }

   }

}

No comments:

Post a Comment