public async Task ShouldNotCheckQueriesWhenTheyAreAllowed() //bug this should not pass!!! { var substitute1 = Substitute.For <IHaveCommandAndQueryAndTasks>(); var substitute2 = Substitute.For <IHaveCommandAndQueryAndTasks>(); substitute1.DoSomething(); await substitute1.DoSomethingAsyncWithoutResult(); var result1 = substitute1.QuerySomething(); var result2 = await substitute1.QuerySomethingAsync(); substitute2.DoSomething(); await substitute2.DoSomethingAsyncWithoutResult(); await substitute2.DoSomethingAsyncWithResult(); var result3 = substitute2.QuerySomething(); var result4 = await substitute2.QuerySomethingAsync(); new Action(() => { XReceived.Exactly(async() => { substitute1.DoSomething(); await substitute1.DoSomethingAsyncWithoutResult(); substitute2.DoSomething(); await substitute2.DoSomethingAsyncWithoutResult(); }, Allowing.Queries()); }).Should().NotThrow(); }
public async Task ShouldNotCheckQueriesWhenTheyAreAllowed2() { var substitute1 = Substitute.For <IHaveCommandAndQueryAndTasks>(); var substitute2 = Substitute.For <IHaveCommandAndQueryAndTasks>(); await substitute1.DoSomethingAsyncWithoutResult(); await substitute1.DoSomethingAsyncWithResult(); substitute1.DoSomething(); await substitute2.DoSomethingAsyncWithoutResult(); substitute2.DoSomething(); new Action(() => { XReceived.Exactly(() => { substitute1.DoSomething(); substitute2.DoSomething(); substitute1.DoSomethingAsyncWithoutResult(); }, Allowing.Queries()); }).Should().ThrowExactly <CallSequenceNotFoundException>( because: "verification of substitute2.DoSomethingAsyncWithoutResult() is missing") .WithMessage(@" Expected to receive only these calls: 1@XReceivedOnlyInOrderSpecification+IHaveCommandAndQueryAndTasks.DoSomething() 2@XReceivedOnlyInOrderSpecification+IHaveCommandAndQueryAndTasks.DoSomething() 1@XReceivedOnlyInOrderSpecification+IHaveCommandAndQueryAndTasks.DoSomethingAsyncWithoutResult() Actually received the following calls: 1@XReceivedOnlyInOrderSpecification+IHaveCommandAndQueryAndTasks.DoSomethingAsyncWithoutResult() 1@XReceivedOnlyInOrderSpecification+IHaveCommandAndQueryAndTasks.DoSomething() 2@XReceivedOnlyInOrderSpecification+IHaveCommandAndQueryAndTasks.DoSomethingAsyncWithoutResult() 2@XReceivedOnlyInOrderSpecification+IHaveCommandAndQueryAndTasks.DoSomething() Calls expected but not received: Calls received but not expected: DoSomethingAsyncWithoutResult() *** Note: calls to property getters and property getters and queries (methods returning something different than void and Task) are not considered part of the query. *** "); }
public async Task ShouldNotCheckQueriesWhenTheyAreAllowed2() { var substitute1 = Substitute.For <IHaveCommandAndQueryAndTasks>(); var substitute2 = Substitute.For <IHaveCommandAndQueryAndTasks>(); await substitute1.DoSomethingAsyncWithoutResult(); await substitute1.DoSomethingAsyncWithResult(); substitute1.DoSomething(); await substitute2.DoSomethingAsyncWithoutResult(); substitute2.DoSomething(); new Action(() => { XReceived.Only(() => { substitute1.DoSomething(); substitute2.DoSomething(); substitute1.DoSomethingAsyncWithoutResult(); }, Allowing.Queries()); }).Should().Throw <Exception>(because: "verification of substitute2.DoSomethingAsyncWithoutResult() is missing"); }
private static IQueryFilter DefualtFilterPlus(IQueryFilter methodFilter) { return(Allowing.AllOf(Allowing.PropertyGetters(), methodFilter)); }