コード例 #1
0
        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)));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        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);
        }