public void Using_ShouldReturnCorrectValue(IAction <IDisposable> disposableAction, IAction <object> action) { // act var actual = ActionExtensions.Using(action, disposableAction); // assert var expected = new UsingAction <object>(disposableAction, action); actual.Should().BeEquivalentTo(expected); }
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_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 Name_ShouldReturnCorrectValue(string actionName, string disposableActionName, UsingAction <object> sut) { // arrange Mock.Get(sut.ActionToExecute).Setup(a => a.Name).Returns(actionName); Mock.Get(sut.DisposableAction).Setup(a => a.Name).Returns(disposableActionName); // act var actual = sut.Name; // assert var expected = $"Using {disposableActionName} with {actionName}"; actual.Should().Be(expected); }
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()); }