public void ExecuteGiven_ShouldCallDisposeOnActionResult(IDisposable disposable, IActor actor, UsingAction <object> sut) { // arrange Mock.Get(actor).Setup(a => a.Execute(sut.DisposableAction)).Returns(disposable); // act sut.ExecuteGivenAs(actor); // assert Mock.Get(disposable).Verify(d => d.Dispose()); }
public void ExecuteGiven_ReturnCorrectValue(object expected, IActor actor, UsingAction <object> sut) { // arrange Mock.Get(actor).Setup(a => a.Execute(sut.ActionToExecute)).Returns(expected); // act var actual = sut.ExecuteGivenAs(actor); // assert actual.Should().Be(expected); }
public void ExecuteGiven_WhenActionToExecuteThrows_ShouldCallDisposeOnActionResult( IDisposable disposable, IActor actor, UsingAction <object> sut) { // arrange Mock.Get(actor).Setup(a => a.Execute(sut.DisposableAction)).Returns(disposable); Mock.Get(actor).Setup(a => a.Execute(sut.ActionToExecute)).Throws(new Exception()); // act try { sut.ExecuteGivenAs(actor); } catch (Exception) { } // assert Mock.Get(disposable).Verify(d => d.Dispose()); }
public void ExecuteGiven_ShouldCreateDisposableBeforeExecutingAction(IDisposable disposable, IActor actor, UsingAction <object> sut) { // arrange var callOrder = new List <string>(); var mockActor = Mock.Get(actor); mockActor.Setup(a => a.Execute(sut.DisposableAction)).Returns(() => { callOrder.Add("createDisposable"); return(disposable); }); mockActor.Setup(a => a.Execute(sut.ActionToExecute)).Callback(() => callOrder.Add("executeAction")); ; // act sut.ExecuteGivenAs(actor); // assert var expected = new[] { "createDisposable", "executeAction" }; callOrder.Should().BeEquivalentTo(expected, o => o.WithStrictOrdering()); }