public void SampleProvider_ExecuteWithParam_Succeeds( ISampleService sampleService, string value, string returnValue) { A.CallTo(() => sampleService.CanExecute) .Returns(true); A.CallTo(() => sampleService.ExecuteWithParam(value)) .Returns(returnValue); var sampleProvider = new SampleProvider(sampleService); var actual = sampleProvider.ExecuteSampleWithParam(value); A.CallTo(() => sampleService.ExecuteWithParam(A <string> .Ignored)) .MustHaveHappened(Repeated.Exactly.Once); Assert.Equal(returnValue, actual); }
public string ExecuteSampleWithParam(string value) { if (_sampleService.CanExecute) { return(_sampleService.ExecuteWithParam(value)); } return(string.Empty); }
public void SampleProvider_ExecuteWithParams_CanExecute_Succeeds( bool canExecute, string returnValue, ISampleService sampleService, string value) { // Arrange A.CallTo(() => sampleService.CanExecute) .Returns(canExecute); A.CallTo(() => sampleService.ExecuteWithParam(value)) .Returns(returnValue); var sampleProvider = new SampleProvider(sampleService); // Act var actual = sampleProvider.ExecuteSampleWithParam(value); // Assert A.CallTo(() => sampleService.ExecuteWithParam(A <string> .Ignored)) .MustHaveHappenedANumberOfTimesMatching(n => n == (canExecute ? 1 : 0)); Assert.Equal(returnValue, actual); }
public void SampleProvider_ExecuteWithParams_CanExecute_Succeeds( bool canExecute, string returnValue, ISampleService sampleService, string value) { // Arrange A.CallTo(() => sampleService.CanExecute) .Returns(canExecute); A.CallTo(() => sampleService.ExecuteWithParam(value)) .Returns(returnValue); var sampleProvider = new SampleProvider(sampleService); // Act var actual = sampleProvider.ExecuteSampleWithParam(value); // Assert A.CallTo(() => sampleService.ExecuteWithParam(A <string> .Ignored)) .MustHaveHappened( canExecute ? Repeated.Exactly.Once : Repeated.Never); Assert.Equal(returnValue, actual); }