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 void PassWhenCallsMatchExactlyEvenInDifferentOrder()
    {
        _bar.End();
        _foo.Start(2);
        _foo.Finish();
        _bar.Begin();

        this.Invoking(_ =>
        {
            XReceived.Exactly(() =>
            {
                _foo.Start(2);
                _bar.Begin();
                _foo.Finish();
                _bar.End();
            });
        }).Should().ThrowExactly <CallSequenceNotFoundException>()
        .WithMessage(@"
Expected to receive these calls in order:

    XReceivedOnlyInOrderSpecification+IFoo.Start(2)
    XReceivedOnlyInOrderSpecification+IBar.Begin()
    XReceivedOnlyInOrderSpecification+IFoo.Finish()
    XReceivedOnlyInOrderSpecification+IBar.End()

Actually received matching calls in this order:

    XReceivedOnlyInOrderSpecification+IBar.End()
    XReceivedOnlyInOrderSpecification+IFoo.Start(2)
    XReceivedOnlyInOrderSpecification+IFoo.Finish()
    XReceivedOnlyInOrderSpecification+IBar.Begin()

*** Note: calls to property getters are not considered part of the query. ***"); //bug should depend on filter
    }
Ejemplo n.º 3
0
        public void ShouldReportIncorrectNamespaceWhenIsInRootFolderAndItsOnlyNamespaceDoesNotMatchRootNamespace()
        {
            //GIVEN
            var ruleViolationFactory       = Substitute.For <IProjectScopedRuleViolationFactory>();
            var parentProjectAssemblyName  = Any.String();
            var parentProjectRootNamespace = Any.String();
            var pathRelativeToProjectRoot  = Any.Instance <RelativeFilePath>();
            var fileBuilder = new SourceCodeFileBuilder
            {
                RuleViolationFactory       = ruleViolationFactory,
                ParentProjectAssemblyName  = parentProjectAssemblyName,
                PathRelativeToProjectRoot  = pathRelativeToProjectRoot,
                ParentProjectRootNamespace = parentProjectRootNamespace,
                DeclaredNamespaces         = Any.OtherThan(parentProjectRootNamespace).AsList()
            };

            var file = fileBuilder.Build();

            var report      = Substitute.For <IAnalysisReportInProgress>();
            var description = Any.Instance <RuleDescription>();
            var violation   = Any.Instance <RuleViolation>();

            ruleViolationFactory.ProjectScopedRuleViolation(description,
                                                            parentProjectAssemblyName + " has root namespace " +
                                                            parentProjectRootNamespace + " but the file " +
                                                            pathRelativeToProjectRoot + " has incorrect namespace " +
                                                            fileBuilder.DeclaredNamespaces.Single()).Returns(violation);

            //WHEN
            file.CheckNamespacesCorrectness(report, description);

            //THEN
            XReceived.Only(() => report.Add(violation));
        }
Ejemplo n.º 4
0
        public void ShouldReportErrorWhenFileDeclaresNoNamespaces()
        {
            //GIVEN
            var ruleViolationFactory       = Substitute.For <IProjectScopedRuleViolationFactory>();
            var parentProjectAssemblyName  = Any.String();
            var parentProjectRootNamespace = Any.String();
            var pathRelativeToProjectRoot  = Any.Instance <RelativeFilePath>();
            var fileBuilder = new SourceCodeFileBuilder
            {
                RuleViolationFactory       = ruleViolationFactory,
                DeclaredNamespaces         = new List <string>(),
                ParentProjectAssemblyName  = parentProjectAssemblyName,
                ParentProjectRootNamespace = parentProjectRootNamespace,
                PathRelativeToProjectRoot  = pathRelativeToProjectRoot
            };
            var file        = fileBuilder.Build();
            var report      = Substitute.For <IAnalysisReportInProgress>();
            var description = Any.Instance <RuleDescription>();
            var violation   = Any.Instance <RuleViolation>();

            ruleViolationFactory.ProjectScopedRuleViolation(description,
                                                            parentProjectAssemblyName + " has root namespace " +
                                                            parentProjectRootNamespace + " but the file " +
                                                            pathRelativeToProjectRoot + " has no namespace declared").Returns(violation);

            //WHEN
            file.CheckNamespacesCorrectness(report, description);

            //THEN
            XReceived.Only(() => report.Add(violation));
        }
        public void ShouldReportRuleViolationWhenDependingProjectExistsButMatchingDependencyIsNotAfterItInThePath()
        {
            //GIVEN
            var dependencyCondition          = Substitute.For <IDescribedDependencyCondition>();
            var conditionDescription         = Any.Instance <RuleDescription>();
            var dependingAssemblyNamePattern = Any.Pattern();
            var rule = new IndependentRule(
                dependencyCondition,
                dependingAssemblyNamePattern,
                Any.Instance <IDependencyPathRuleViolationFactory>());
            var report = Substitute.For <IAnalysisReportInProgress>();
            var projectDependencyPath = Substitute.For <IProjectDependencyPath>();
            var dependingAssembly     = Substitute.For <IProjectSearchResult>();
            var dependencyAssembly    = Substitute.For <IProjectSearchResult>();

            dependencyCondition.Description().Returns(conditionDescription);

            projectDependencyPath.AssemblyWithNameMatching(dependingAssemblyNamePattern).Returns(dependingAssembly);
            dependingAssembly.Exists().Returns(true);

            projectDependencyPath.AssemblyMatching(dependencyCondition, dependingAssembly).Returns(dependencyAssembly);
            dependencyAssembly.IsNotBefore(dependingAssembly).Returns(false);

            //WHEN
            rule.Check(report, projectDependencyPath);

            //THEN
            XReceived.Only(() =>
            {
                report.FinishedEvaluatingRule(conditionDescription);
            });
        }
    public void FailWhenCheckingASingleCallThatWasNotMade()
    {
        _foo.Start();

        Assert.Throws <CallSequenceNotFoundException>(() =>
                                                      XReceived.Exactly(() => _foo.Finish())
                                                      );
    }
Ejemplo n.º 7
0
            public void Fail_when_checking_a_single_call_that_was_not_made()
            {
                _foo.Start();

                Assert.Throws <CallSequenceNotFoundException>(() =>
                                                              XReceived.Only(() => _foo.Finish())
                                                              );
            }
    public void EventSubscription()
    {
        _foo.OnFoo += () => { };

        XReceived.Exactly(() =>
        {
            _foo.OnFoo += Arg.Any <Action>();
        });
    }
Ejemplo n.º 9
0
 public void DatabaseShouldBeUpdatedWithConnectionFrom(UserDto user2,
                                                       UserDto user1)
 {
     XReceived.Only(() => _connectionInProgress.Success(Arg <UserDto> .That(dto =>
     {
         dto.Should().Be(user2);
         dto.Connections.Should().Contain(user1);
     })));
 }
Ejemplo n.º 10
0
        public void ShouldReportThatUserIsNotFoundWhenAttemptingConnectionWithIt()
        {
            //GIVEN
            var noConnector          = new NoConnector();
            var connectionInProgress = Substitute.For <IConnectionInProgress>();

            //WHEN
            noConnector.AttemptConnectionWith(Any.Exploding <IConnectee>(), connectionInProgress);

            //THEN
            XReceived.Only(() => connectionInProgress.UserNotFound());
        }
    public void IgnoreCallsFromUnrelatedSubstitutes()
    {
        _bar.Begin();
        _foo.FunkyStuff("get funky!");
        _bar.End();

        XReceived.Exactly(() =>
        {
            _bar.Begin();
            _bar.End();
        });
    }
Ejemplo n.º 12
0
            public void Ignore_calls_from_unrelated_substitutes()
            {
                _bar.Begin();
                _foo.FunkyStuff("get funky!");
                _bar.End();

                XReceived.Only(() =>
                {
                    _bar.Begin();
                    _bar.End();
                });
            }
Ejemplo n.º 13
0
            public void Ordered_calls_with_delegates()
            {
                var func = Substitute.For <Func <string> >();

                func();
                func();

                XReceived.Only(() =>
                {
                    func();
                    func();
                });
            }
    public void OrderedCallsWithDelegates()
    {
        var func = Substitute.For <Func <string> >();

        func();
        func();

        XReceived.Exactly(() =>
        {
            func();
            func();
        });
    }
    public void CheckAutoSubbedProps()
    {
        _foo.Start();
        _bar.Baz.Flurgle = "hi";
        _foo.Finish();


        XReceived.Exactly(() =>
        {
            _foo.Start();
            _bar.Baz.Flurgle = "hi";
            _foo.Finish();
        });
    }
Ejemplo n.º 16
0
            public void Check_auto_subbed_props()
            {
                _foo.Start();
                _bar.Baz.Flurgle = "hi";
                _foo.Finish();


                XReceived.Only(() =>
                {
                    _foo.Start();
                    _bar.Baz.Flurgle = "hi";
                    _foo.Finish();
                });
            }
    public void FailWhenOneOfTheCallsWasNotReceived()
    {
        _foo.Start();
        _foo.Finish();

        Assert.Throws <CallSequenceNotFoundException>(() =>
                                                      XReceived.Exactly(() =>
        {
            _foo.Start();
            _foo.FunkyStuff("hi");
            _foo.Finish();
        })
                                                      );
    }
    public void NonMatchingOrderedCallsWithDelegates()
    {
        var func = Substitute.For <Action>();

        func();

        Assert.Throws <CallSequenceNotFoundException>(() =>
                                                      XReceived.Exactly(() =>
        {
            func();
            func();
        })
                                                      );
    }
Ejemplo n.º 19
0
            public void Non_matching_ordered_calls_with_delegates()
            {
                var func = Substitute.For <Action>();

                func();

                Assert.Throws <CallSequenceNotFoundException>(() =>
                                                              XReceived.Only(() =>
                {
                    func();
                    func();
                })
                                                              );
            }
Ejemplo n.º 20
0
            public void Fail_when_one_of_the_calls_was_not_received()
            {
                _foo.Start();
                _foo.Finish();

                Assert.Throws <CallSequenceNotFoundException>(() =>
                                                              XReceived.Only(() =>
                {
                    _foo.Start();
                    _foo.FunkyStuff("hi");
                    _foo.Finish();
                })
                                                              );
            }
    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. ***

");
    }
Ejemplo n.º 22
0
        public void ShouldTranslateShootingCommandToShootingReport()
        {
            //GIVEN
            var executionEngine = Substitute.For <IExecutionEngine>();
            var interpreter     = new CommandInterpreter(executionEngine);

            //WHEN
            interpreter.OnEvent(CommandInterpreter.Shooting);

            //THEN
            XReceived.Only(() =>
            {
                executionEngine.ShootingStarted();
            });
        }
Ejemplo n.º 23
0
        public void ShouldTranslateIncidentCommandToIncidentReport()
        {
            //GIVEN
            var executionEngine = Substitute.For <IExecutionEngine>();
            var interpreter     = new CommandInterpreter(executionEngine);

            //WHEN
            interpreter.OnEvent(CommandInterpreter.Incident);

            //THEN
            XReceived.Only(() =>
            {
                executionEngine.IncidentDiscovered();
            });
        }
    public void UseArgMatcher()
    {
        _foo.Start(1);
        _bar.Begin();
        _foo.Finish();
        _bar.End();

        XReceived.Exactly(() =>
        {
            _foo.Start(Arg.Is <int>(x => x < 10));
            _bar.Begin();
            _foo.Finish();
            _bar.End();
        });
    }
Ejemplo n.º 25
0
            public void Pass_when_calls_match_exactly_even_in_different_order()
            {
                _bar.End();
                _foo.Start(2);
                _foo.Finish();
                _bar.Begin();

                XReceived.Only(() =>
                {
                    _foo.Start(2);
                    _bar.Begin();
                    _foo.Finish();
                    _bar.End();
                });
            }
    public void PassWhenCallsMatchExactlyEvenInDifferentOrder()
    {
        _bar.End();
        _foo.Start(2);
        _foo.Finish();
        _bar.Begin();

        XReceived.Only(() =>
        {
            _foo.Start(2);
            _bar.Begin();
            _foo.Finish();
            _bar.End();
        });
    }
Ejemplo n.º 27
0
        public void ShouldTranslateRobberyCommandToRobberyReport()
        {
            //GIVEN
            var executionEngine = Substitute.For <IExecutionEngine>();
            var interpreter     = new CommandInterpreter(executionEngine);

            //WHEN
            interpreter.OnEvent(CommandInterpreter.Robbery);

            //THEN
            XReceived.Only(() =>
            {
                executionEngine.RobberyTookPlace();
            });
        }
Ejemplo n.º 28
0
            public void Verifying_calls_should_ignore_property_getter_calls()
            {
                var baz = _bar.Baz;

                baz.Wurgle();
                baz.Slurgle();

                XReceived.Only(() =>
                {
                    // This call spec should be regarded as matching the
                    // calling code above. So needs to ignore the get
                    // request to _bar.Baz.
                    _bar.Baz.Wurgle();
                    _bar.Baz.Slurgle();
                });
            }
    public void FailWhenAutoSubbedPropCallNotReceived()
    {
        _foo.Start();
        _bar.Baz.Flurgle = "hi";
        _foo.Finish();


        Assert.Throws <CallSequenceNotFoundException>(() =>
                                                      XReceived.Exactly(() =>
        {
            _foo.Start();
            _bar.Baz.Flurgle = "howdy";
            _foo.Finish();
        })
                                                      );
    }
    public void VerifyingCallsShouldIgnorePropertyGetterCalls()
    {
        var baz = _bar.Baz;

        baz.Wurgle();
        baz.Slurgle();

        XReceived.Exactly(() =>
        {
            // This call spec should be regarded as matching the
            // calling code above. So needs to ignore the get
            // request to _bar.Baz.
            _bar.Baz.Wurgle();
            _bar.Baz.Slurgle();
        });
    }