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)); }
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 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 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.Only(async() => { substitute1.DoSomething(); substitute2.DoSomething(); await substitute1.DoSomethingAsyncWithoutResult(); await substitute2.DoSomethingAsyncWithoutResult(); }, Allowing.Queries()); }).Should().NotThrow(); }
public void Fail_when_checking_a_single_call_that_was_not_made() { _foo.Start(); Assert.Throws <CallSequenceNotFoundException>(() => XReceived.Only(() => _foo.Finish()) ); }
public void FailWhenCheckingASingleCallThatWasNotMade() { _foo.Start(); Assert.Throws <CallSequenceNotFoundException>(() => XReceived.Only(() => _foo.Finish()) ); }
public void Event_subscription() { _foo.OnFoo += () => { }; XReceived.Only(() => { _foo.OnFoo += Arg.Any <Action>(); }); }
public void DatabaseShouldBeUpdatedWithConnectionFrom(UserDto user2, UserDto user1) { XReceived.Only(() => _connectionInProgress.Success(Arg <UserDto> .That(dto => { dto.Should().Be(user2); dto.Connections.Should().Contain(user1); }))); }
public void Ignore_calls_from_unrelated_substitutes() { _bar.Begin(); _foo.FunkyStuff("get funky!"); _bar.End(); XReceived.Only(() => { _bar.Begin(); _bar.End(); }); }
public void IgnoreCallsFromUnrelatedSubstitutes() { _bar.Begin(); _foo.FunkyStuff("get funky!"); _bar.End(); XReceived.Only(() => { _bar.Begin(); _bar.End(); }); }
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 OrderedCallsWithDelegates() { var func = Substitute.For <Func <string> >(); func(); func(); XReceived.Only(() => { func(); func(); }); }
public void NonMatchingOrderedCallsWithDelegates() { var func = Substitute.For <Action>(); func(); Assert.Throws <CallSequenceNotFoundException>(() => XReceived.Only(() => { func(); func(); }) ); }
public void FailWhenOneOfTheCallsWasNotReceived() { _foo.Start(); _foo.Finish(); Assert.Throws <CallSequenceNotFoundException>(() => XReceived.Only(() => { _foo.Start(); _foo.FunkyStuff("hi"); _foo.Finish(); }) ); }
public void CheckAutoSubbedProps() { _foo.Start(); _bar.Baz.Flurgle = "hi"; _foo.Finish(); XReceived.Only(() => { _foo.Start(); _bar.Baz.Flurgle = "hi"; _foo.Finish(); }); }
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 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 ShouldTranslateIncidentCommandToIncidentReport() { //GIVEN var executionEngine = Substitute.For <IExecutionEngine>(); var interpreter = new CommandInterpreter(executionEngine); //WHEN interpreter.OnEvent(CommandInterpreter.Incident); //THEN XReceived.Only(() => { executionEngine.IncidentDiscovered(); }); }
public void ShouldTranslateRobberyCommandToRobberyReport() { //GIVEN var executionEngine = Substitute.For <IExecutionEngine>(); var interpreter = new CommandInterpreter(executionEngine); //WHEN interpreter.OnEvent(CommandInterpreter.Robbery); //THEN XReceived.Only(() => { executionEngine.RobberyTookPlace(); }); }
public void ShouldTranslateShootingCommandToShootingReport() { //GIVEN var executionEngine = Substitute.For <IExecutionEngine>(); var interpreter = new CommandInterpreter(executionEngine); //WHEN interpreter.OnEvent(CommandInterpreter.Shooting); //THEN XReceived.Only(() => { executionEngine.ShootingStarted(); }); }
public void UseArgMatcher() { _foo.Start(1); _bar.Begin(); _foo.Finish(); _bar.End(); XReceived.Only(() => { _foo.Start(Arg.Is <int>(x => x < 10)); _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(); }); }
public void FailWhenAutoSubbedPropCallNotReceived() { _foo.Start(); _bar.Baz.Flurgle = "hi"; _foo.Finish(); Assert.Throws <CallSequenceNotFoundException>(() => XReceived.Only(() => { _foo.Start(); _bar.Baz.Flurgle = "howdy"; _foo.Finish(); }) ); }
public void VerifyingCallsShouldIgnorePropertyGetterCalls() { 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 Fail_when_auto_subbed_prop_call_not_received() { _foo.Start(); _bar.Baz.Flurgle = "hi"; _foo.Finish(); Assert.Throws <CallSequenceNotFoundException>(() => XReceived.Only(() => { _foo.Start(); _bar.Baz.Flurgle = "howdy"; _foo.Finish(); }) ); }
public void Fail_when_call_arg_does_not_match() { _foo.Start(1); _bar.Begin(); _foo.Finish(); _bar.End(); Assert.Throws <CallSequenceNotFoundException>(() => XReceived.Only(() => { _foo.Start(2); _bar.Begin(); _foo.Finish(); _bar.End(); }) ); }
public void FailWhenCallArgDoesNotMatch() { _foo.Start(1); _bar.Begin(); _foo.Finish(); _bar.End(); Assert.Throws <CallSequenceNotFoundException>(() => XReceived.Only(() => { _foo.Start(2); _bar.Begin(); _foo.Finish(); _bar.End(); }) ); }
public void ShouldReportInvalidOtherUserIdWhenInvalidConnecteeIdExceptionIsThrownFromLookup() { //GIVEN var connectionInProgress = Substitute.For <IConnectionInProgress>(); var user1Id = Any.String(); var user2Id = Any.String(); var lookup = Substitute.For <IUserLookup>(); var destination = Substitute.For <IConnectorDestination>(); var command = new ConnectionUseCase(connectionInProgress, user1Id, user2Id, lookup, destination); lookup.LookupConnector(user1Id).Throws(Any.Instance <InvalidConnecteeIdException>()); //WHEN command.Execute(); //THEN XReceived.Only(() => connectionInProgress.Received(1).InvalidOtherUserId()); }
public void ShouldReportOkWhenPathDoesNotContainADependingProject() { //GIVEN var dependencyCondition = Substitute.For <IDescribedDependencyCondition>(); var dependingAssemblyNamePattern = Any.Pattern(); var rule = new IndependentRule(dependencyCondition, dependingAssemblyNamePattern, Any.Instance <IDependencyPathRuleViolationFactory>()); var report = Substitute.For <IAnalysisReportInProgress>(); var projectDependencyPath = Substitute.For <IProjectDependencyPath>(); projectDependencyPath.AssemblyWithNameMatching(dependingAssemblyNamePattern).Exists().Returns(false); //WHEN rule.Check(report, projectDependencyPath); //THEN XReceived.Only(() => report.FinishedEvaluatingRule(dependencyCondition.Description())); }
public void FailWhenAdditionalRelatedCallsAtEnd() { _foo.Start(); _bar.Begin(); _foo.Finish(); _bar.End(); _foo.Start(); Assert.Throws <CallSequenceNotFoundException>(() => XReceived.Only(() => { _foo.Start(); _bar.Begin(); _foo.Finish(); _bar.End(); }) ); }