public void Handlers_Can_Be_Unsubscribed() { var pub = new Publisher(); var calledSubscribers = new List<int>(); var sub1 = new InstanceSubscriber(1, pub, calledSubscribers.Add); var sub2 = new InstanceSubscriber(2, pub, calledSubscribers.Add); StaticSubscriber.FooWasRaised = false; StaticSubscriber.Subscribe(pub); // Make sure they really were subscribed pub.Raise(); calledSubscribers.Should().Equal(1, 2); StaticSubscriber.FooWasRaised.Should().BeTrue(); calledSubscribers.Clear(); sub1.Unsubscribe(pub); pub.Raise(); calledSubscribers.Should().Equal(2); StaticSubscriber.FooWasRaised = false; StaticSubscriber.Unsubscribe(pub); pub.Raise(); StaticSubscriber.FooWasRaised.Should().BeFalse(); calledSubscribers.Clear(); sub2.Unsubscribe(pub); pub.Raise(); calledSubscribers.Should().BeEmpty(); // Make sure subscribers are not collected before the end of the test GC.KeepAlive(sub1); GC.KeepAlive(sub2); }
public void Should_fluent_assertions() { object obj = null; obj.Should().Be.Null(); obj = new object(); obj.Should().Be.OfType(typeof(object)); obj.Should().Equal(obj); obj.Should().Not.Be.Null(); obj.Should().Not.Be.SameAs(new object()); obj.Should().Not.Be.OfType<string>(); obj.Should().Not.Equal("foo"); obj = "x"; obj.Should().Not.Be.InRange("y", "z"); obj.Should().Be.InRange("a", "z"); obj.Should().Be.SameAs("x"); "This String".Should().Contain("This"); "This String".Should().Not.Be.Empty(); "This String".Should().Not.Contain("foobar"); false.Should().Be.False(); true.Should().Be.True(); var list = new List<object>(); list.Should().Count.Zero(); list.Should().Not.Contain.Item(new object()); var item = new object(); list.Add(item); list.Should().Not.Be.Empty(); list.Should().Contain.Item(item); }
public async Task InstallPackageTest() { await Workflow.RSession.EnsureHostStartedAsync(new RHostStartupInfo {Name = nameof(InstallPackageTest)}, null, 50000); var completionSets = new List<CompletionSet>(); for (int i = 0; i < 2; i++) { try { await Workflow.Packages.UninstallPackageAsync("abc", null); //await Workflow.RSession.ExecuteAsync("remove.packages('abc')", REvaluationKind.Mutating); } catch (RException) { } await PackageIndex.BuildIndexAsync(); completionSets.Clear(); RCompletionTestUtilities.GetCompletions(EditorShell, "abc::", 5, completionSets); completionSets.Should().ContainSingle(); // Try again one more time if (completionSets[0].Completions.Count == 0) { break; } } completionSets[0].Completions.Should().BeEmpty(); try { await Workflow.RSession.ExecuteAsync("install.packages('abc')", REvaluationKind.Mutating); } catch (RException) { } await PackageIndex.BuildIndexAsync(); completionSets.Clear(); RCompletionTestUtilities.GetCompletions(EditorShell, "abc::", 5, completionSets); completionSets.Should().ContainSingle(); completionSets[0].Completions.Should().NotBeEmpty(); }
public void Given_Action_And_Strings_When_Calling_Each_Then_Action_Is_Invoked_For_Each_Element() { IEnumerable<int> items = new List<int> { 1, 2, 3 }; var visited = new List<int>(); Action<int> action = visited.Add; items.Each(action); visited.Should().ContainInOrder(items); visited.Should().HaveCount(items.Count()); }
public void InstallTelemetry() { var telemetryEvents = new List<string>(); var telemetry = Substitute.For<ITelemetryService>(); telemetry.When(x => x.ReportEvent(Arg.Any<TelemetryArea>(), Arg.Any<string>(), Arg.Any<object>())) .Do(x => telemetryEvents.Add(x.Args()[1] as string)); var coreShell = Substitute.For<ICoreShell>(); var services = Substitute.For<ICoreServices>(); services.Telemetry.Returns(telemetry); var ps = Substitute.For<IProcessServices>(); ps.When(x => x.Start(Arg.Any<string>())).Do(c => { c.Args()[0].Should().NotBeNull(); }); services.ProcessServices.Returns(ps); coreShell.Services.Returns(services); coreShell.ShowMessage(Arg.Any<string>(), Arg.Any<MessageButtons>()).Returns(MessageButtons.Yes); var downloader = Substitute.For<IFileDownloader>(); downloader.Download(null, null, CancellationToken.None).ReturnsForAnyArgs((string)null); var inst = new MicrosoftRClientInstaller(); inst.LaunchRClientSetup(coreShell, downloader); telemetryEvents.Should().HaveCount(1); telemetryEvents[0].Should().Be(RtvsTelemetry.ConfigurationEvents.RClientInstallYes); downloader.Download(null, null, CancellationToken.None).ReturnsForAnyArgs("Failed"); telemetryEvents.Clear(); inst.LaunchRClientSetup(coreShell, downloader); telemetryEvents.Should().HaveCount(2); telemetryEvents[0].Should().Be(RtvsTelemetry.ConfigurationEvents.RClientInstallYes); telemetryEvents[1].Should().Be(RtvsTelemetry.ConfigurationEvents.RClientDownloadFailed); downloader.Download(null, null, CancellationToken.None).ReturnsForAnyArgs((string)null); ps = Substitute.For<IProcessServices>(); ps.When(x => x.Start(Arg.Any<string>())).Do(c => { throw new Win32Exception((unchecked((int)0x800704C7))); }); services.ProcessServices.Returns(ps); telemetryEvents.Clear(); inst.LaunchRClientSetup(coreShell, downloader); telemetryEvents.Should().HaveCount(2); telemetryEvents[0].Should().Be(RtvsTelemetry.ConfigurationEvents.RClientInstallYes); telemetryEvents[1].Should().Be(RtvsTelemetry.ConfigurationEvents.RClientInstallCancel); }
public void ReshufflesDiscards() { var cards = new List<int>(); for (int i = 0; i < 95; i++) { var card = _deck.DrawCard(); if (card%9 == 0) { cards.Add(card); _deck.DiscardCard(card); } } var shuffledDiscards = new List<int>(); for (int i = 0; i < cards.Count + 4; i++) { if (i > 3) { var card = _deck.DrawCard(); card.Satisfy(x => x%9 == 0); shuffledDiscards.Add(card); } else _deck.DrawCard(); } cards.Should().Not.Have.SameSequenceAs(shuffledDiscards); }
public void FunctionDefinition01() { var completionSets = new List<CompletionSet>(); RCompletionTestUtilities.GetCompletions(_editorShell, "x <- function()", 14, completionSets); completionSets.Should().ContainSingle() .Which.Completions.Should().BeEmpty(); }
public void BeforeComment() { var completionSets = new List<CompletionSet>(); RCompletionTestUtilities.GetCompletions(_editorShell, "#No", 0, completionSets); completionSets.Should().ContainSingle() .Which.Completions.Should().NotBeEmpty(); }
public void It_iterates_through_all_added_resolvers_in_order_when_they_return_null() { var compositeCommandResolver = new CompositeCommandResolver(); var resolverCalls = new List<int>(); var mockResolver1 = new Mock<ICommandResolver>(); mockResolver1.Setup(r => r .Resolve(It.IsAny<CommandResolverArguments>())) .Returns(default(CommandSpec)) .Callback(() => resolverCalls.Add(1)); var mockResolver2 = new Mock<ICommandResolver>(); mockResolver2.Setup(r => r .Resolve(It.IsAny<CommandResolverArguments>())) .Returns(default(CommandSpec)) .Callback(() => resolverCalls.Add(2)); compositeCommandResolver.AddCommandResolver(mockResolver1.Object); compositeCommandResolver.AddCommandResolver(mockResolver2.Object); compositeCommandResolver.Resolve(default(CommandResolverArguments)); resolverCalls.Should() .HaveCount(2) .And .ContainInOrder(new [] {1, 2}); }
public void ResponsePropertyCollectionsShouldBeReadOnly() { var exceptions = new HashSet<PropertyInfo> { typeof(ITypeMapping).GetProperty(nameof(ITypeMapping.DynamicDateFormats)), typeof(ITypeMapping).GetProperty(nameof(ITypeMapping.Meta)), typeof(TypeMapping).GetProperty(nameof(TypeMapping.DynamicDateFormats)), typeof(TypeMapping).GetProperty(nameof(TypeMapping.Meta)), #pragma warning disable 618 typeof(IMultiPercolateResponse).GetProperty(nameof(IMultiPercolateResponse.Responses)), #pragma warning restore 618 typeof(IBulkResponse).GetProperty(nameof(IBulkResponse.ItemsWithErrors)), typeof(IMultiSearchResponse).GetProperty(nameof(IMultiSearchResponse.AllResponses)), }; var responseInterfaceTypes = from t in typeof(IResponse).Assembly().Types() where t.IsInterface() && typeof(IResponse).IsAssignableFrom(t) select t; var ruleBreakers = new List<string>(); var seenTypes = new HashSet<Type>(); foreach (var responseType in responseInterfaceTypes) { FindPropertiesBreakingRule(responseType, exceptions, seenTypes, ruleBreakers); } ruleBreakers.Should().BeEmpty(); }
public void JsonReader_should_support_reading_multiple_documents( [Range(0, 3)] int numberOfDocuments) { var document = new BsonDocument("x", 1); var json = document.ToJson(); var input = Enumerable.Repeat(json, numberOfDocuments).Aggregate("", (a, j) => a + j); var expectedResult = Enumerable.Repeat(document, numberOfDocuments); using (var jsonReader = new JsonReader(input)) { var result = new List<BsonDocument>(); while (!jsonReader.IsAtEndOfFile()) { jsonReader.ReadStartDocument(); var name = jsonReader.ReadName(); var value = jsonReader.ReadInt32(); jsonReader.ReadEndDocument(); var resultDocument = new BsonDocument(name, value); result.Add(resultDocument); } result.Should().Equal(expectedResult); } }
public void NewValidationRulesShouldBeInTheRuleSetExceptBaselinedExceptionRules() { var validationRules = new Dictionary<object, string>(); var items = typeof(ValidationRules).GetFields().Select(f=> new KeyValuePair<object, string>(f.GetValue(null), f.Name)); foreach (var item in items) { validationRules.Add(item.Key, item.Value); } var unFoundValidationRules = new List<object>(); foreach(var ruleSet in ValidationRuleSet.GetEdmModelRuleSet(new Version(4, 0))) { if (validationRules.ContainsKey(ruleSet)) { validationRules.Remove(ruleSet); } else { unFoundValidationRules.Add(validationRules); } } unFoundValidationRules.Should().HaveCount(0); // The 4 remaining rules are deprecated: // ComplexTypeMustContainProperties // OnlyEntityTypesCanBeOpen // ComplexTypeInvalidPolymorphicComplexType // ComplexTypeInvalidAbstractComplexType validationRules.ToList().Should().HaveCount(4); }
public void SuppressedCompletion(string content, int position) { var completionSets = new List<CompletionSet>(); RCompletionTestUtilities.GetCompletions(_editorShell, content, position, completionSets); completionSets.Should().ContainSingle() .Which.Completions.Should().BeEmpty(); }
public void It_stops_iterating_through_added_resolvers_when_one_returns_nonnull() { var compositeCommandResolver = new CompositeCommandResolver(); var resolverCalls = new List<int>(); var mockResolver1 = new Mock<ICommandResolver>(); mockResolver1.Setup(r => r .Resolve(It.IsAny<CommandResolverArguments>())) .Returns(new CommandSpec(null, null, default(CommandResolutionStrategy))) .Callback(() => resolverCalls.Add(1)); var mockResolver2 = new Mock<ICommandResolver>(); mockResolver2.Setup(r => r .Resolve(It.IsAny<CommandResolverArguments>())) .Returns(default(CommandSpec)) .Callback(() => resolverCalls.Add(2)); compositeCommandResolver.AddCommandResolver(mockResolver1.Object); compositeCommandResolver.AddCommandResolver(mockResolver2.Object); compositeCommandResolver.Resolve(default(CommandResolverArguments)); resolverCalls.Should() .HaveCount(1) .And .ContainInOrder(new [] {1}); }
public void RCompletionSource_CommentsTest01() { List<CompletionSet> completionSets = new List<CompletionSet>(); GetCompletions("#No", 3, completionSets); completionSets.Should().ContainSingle() .Which.Completions.Should().BeEmpty(); }
public void InplaceUpdateRemoveAllTest() { List<IntegerWrap> source = new List<IntegerWrap> { new IntegerWrap(1), new IntegerWrap(2), new IntegerWrap(3) }; List<IntegerWrap> update = new List<IntegerWrap>(); source.InplaceUpdate(update, IntegerComparer, ElementUpdater); source.Should().Equal(update, IntegerComparer); }
public void Should_calculate_retry_timespans_from_current_retry_attempt_and_timespan_provider() { var expectedRetryCounts = new[] { 2.Seconds(), 4.Seconds(), 8.Seconds(), 16.Seconds(), 32.Seconds() }; var retryTimeSpans = new List<TimeSpan>(); var policy = Policy .Handle<DivideByZeroException>() .WaitAndRetry(5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (_, timeSpan) => retryTimeSpans.Add(timeSpan) ); policy.RaiseException<DivideByZeroException>(5); retryTimeSpans.Should() .ContainInOrder(expectedRetryCounts); }
public void ResolvesAllAssemblies() { var packagePath = Path.Combine(PackagesPath, F.DefaultPackageName, F.DefaultVersion); var fileSystem = FileSystemMockBuilder.Create() .AddFiles(packagePath, F.TwoAssemblies) .Build(); var library = F.Create(assemblies: F.TwoAssemblies); var resolver = new PackageCompilationAssemblyResolver(fileSystem, PackagesPath); var assemblies = new List<string>(); var result = resolver.TryResolveAssemblyPaths(library, assemblies); assemblies.Should().HaveCount(2); assemblies.Should().Contain(Path.Combine(packagePath, F.DefaultAssemblyPath)); assemblies.Should().Contain(Path.Combine(packagePath, F.SecondAssemblyPath)); }
public void Shuffle_OrderChanges() { // In theory we could get back the exact same order- really unlikely, particularly with larger collections int[] source = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; List<int> items = new List<int>(source); items.Shuffle(); items.Should().NotEqual(source); }
public void RotateToHeadShouldWork() { var l = new List<int>() {1,2,3,4,5,6,7}; l = l.RotateToHead(n => n == 4); l.Should().Equal(4, 5, 6, 7, 1, 2, 3); }
public void BaseFunctions01() { var completionSets = new List<CompletionSet>(); RCompletionTestUtilities.GetCompletions(EditorShell, "", 0, completionSets); completionSets.Should().ContainSingle() .Which.Completions.Should().Contain(c => c.DisplayText == "abbreviate") .And.Contain(c => c.DisplayText == "abs"); }
public void RCompletionSource_BaseFunctionsTest01() { List<CompletionSet> completionSets = new List<CompletionSet>(); GetCompletions("", 0, completionSets); completionSets.Should().ContainSingle() .Which.Completions.Should().Contain(c => c.DisplayText == "abbreviate") .And.Contain(c => c.DisplayText == "abs"); }
public void RtvsPackage() { var completionSets = new List<CompletionSet>(); RCompletionTestUtilities.GetCompletions(EditorShell, "rtv", 3, completionSets, new TextRange(0, 3)); completionSets.Should().ContainSingle(); completionSets[0].Filter(); completionSets[0].Completions[0].DisplayText.Should().Be("rtvs"); }
protected void ExpectClientsReceivedDeviceConfiguration() { var clientsWhoGotTheMessage = new List<IActorRef>(); Enumerable.Range(0, ClientProxies.Count).ForEach(i => { ExpectMsg<DeviceConfiguration>((m, actor) => clientsWhoGotTheMessage.Add(actor)); }); clientsWhoGotTheMessage.Should().BeEquivalentTo(ClientProxies); }
public void RCompletionSource_SpecificPackageTest01() { List<CompletionSet> completionSets = new List<CompletionSet>(); GetCompletions("utils::", 7, completionSets); completionSets.Should().ContainSingle(); completionSets[0].Completions.Should().Contain(c => c.DisplayText == "adist") .Which.Description.Should().Be("Approximate String Distances"); }
public void RCompletionSource_PackagesTest01() { List<CompletionSet> completionSets = new List<CompletionSet>(); GetCompletions("library(", 8, completionSets); completionSets.Should().ContainSingle(); completionSets[0].Completions.Should().Contain(c => c.DisplayText == "base") .Which.Description.Should().Be("Base R functions."); }
public void Packages01() { var completionSets = new List<CompletionSet>(); RCompletionTestUtilities.GetCompletions(EditorShell, "lIbrAry(", 8, completionSets); completionSets.Should().ContainSingle(); completionSets[0].Completions.Should().Contain(c => c.DisplayText == "base") .Which.Description.Should().Be("Base R functions."); }
public void FunctionDefinition02() { for (int i = 14; i <= 18; i++) { var completionSets = new List<CompletionSet>(); RCompletionTestUtilities.GetCompletions(_editorShell, "x <- function(a, b)", i, completionSets); completionSets.Should().ContainSingle() .Which.Completions.Should().BeEmpty(); } }
public static void Verify(Project project, DiagnosticAnalyzer diagnosticAnalyzer) { var compilation = project.GetCompilationAsync().Result; var compilationWithAnalyzer = GetDiagnostics(compilation, diagnosticAnalyzer); var expected = new List<int>(ExpectedIssues(compilation.SyntaxTrees.First())); foreach (var diagnostic in compilationWithAnalyzer .Where(diag => diag.Id == diagnosticAnalyzer.SupportedDiagnostics.Single().Id)) { var line = diagnostic.GetLineNumberToReport(); expected.Should().Contain(line); expected.Remove(line); } expected.Should().BeEquivalentTo(Enumerable.Empty<int>()); }
public void doit() { var list = new List<string>(); var gameConnector = new GameConnector(); gameConnector.NewPosition += (sender, args) => list.Add(args.Board); gameConnector.Connect(); Thread.Sleep(1000); list.Should().NotBeEmpty(); }