public void ExecuteLogsFailMessage() { var buildInfo = this.mocks.StrictMock <BuildProgressInformation>(string.Empty, string.Empty); var result = this.mocks.StrictMock <IIntegrationResult>(); var logger = this.mocks.StrictMock <ILogger>(); SetupResult.For(result.Status).PropertyBehavior(); SetupResult.For(result.BuildProgressInformation).Return(buildInfo); Expect.Call(() => buildInfo.SignalStartRunTask("Adding a comment to the log")); Expect.Call(() => logger.Debug("Logging error message: Test Message")); GeneralTaskResult loggedResult = null; Expect.Call(() => result.AddTaskResult( Arg <GeneralTaskResult> .Matches <GeneralTaskResult>(arg => { loggedResult = arg; return(true); }))); var task = new CommentTask { FailTask = true, Message = "Test Message", Logger = logger }; result.Status = IntegrationStatus.Unknown; this.mocks.ReplayAll(); task.Run(result); this.mocks.VerifyAll(); Assert.IsNotNull(loggedResult); Assert.IsFalse(loggedResult.CheckIfSuccess()); Assert.AreEqual("Test Message", loggedResult.Data); }
public void ExecuteLogsFailMessage() { var buildInfo = this.mocks.Create <BuildProgressInformation>(MockBehavior.Strict, string.Empty, string.Empty).Object; var result = this.mocks.Create <IIntegrationResult>(MockBehavior.Strict).Object; var logger = this.mocks.Create <ILogger>(MockBehavior.Strict).Object; Mock.Get(result).SetupProperty(_result => _result.Status); Mock.Get(result).SetupGet(_result => _result.BuildProgressInformation).Returns(buildInfo); Mock.Get(buildInfo).Setup(_buildInfo => _buildInfo.SignalStartRunTask("Adding a comment to the log")).Verifiable(); Mock.Get(logger).Setup(_logger => _logger.Debug("Logging error message: Test Message")).Verifiable(); GeneralTaskResult loggedResult = null; Mock.Get(result).Setup(_result => _result.AddTaskResult(It.IsAny <GeneralTaskResult>())) .Callback <ITaskResult>(arg => loggedResult = (GeneralTaskResult)arg).Verifiable(); var task = new CommentTask { FailTask = true, Message = "Test Message", Logger = logger }; result.Status = IntegrationStatus.Unknown; task.Run(result); this.mocks.VerifyAll(); Assert.IsNotNull(loggedResult); Assert.IsFalse(loggedResult.CheckIfSuccess()); Assert.AreEqual("Test Message", loggedResult.Data); }