I'm using/implementing JustMock for the first time. I've watched the webnair, but I can't seem to get the Mocked object working properly. We have a full paid version of JustMock.
I have an internal database access layer object, "OperationsData", and an "ComponentException" object with a private constructor. I'm trying to write the unit test method for the Persist method of the ComponentException object. The unit tests are all in a separate project so the internal class and the private constructor use a "_Accessor".
When I run the unit test it complains that OperationsData connection string isn't instantiated. Why isn't it just using the mocked object and return the expectedExceptionId that I want? Thanks.
This is the ComponentException.Persist() ...
This is the UnitTest...
PS. I also tried...
I have an internal database access layer object, "OperationsData", and an "ComponentException" object with a private constructor. I'm trying to write the unit test method for the Persist method of the ComponentException object. The unit tests are all in a separate project so the internal class and the private constructor use a "_Accessor".
When I run the unit test it complains that OperationsData connection string isn't instantiated. Why isn't it just using the mocked object and return the expectedExceptionId that I want? Thanks.
This is the ComponentException.Persist() ...
public void Persist(){ try { OperationsData data = new OperationsData(); this.ExceptionId = data.PersistException(this.Id, this.ExceptionCode, this.ComponentName, this.SeverityIndicator.ToString(), this.ProcessName, this.BusinessExceptionDetail, this.StackTrace); } catch (Exception ex) {...}}[TestMethod()]public void SuccessfulPersistTest(){ /// Arrange long expectedExceptionID = 12345; long ID = 678901; string exceptionCode = string.Empty; string componentName = string.Empty; string severityIndicator = string.Empty; string processName = string.Empty; string businessExceptionDetail = string.Empty; string stackTrace = string.Empty; OperationsData_Accessor operationsData = new OperationsData_Accessor(); operationsData.Arrange(od => od.PersistException(ID, exceptionCode, componentName, severityIndicator, processName, businessExceptionDetail, stackTrace)) .IgnoreInstance() .Returns(expectedExceptionID); ///Action ComponentException_Accessor target = new ComponentException_Accessor(); target.Persist(); ///Assert Assert.AreEqual(expectedExceptionID, target.ExceptionId); operationsData.Assert();}PS. I also tried...
OperationsData_Accessor operationsData = Mock.Create<OperationsData_Accessor>(Constructor.Mocked);