コード例 #1
0
        public void InvokeInCorrectBranch()
        {
            // Arrange
            var builder = NewApplicationBuilder();
            var tracker = new ComponentsInvokeTracker();

            // Act
            builder.Use(tracker.Component_A);
            builder.UseWhen(tracker.Condition("Branch_1", true), branchOneApp =>
            {
                branchOneApp.Use(tracker.Component_B);
                branchOneApp.UseWhen(tracker.Condition("Branch_2", false), branchTwoApp =>
                {
                    branchTwoApp.Use(tracker.Component_C);
                });
                branchOneApp.Use(tracker.Component_Terminator);
            });
            builder.Run(tracker.Component_Run);
            builder.Use(tracker.Component_C);
            var app = builder.Build();

            app(null).GetAwaiter().GetResult();

            // Assert
            Assert.Equal(new[] { "A", "Branch_1", "B", "Branch_2", "Terminator" }, tracker.Invoked);
        }
コード例 #2
0
        public void ThrowWithoutTerminator()
        {
            // Arrange
            var builder = NewApplicationBuilder();
            var tracker = new ComponentsInvokeTracker();

            // Act
            builder.Use(tracker.Component_A);
            builder.Use(tracker.Component_B);
            var app = builder.Build();

            // Assert
            Assert.Throws <InvalidOperationException>(() => app(null).GetAwaiter().GetResult());
        }
コード例 #3
0
        public void InvokeInOrder()
        {
            // Arrange
            var builder = NewApplicationBuilder();
            var tracker = new ComponentsInvokeTracker();

            // Act
            builder.Use(tracker.Component_A);
            builder.Use(tracker.Component_B);
            builder.Use(tracker.Component_Terminator);
            var app = builder.Build();

            app(null).GetAwaiter().GetResult();

            // Assert
            Assert.Equal(new[] { "A", "B", "Terminator" }, tracker.Invoked);
        }