public void ThrowsForQueryWithThrowSetupMatchingPredicate() { // Arrange var queryProcessor = new FakeQueryProcessor(); queryProcessor.SetupExceptionFor <TestQueryB>(q => q.Number == 1337, new AbandonedMutexException()); // Act + Assert Assert.Throws <AbandonedMutexException>(() => queryProcessor.Execute(new TestQueryB(1337))); }
public void ReturnsValueThatWasSetUpForQueryWithPredicate() { // Arrange var queryProcessor = new FakeQueryProcessor(); queryProcessor.SetupResultFor <TestQueryB>(q => q.Number == 1337, 1234); // Act var result = queryProcessor.Execute(new TestQueryB(1337)); // Assert result.ShouldBe(1234); }
public void ReturnsDefaultValueOfQueriesWithoutSetup() { // Arrange var queryProcessor = new FakeQueryProcessor(); queryProcessor.SetupResultFor <TestQueryB>(1234); // Act var result = queryProcessor.Execute(new TestQueryA(Guid.NewGuid())); // Assert result.ShouldBe(default(Guid)); }
public void DoesNotThrowIfQueryDoesntMatchPredicate() { // Arrange var queryProcessor = new FakeQueryProcessor(); queryProcessor.SetupExceptionFor <TestQueryB>(q => q.Number == 1337, new AbandonedMutexException()); // Act var result = queryProcessor.Execute(new TestQueryB(9999)); // Assert result.ShouldBe(default(int)); }
public void ReturnsDefaultValueIfQueryDoesntMatchPredicate() { // Arrange var queryProcessor = new FakeQueryProcessor(); queryProcessor.SetupResultFor <TestQueryB>(q => q.Number == 1337, 1234); // Act var result = queryProcessor.Execute(new TestQueryB(9999)); // Assert result.ShouldBe(default(int)); }
public void ReturnsExecutedQueries() { // Arrange var guid = Guid.NewGuid(); var queryProcessor = new FakeQueryProcessor(); // Act queryProcessor.Execute(new TestQueryA(guid)); queryProcessor.Execute(new TestQueryB(100)); queryProcessor.Execute(new TestQueryB(200)); queryProcessor.Execute(new TestQueryB(300)); // Assert queryProcessor.GetExecutedQueries().Count().ShouldBe(4); queryProcessor.GetExecutedQueries <TestQueryA>().Count().ShouldBe(1); queryProcessor.GetExecutedQueries <TestQueryB>().Count().ShouldBe(3); queryProcessor.GetExecutedQueries <TestQueryC>().Count().ShouldBe(0); queryProcessor.GetExecutedQueries <TestQueryA>().Single().Id.ShouldBe(guid); queryProcessor.GetExecutedQueries <TestQueryB>().ElementAt(0).Number.ShouldBe(100); queryProcessor.GetExecutedQueries <TestQueryB>().ElementAt(1).Number.ShouldBe(200); queryProcessor.GetExecutedQueries <TestQueryB>().ElementAt(2).Number.ShouldBe(300); }