We are using the Q1 2011 release (at least until Q1 2012) is released. I have a few problems related to objects that should be mocked and arranged not behaving as they are arranged/mocked. We have a base class that we use for all of our testing within a class in the code, and then each method within code has a TestClass associated with it, with the seperate test methods for that method under test defined within.
here is the base class
now a class and method that the test is failing on....
with this particular example we have two issues.
1. The Call to CheckForSiteNumberAndUserName executes the original code despite the DoNothing on the arrange.
2. The call to GetEquipmentDetails within the SPM150 Mock, does nothing (as it should) but returns null despite the fact that it is arranged to return the ExistingItemMock (created in the OnInitialize method)
Any help is greatly appreciated.
here is the base class
[TestClass] public class SPM150ControllerTestBase { public IAssetsService AssetsServiceMock { get; set; } public INavigationService NavigationServiceMock { get; set; } public ISPM150Service SPM150ServiceMock { get; set; } public IGlobalData GlobalDataMock { get; set; } public SPM150Controller Target { get; set; } [TestInitialize] public void TestInit() { AssetsServiceMock = Mock.Create<IAssetsService>(); SPM150ServiceMock = Mock.Create<ISPM150Service>(); NavigationServiceMock = Mock.Create<INavigationService>(); GlobalDataMock = Mock.Create<IGlobalData>(); Target = Mock.Create<SPM150Controller>(Behavior.CallOriginal, new object[] { AssetsServiceMock, SPM150ServiceMock, NavigationServiceMock, GlobalDataMock, null }); OnInitialize(); } protected virtual void OnInitialize() { } }now a class and method that the test is failing on....
[TestClass] public class UpdateEquipmentTest : SPM150ControllerTestBase { public IEquipmentListItem UpdateItemMock { get; set; } public IEquipmentListItem ExistingItemMock { get; set; } //[TestInitialize] //public void OnInit() //{ // base.TestInit(); //} protected override void OnInitialize() { UpdateItemMock = Mock.Create<IEquipmentListItem>(); ExistingItemMock = Mock.Create<IEquipmentListItem>(); //Mock.Arrange(() => UpdateItemMock.BenchmarkValue).Returns(100); //Mock.Arrange(() => UpdateItemMock.Classification).Returns("No Class"); //Mock.Arrange(() => UpdateItemMock.DeviceName).Returns("A Device"); //Mock.Arrange(() => UpdateItemMock.IPAddress).Returns("000.000.000.000"); //Mock.Arrange(() => UpdateItemMock.Request).Returns(0); //Mock.Arrange(() => ExistingItemMock.BenchmarkValue).Returns(100); //Mock.Arrange(() => ExistingItemMock.Classification).Returns("No Class"); //Mock.Arrange(() => ExistingItemMock.DeviceName).Returns("A Device"); //Mock.Arrange(() => ExistingItemMock.IPAddress).Returns("000.000.000.000"); //Mock.Arrange(() => ExistingItemMock.Request).Returns(0); UpdateItemMock.BenchmarkValue = 100.0; UpdateItemMock.Classification = "No Class"; UpdateItemMock.DeviceName = "A Device"; UpdateItemMock.IPAddress = "000.000.000.000"; UpdateItemMock.ModbusUnitId = 100; UpdateItemMock.Request = 0; //set with default values can change if needed... ExistingItemMock.BenchmarkValue = 100.0; ExistingItemMock.DeviceName = "A Device"; ExistingItemMock.ModbusUnitId = 100; ExistingItemMock.IPAddress = "000.000.000.000"; ExistingItemMock.Request = 0; Mock.Arrange(() => Target.LogBenchmarkValueChange(Arg.AnyString, Arg.AnyDouble, Arg.AnyString, Arg.AnyString, Arg.AnyDouble)).DoNothing(); Mock.Arrange(() => Target.LogIPChange(Arg.AnyString, Arg.AnyString, Arg.AnyString, Arg.AnyString, Arg.AnyString)).DoNothing(); Mock.Arrange(() => Target.LogModBusUnitIdChange(Arg.AnyString, Arg.AnyInt, Arg.AnyString, Arg.AnyString, Arg.AnyInt)).DoNothing(); Mock.Arrange(() => Target.LogDeviceNameChange(Arg.AnyString, Arg.AnyString, Arg.AnyString, Arg.AnyString, Arg.AnyString)).DoNothing(); } [TestMethod] public void Test0020CheckForSiteAndUserCalledCorrectParametersVersion1() { Mock.Arrange(() => Target.CheckForSiteNumberAndUserName(Arg.AnyString, Arg.AnyString)).DoNothing().OccursOnce(); Mock.Arrange(() => SPM150ServiceMock.GetEquipmentDetails(Arg.AnyInt)).Returns(ExistingItemMock); Target.UpdateEquipment("12345", UpdateItemMock, "Hi Bob!"); //Target.Assert(); //Target.Assert(x => x.CheckForSiteNumberAndUserName("12345", "Hi Bob!")); Mock.Assert(() => Target.CheckForSiteNumberAndUserName("12345", "Hi Bob!")); }}with this particular example we have two issues.
1. The Call to CheckForSiteNumberAndUserName executes the original code despite the DoNothing on the arrange.
2. The call to GetEquipmentDetails within the SPM150 Mock, does nothing (as it should) but returns null despite the fact that it is arranged to return the ExistingItemMock (created in the OnInitialize method)
Any help is greatly appreciated.