public void WhenSendingMailFails_ShowsErrorMessage() { var expectedError = ErrorCode.Smtp_AuthenticationDenied; _smtpAction.ProcessJob(Arg.Any <Job>()).Returns(new ActionResult(expectedError)); var assistant = BuildAssistant(); assistant.SendTestMail(_profile, _accounts); _interactionRequest.AssertWasRaised <MessageInteraction>(); var messageInteraction = _interactionRequest.AssertWasRaised <MessageInteraction>(); Assert.AreEqual(_translation.SendTestMail, messageInteraction.Title); Assert.AreEqual(TranslationAttribute.GetValue(expectedError), messageInteraction.Text); Assert.AreEqual(MessageIcon.Error, messageInteraction.Icon); }
public void ShouldBeAbleToUseThePrevious() { IDeclarationQueue <MyClass> declarationQueue = Substitute.For <IDeclarationQueue <MyClass> >(); RangeDeclaration <MyClass> rangeDeclaration = new RangeDeclaration <MyClass>(listBuilderImpl, null, 10, 19); listBuilderImpl.BuilderSettings.Returns(new BuilderSettings()); listBuilderImpl.CreateObjectBuilder().Returns((IObjectBuilder <MyClass>)null); declarationQueue.GetLastItem().Returns(rangeDeclaration); listBuilderImpl.Declarations.Returns(declarationQueue); listBuilderImpl.AddDeclaration(Arg.Any <RangeDeclaration <MyClass> >()).Returns((IDeclaration <MyClass>)null); listBuilderImpl.BuilderSettings.Returns(new BuilderSettings()); var thePreviousDeclaration = (RangeDeclaration <MyClass>)ListBuilderExtensions.ThePrevious(listBuilderImpl, 10); thePreviousDeclaration.Start.ShouldBe(0); thePreviousDeclaration.End.ShouldBe(9); }
public void NSubstitute_Exception() { // Arrange var mockDataAccess = Substitute.For <IDataAccess>(); mockDataAccess.GetSpecificDrugs(Arg.Any <List <int> >()).Throws <ArgumentException>(); var mockThirdPartyAccess = Substitute.For <IThirdPartyDataAccess>(); var drugService = new DrugService(mockDataAccess, mockThirdPartyAccess); // Act Action getSpecificDrugs = () => drugService.GetSpecificDrugs(Arg.Any <List <int> >()); // Assert getSpecificDrugs.ShouldThrow <ArgumentException>(); }
public void TheNextShouldReturnRangeDeclaration() { IDeclarationQueue <MyClass> declarationQueue = Substitute.For <IDeclarationQueue <MyClass> >(); RangeDeclaration <MyClass> rangeDeclaration = new RangeDeclaration <MyClass>(listBuilderImpl, null, 0, 9); listBuilderImpl.BuilderSettings.Returns(new BuilderSettings()); listBuilderImpl.CreateObjectBuilder().Returns((IObjectBuilder <MyClass>)null); declarationQueue.GetLastItem().Returns(rangeDeclaration); listBuilderImpl.Declarations.Returns(declarationQueue); listBuilderImpl.AddDeclaration(Arg.Any <RangeDeclaration <MyClass> >()).Returns((IDeclaration <MyClass>)null); listBuilderImpl.BuilderSettings.Returns(new BuilderSettings()); var andTheNextDeclaration = (RangeDeclaration <MyClass>)ListBuilderExtensions.TheNext(listBuilderImpl, 10); Assert.That(andTheNextDeclaration.Start, Is.EqualTo(10)); Assert.That(andTheNextDeclaration.End, Is.EqualTo(19)); }
public async Task SendUsageStatistics_JobUsageStatsMetricHoldsProperValues() { var job = BuildJob(); var duration = TimeSpan.MaxValue; var status = "test status"; var product = _applicationNameProvider.ApplicationNameWithEdition.ToLower().Replace(" ", "_"); JobUsageStatisticsMetric metric = new JobUsageStatisticsMetric(); _usageStatisticsManager.EnableUsageStatistics = true; _usageStatisticsSender.When(sender => sender.SendAsync(Arg.Any <IUsageMetric>())).Do(info => { metric = info.Arg <JobUsageStatisticsMetric>(); }); await _usageStatisticsManager.SendUsageStatistics(duration, job, status); Assert.AreEqual("JobMetric", metric.EventName); Assert.AreEqual(product, metric.Product); Assert.AreEqual(_machineIdGenerator.GetMachineId(), metric.MachineId); Assert.AreEqual(_versionHelper.ApplicationVersion, metric.Version); Assert.AreEqual(OutputFormat.Pdf.ToString(), metric.OutputFormat); Assert.AreEqual(status, metric.Status); Assert.AreEqual((long)duration.TotalMilliseconds, metric.Duration); Assert.AreEqual(job.JobInfo.TotalPages, metric.TotalPages); Assert.AreEqual(job.NumberOfCopies, metric.NumberOfCopies); Assert.AreEqual(job.Profile.DropboxSettings.Enabled, metric.Dropbox); Assert.AreEqual(job.Profile.Ftp.Enabled, metric.Ftp); Assert.AreEqual(job.Profile.EmailSmtpSettings.Enabled, metric.Smtp); Assert.AreEqual(job.Profile.HttpSettings.Enabled, metric.Http); Assert.AreEqual(job.Profile.Printing.Enabled, metric.Print); Assert.AreEqual(job.Profile.CoverPage.Enabled, metric.Cover); Assert.AreEqual(job.Profile.BackgroundPage.Enabled, metric.Background); Assert.AreEqual(job.Profile.AttachmentPage.Enabled, metric.Attachment); Assert.AreEqual(job.Profile.Stamping.Enabled, metric.Stamp); Assert.AreEqual(job.Profile.PdfSettings.Security.Enabled, metric.Encryption); Assert.AreEqual(job.Profile.PdfSettings.Signature.Enabled, metric.Signature); Assert.AreEqual(job.Profile.Scripting.Enabled, metric.Script); Assert.AreEqual(job.Profile.CustomScript.Enabled, metric.CustomScript); Assert.AreEqual(job.Profile.UserTokens.Enabled, metric.UserToken); }
private static WebConnectionInfo MockCookieDataManager(IServiceLocator serviceLocator) { WebConnectionInfo webConnectionInfo = new WebConnectionInfo { UserAuthToken = "test" }; string serializedWebConnectionInfo = JsonConvert.SerializeObject( webConnectionInfo, new JsonSerializerSettings { Converters = { new WebConnectionInfoConverter() } }); ICookieDataManager cookieDataManager = Substitute.For <ICookieDataManager>(); cookieDataManager.Decompress(Arg.Any <string>()).Returns(serializedWebConnectionInfo); serviceLocator.GetInstance <ICookieDataManager>().Returns(cookieDataManager); return(webConnectionInfo); }
public async Task ShouldRouteToCorrect_Notification_WithManyHandlers() { var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"), "csharp"); var textDocumentSyncHandler2 = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cake"), "csharp"); textDocumentSyncHandler.Handle(Arg.Any <DidSaveTextDocumentParams>(), Arg.Any <CancellationToken>()) .Returns(Unit.Value); textDocumentSyncHandler2.Handle(Arg.Any <DidSaveTextDocumentParams>(), Arg.Any <CancellationToken>()) .Returns(Unit.Value); var textDocumentIdentifiers = new TextDocumentIdentifiers(); AutoSubstitute.Provide(textDocumentIdentifiers); var collection = new SharedHandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, textDocumentIdentifiers, new ServiceCollection().BuildServiceProvider()) { textDocumentSyncHandler, textDocumentSyncHandler2 }; AutoSubstitute.Provide <IHandlerCollection>(collection); AutoSubstitute.Provide <IEnumerable <ILspHandlerDescriptor> >(collection); AutoSubstitute.Provide <IHandlerMatcher>(new TextDocumentMatcher(LoggerFactory.CreateLogger <TextDocumentMatcher>(), textDocumentIdentifiers)); var mediator = AutoSubstitute.Resolve <LspRequestRouter>(); var @params = new DidSaveTextDocumentParams { TextDocument = new TextDocumentIdentifier(new Uri("file:///c:/test/123.cake")) }; var request = new Notification( TextDocumentNames.DidSave, JObject.Parse(JsonConvert.SerializeObject(@params, new Serializer(ClientVersion.Lsp3).Settings)) ); await mediator.RouteNotification(mediator.GetDescriptors(request), request, CancellationToken.None); await textDocumentSyncHandler.Received(0) .Handle(Arg.Any <DidSaveTextDocumentParams>(), Arg.Any <CancellationToken>()); await textDocumentSyncHandler2.Received(1) .Handle(Arg.Any <DidSaveTextDocumentParams>(), Arg.Any <CancellationToken>()); }
public void Should_Return_Did_Folding_Range_handler() { // Given var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.ps*1"), "powershell"); var handler = Substitute.For <IFoldingRangeHandler>(); handler.GetRegistrationOptions(Arg.Any <FoldingRangeCapability>(), Arg.Any <ClientCapabilities>()).Returns( new FoldingRangeRegistrationOptions { DocumentSelector = new DocumentSelector(new DocumentFilter { Pattern = "**/*.ps*1" }) } ); var textDocumentIdentifiers = new TextDocumentIdentifiers(); AutoSubstitute.Provide(textDocumentIdentifiers); var collection = new SharedHandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, textDocumentIdentifiers, Substitute.For <IResolverContext>(), new LspHandlerTypeDescriptorProvider(new [] { typeof(FoundationTests).Assembly, typeof(LanguageServer).Assembly, typeof(LanguageClient).Assembly, typeof(IRegistrationManager).Assembly, typeof(LspRequestRouter).Assembly })) { textDocumentSyncHandler, handler }; AutoSubstitute.Provide <IHandlerCollection>(collection); AutoSubstitute.Provide <IEnumerable <ILspHandlerDescriptor> >(collection); var handlerMatcher = AutoSubstitute.Resolve <TextDocumentMatcher>(); // When var result = handlerMatcher.FindHandler( new FoldingRangeRequestParam { TextDocument = new TextDocumentItem { Uri = new Uri("file:///abc/123/d.ps1") } }, collection.Where(x => x.Method == TextDocumentNames.DidOpen) ); // Then var lspHandlerDescriptors = result as ILspHandlerDescriptor[] ?? result.ToArray(); lspHandlerDescriptors.Should().NotBeNullOrEmpty(); lspHandlerDescriptors.Should().Contain(x => x.Method == TextDocumentNames.DidOpen); }
public ClientCapabilityProviderFixture() { var handler = Substitute.For <IExecuteCommandHandler>(); handler.GetRegistrationOptions(Arg.Any <ExecuteCommandCapability>(), Arg.Any <ClientCapabilities>()).Returns(new ExecuteCommandRegistrationOptions()); var handlerCollection = new SharedHandlerCollection( SupportedCapabilitiesFixture.AlwaysTrue, new TextDocumentIdentifiers(), Substitute.For <IResolverContext>(), new LspHandlerTypeDescriptorProvider(new [] { typeof(FoundationTests).Assembly, typeof(LanguageServer).Assembly, typeof(LanguageClient).Assembly, typeof(IRegistrationManager).Assembly, typeof(LspRequestRouter).Assembly }) ) { handler }; var capabilityProvider = new ClientCapabilityProvider(handlerCollection, true); Provider = capabilityProvider; }
public void WhenSendingMailFails_ShowsErrorMessage() { var expectedError = ErrorCode.Smtp_AuthenticationDenied; _smtpAction.ProcessJob(Arg.Any <Job>()).Returns(new ActionResult(expectedError)); var assistant = BuildAssistant(); assistant.SendTestMail(_profile, new Accounts()); _interactionInvoker.Received().Invoke(Arg.Any <MessageInteraction>()); var messageInteraction = _interactions.Where(x => x is MessageInteraction).Cast <MessageInteraction>().First(); var errorCodeInt = (int)expectedError; Assert.AreEqual("SmtpEmailActionSettings\\SendTestMail", messageInteraction.Title); Assert.AreEqual($"ErrorCodes\\{errorCodeInt}", messageInteraction.Text); Assert.AreEqual(MessageIcon.Error, messageInteraction.Icon); }
public void WhenProfileInvalid_DisplaysErrorMessage() { var expectedError = ErrorCode.Smtp_NoPasswordSpecified; _smtpAction.Check(_profile, Arg.Any <Accounts>()).Returns(x => new ActionResult(expectedError)); var assistant = BuildAssistant(); assistant.SendTestMail(_profile, new Accounts()); _interactionInvoker.Received().Invoke(Arg.Any <MessageInteraction>()); var messageInteraction = _interactions.Where(x => x is MessageInteraction).Cast <MessageInteraction>().First(); var errorCodeInt = (int)expectedError; Assert.AreEqual("SmtpEmailActionSettings\\SendTestMail", messageInteraction.Title); Assert.AreEqual($"ErrorCodes\\{errorCodeInt}", messageInteraction.Text); Assert.AreEqual(MessageIcon.Error, messageInteraction.Icon); }
public async Task Started_Interface_Is_Supported_On_Handlers_After_Startup() { var onLanguageClientStarted = (IOnLanguageClientStarted)Substitute.For(new[] { typeof(IOnLanguageClientStarted), typeof(PublishDiagnosticsHandler) }, Array.Empty <object>()); var onLanguageServerStarted = (IOnLanguageServerStarted)Substitute.For(new[] { typeof(IOnLanguageServerStarted), typeof(CompletionHandler) }, new object[] { new CompletionRegistrationOptions() }); var(client, server) = await Initialize(o => { }, o => { }); await onLanguageClientStarted.Received(0).OnStarted(client, Arg.Any <CancellationToken>()); await onLanguageServerStarted.Received(0).OnStarted(server, Arg.Any <CancellationToken>()); client.Register(r => r.AddHandler((IJsonRpcHandler)onLanguageClientStarted !)); server.Register(r => r.AddHandler((IJsonRpcHandler)onLanguageServerStarted !)); await onLanguageClientStarted.Received(1).OnStarted(client, Arg.Any <CancellationToken>()); await onLanguageServerStarted.Received(1).OnStarted(server, Arg.Any <CancellationToken>()); }
public async Task ShouldRouteToCorrect_Request() { var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"), "csharp"); textDocumentSyncHandler.Handle(Arg.Any <DidSaveTextDocumentParams>(), Arg.Any <CancellationToken>()) .Returns(Unit.Value); var codeActionHandler = Substitute.For <ICodeActionHandler>(); codeActionHandler.GetRegistrationOptions().Returns(new CodeActionRegistrationOptions { DocumentSelector = DocumentSelector.ForPattern("**/*.cs") }); codeActionHandler .Handle(Arg.Any <CodeActionParams>(), Arg.Any <CancellationToken>()) .Returns(new CommandOrCodeActionContainer()); var collection = new SharedHandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, new TextDocumentIdentifiers(), new ServiceCollection().BuildServiceProvider()) { textDocumentSyncHandler, codeActionHandler }; AutoSubstitute.Provide <IHandlerCollection>(collection); AutoSubstitute.Provide <IEnumerable <ILspHandlerDescriptor> >(collection); var mediator = AutoSubstitute.Resolve <LspRequestRouter>(); var id = Guid.NewGuid().ToString(); var @params = new DidSaveTextDocumentParams { TextDocument = new TextDocumentIdentifier(new Uri("file:///c:/test/123.cs")) }; var request = new Request( id, TextDocumentNames.CodeAction, JObject.Parse(JsonConvert.SerializeObject(@params, new Serializer(ClientVersion.Lsp3).Settings)) ); await mediator.RouteRequest(mediator.GetDescriptors(request), request, CancellationToken.None); await codeActionHandler.Received(1).Handle(Arg.Any <CodeActionParams>(), Arg.Any <CancellationToken>()); }
public void Should_DealWithClassesThatImplementMultipleHandlers_BySettingKeyAccordingly() { var codeLensHandler = Substitute.For(new[] { typeof(ICodeLensHandler), typeof(ICodeLensResolveHandler) }, new object[0]); ((ICodeLensHandler)codeLensHandler).GetRegistrationOptions(Arg.Any <CodeLensCapability>(), Arg.Any <ClientCapabilities>()) .Returns( new CodeLensRegistrationOptions { DocumentSelector = new DocumentSelector(DocumentFilter.ForLanguage("foo")) } ); var handler = new SharedHandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, new TextDocumentIdentifiers(), Substitute.For <IResolverContext>(), new LspHandlerTypeDescriptorProvider(new [] { typeof(FoundationTests).Assembly, typeof(LanguageServer).Assembly, typeof(LanguageClient).Assembly, typeof(IRegistrationManager).Assembly, typeof(LspRequestRouter).Assembly })); handler.Initialize(); handler.Add((codeLensHandler as IJsonRpcHandler) !); var descriptor = handler.OfType <LspHandlerDescriptor>().Select(x => x.Key); descriptor.Should().BeEquivalentTo("[foo]", "default"); }
public async Task ShouldRouteToCorrect_Notification() { var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"), "csharp"); textDocumentSyncHandler.Handle(Arg.Any <DidSaveTextDocumentParams>(), Arg.Any <CancellationToken>()) .Returns(Unit.Value); var collection = new SharedHandlerCollection( SupportedCapabilitiesFixture.AlwaysTrue, new TextDocumentIdentifiers(), Substitute.For <IResolverContext>(), new LspHandlerTypeDescriptorProvider( new[] { typeof(FoundationTests).Assembly, typeof(LanguageServer).Assembly, typeof(LanguageClient).Assembly, typeof(IRegistrationManager).Assembly, typeof(LspRequestRouter).Assembly } ) ) { textDocumentSyncHandler }; AutoSubstitute.Provide <IHandlerCollection>(collection); AutoSubstitute.Provide <IEnumerable <ILspHandlerDescriptor> >(collection); var mediator = AutoSubstitute.Resolve <LspRequestRouter>(); var @params = new DidSaveTextDocumentParams { TextDocument = new TextDocumentIdentifier(new Uri("file:///c:/test/123.cs")) }; var request = new Notification( TextDocumentNames.DidSave, JObject.Parse(JsonConvert.SerializeObject(@params, new Serializer(ClientVersion.Lsp3).Settings)) ); await mediator.RouteNotification(mediator.GetDescriptors(request), request, CancellationToken.None); await textDocumentSyncHandler.Received(1) .Handle(Arg.Any <DidSaveTextDocumentParams>(), Arg.Any <CancellationToken>()); }
public async Task WhenCreateOfflineConnection_WithOfflinePersonIdAndInstanceId() { // Arrange WebHealthVaultConfiguration configuration = new WebHealthVaultConfiguration { DefaultHealthVaultShellUrl = new Uri("http://www.bing.com"), DefaultHealthVaultUrl = new Uri("http://www.bing.com") }; IServiceLocator serviceLocator = Substitute.For <IServiceLocator>(); serviceLocator.GetInstance <WebHealthVaultConfiguration>().Returns(configuration); IOfflineHealthVaultConnection mokcedOfflineHealthVaultConnection = Substitute.For <OfflineHealthVaultConnection>(serviceLocator); Ioc.Container.Configure(c => c.ExportInstance(mokcedOfflineHealthVaultConnection).As <IOfflineHealthVaultConnection>()); WebHealthVaultFactory factory = new WebHealthVaultFactory(); string offlinePersonId = Guid.NewGuid().ToString(); IServiceInstanceProvider serviceInstanceProvider = Substitute.For <IServiceInstanceProvider>(); serviceInstanceProvider.GetHealthServiceInstanceAsync(Arg.Any <string>()) .Returns(new HealthServiceInstance { Name = "Test" }); Ioc.Container.Configure(c => c.ExportInstance(serviceInstanceProvider).As <IServiceInstanceProvider>()); string instanceId = Guid.NewGuid().ToString(); // Act IOfflineHealthVaultConnection offlineHealthVaultConnection = await factory.CreateOfflineConnectionInternalAsync( offlinePersonId : offlinePersonId, instanceId : instanceId); // Assert Assert.AreEqual(offlinePersonId, offlineHealthVaultConnection.OfflinePersonId.ToString()); Assert.AreEqual("Test", ((OfflineHealthVaultConnection)offlineHealthVaultConnection).ServiceInstance.Name); }
public void Should_Contain_AllDefinedMethods_OnLanguageServer(Type requestHandler, Type type2, string key, string key2, int count) { var handler = new SharedHandlerCollection(SupportedCapabilitiesFixture.AlwaysTrue, new TextDocumentIdentifiers(), Substitute.For <IResolverContext>(), new LspHandlerTypeDescriptorProvider(new [] { typeof(FoundationTests).Assembly, typeof(LanguageServer).Assembly, typeof(LanguageClient).Assembly, typeof(IRegistrationManager).Assembly, typeof(LspRequestRouter).Assembly })); handler.Initialize(); var sub = (IJsonRpcHandler)Substitute.For(new[] { requestHandler, type2 }, new object[0]); if (sub is IRegistration <ITextDocumentRegistrationOptions> reg) { reg.GetRegistrationOptions(Arg.Any <ClientCapabilities>()) .Returns( new TextDocumentSyncRegistrationOptions() { DocumentSelector = new DocumentSelector() } ); } handler.Add(sub); handler.Should().Contain(x => x.Method == key); handler.Should().Contain(x => x.Method == key2); handler.Should().HaveCount(count); }
public void NSubstitute_GetTheDrugs() { // Arrange var mockDataAccess = Substitute.For <IDataAccess>(); mockDataAccess.GetAllTheDrugs().Returns(_fakeDrugList); var mockThirdPartyAccess = Substitute.For <IThirdPartyDataAccess>(); mockThirdPartyAccess.GetThirdPartyDrugInfo(Arg.Any <Drug>()) .Returns(FakeThirdPartyInfo1, FakeThirdPartyInfo2, FakeThirdPartyInfo3); var drugService = new DrugService(mockDataAccess, mockThirdPartyAccess); // Act var actualDrugs = drugService.GetTheDrugs(); // Assert actualDrugs.Count().ShouldBe(3); mockDataAccess.Received(1).GetAllTheDrugs(); mockThirdPartyAccess.Received(3).GetThirdPartyDrugInfo(Arg.Any <Drug>()); }
public async Task SendServiceStatistics_ServiceUsageStatisticsMetricHoldsProperValues() { var duration = TimeSpan.MaxValue; var product = _applicationNameProvider.ApplicationNameWithEdition.ToLower().Replace(" ", "_"); ServiceUsageStatisticsMetric metric = new ServiceUsageStatisticsMetric(); _usageStatisticsManager.EnableUsageStatistics = true; _usageStatisticsSender.When(sender => sender.SendAsync(Arg.Any <IUsageMetric>())).Do(info => { metric = info.Arg <ServiceUsageStatisticsMetric>(); }); await _usageStatisticsManager.SendServiceStatistics(duration); Assert.AreEqual("ServiceMetric", metric.EventName); Assert.AreEqual(product, metric.Product); Assert.AreEqual(_machineIdGenerator.GetMachineId(), metric.MachineId); Assert.AreEqual(_versionHelper.ApplicationVersion, metric.Version); Assert.AreEqual(_osHelper.GetWindowsVersion(), metric.OperatingSystem); Assert.AreEqual((long)duration.TotalMilliseconds, metric.ServiceUptime); }
public async Task WhenAuthorizingAdditionalRecords_ThenShellAuthServiceInvoked() { SetupLocalStore(); var responseMessage = GenerateResponseMessage("GetAuthorizedPeopleResult.xml"); _subHealthWebRequestClient .SendAsync( new Uri("https://platform.healthvault-ppe.com/platform/wildcat.ashx"), Arg.Any <byte[]>(), Arg.Any <int>(), Arg.Any <IDictionary <string, string> >(), Arg.Any <CancellationToken>()) .Returns(responseMessage); HealthVaultSodaConnection healthVaultSodaConnection = CreateHealthVaultSodaConnection(); await healthVaultSodaConnection.AuthorizeAdditionalRecordsAsync(); await _subShellAuthService.Received() .AuthorizeAdditionalRecordsAsync(new Uri("https://account.healthvault-ppe.com/"), new Guid(ApplicationInstanceId)); await _subLocalObjectStore.Received() .WriteAsync(HealthVaultSodaConnection.PersonInfoKey, Arg.Any <object>()); }
public async Task WhenAuthenticateCalledWithNoStoredInfo_ThenInfoIsFetchedAndStored() { SetupEmptyLocalStore(); _healthVaultConfiguration.MasterApplicationId = s_masterApplicationId; var responseMessage1 = GenerateResponseMessage("NewApplicationCreationInfoResult.xml"); var responseMessage2 = GenerateResponseMessage("GetServiceDefinitionResult.xml"); // #3 is CAST call - but goes through IClientSessionCredentialClient and not HealthWebRequestClient var responseMessage4 = GenerateResponseMessage("GetAuthorizedPeopleResult.xml"); // The first few calls use the default endpoint _subHealthWebRequestClient .SendAsync( new Uri("https://platform2.healthvault.com/platform/wildcat.ashx"), Arg.Any <byte[]>(), Arg.Any <int>(), Arg.Any <IDictionary <string, string> >(), Arg.Any <CancellationToken>()) .Returns(responseMessage1, responseMessage2); // After GetServiceDefinition called, we are calling new endpoint _subHealthWebRequestClient .SendAsync( new Uri("https://platform.healthvault-ppe.com/platform/wildcat.ashx"), Arg.Any <byte[]>(), Arg.Any <int>(), Arg.Any <IDictionary <string, string> >(), Arg.Any <CancellationToken>()) .Returns(responseMessage4); var sessionCredential = new SessionCredential { Token = SessionToken, SharedSecret = SessionSharedSecret }; _subClientSessionCredentialClient .GetSessionCredentialAsync(Arg.Any <CancellationToken>()) .Returns(sessionCredential); _subServiceLocator .GetInstance <IClientSessionCredentialClient>() .Returns(_subClientSessionCredentialClient); // These values match the values in NewApplicationCreationInfoResult.xml _subShellAuthService .ProvisionApplicationAsync( new Uri("https://account.healthvault.com"), s_masterApplicationId, ApplicationCreationToken, ApplicationInstanceId) .Returns("1"); HealthVaultSodaConnection healthVaultSodaConnection = CreateHealthVaultSodaConnection(); await healthVaultSodaConnection.AuthenticateAsync(); _subClientSessionCredentialClient.Received().AppSharedSecret = ApplicationSharedSecret; _subClientSessionCredentialClient.Received().Connection = healthVaultSodaConnection; await _subLocalObjectStore.Received() .WriteAsync( HealthVaultSodaConnection.ServiceInstanceKey, Arg.Is <object>(o => ((HealthServiceInstance)o).HealthServiceUrl == new Uri("https://platform.healthvault-ppe.com/platform/wildcat.ashx"))); await _subLocalObjectStore.Received() .WriteAsync( HealthVaultSodaConnection.ApplicationCreationInfoKey, Arg.Is <object>(o => ((ApplicationCreationInfo)o).AppInstanceId == new Guid("b5c5593b-afb4-466d-88f2-31707fb8634b"))); await _subLocalObjectStore.Received() .WriteAsync( HealthVaultSodaConnection.SessionCredentialKey, Arg.Is <object>(o => ((SessionCredential)o).SharedSecret == SessionSharedSecret)); await _subLocalObjectStore.Received() .WriteAsync( HealthVaultSodaConnection.PersonInfoKey, Arg.Is <object>(o => ((PersonInfo)o).Name == "David Rickard")); }
public async Task ShouldRouteToCorrect_Request_WithManyHandlers_CodeLensHandler() { var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs"), "csharp"); var textDocumentSyncHandler2 = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cake"), "csharp"); textDocumentSyncHandler.Handle(Arg.Any <DidSaveTextDocumentParams>(), Arg.Any <CancellationToken>()) .Returns(Unit.Value); textDocumentSyncHandler2.Handle(Arg.Any <DidSaveTextDocumentParams>(), Arg.Any <CancellationToken>()) .Returns(Unit.Value); var codeActionHandler = Substitute.For <ICodeLensHandler>(); codeActionHandler.GetRegistrationOptions().Returns(new CodeLensRegistrationOptions { DocumentSelector = DocumentSelector.ForPattern("**/*.cs") }); codeActionHandler .Handle(Arg.Any <CodeLensParams>(), Arg.Any <CancellationToken>()) .Returns(new CodeLensContainer()); var codeActionHandler2 = Substitute.For <ICodeLensHandler>(); codeActionHandler2.GetRegistrationOptions().Returns(new CodeLensRegistrationOptions { DocumentSelector = DocumentSelector.ForPattern("**/*.cake") }); codeActionHandler2 .Handle(Arg.Any <CodeLensParams>(), Arg.Any <CancellationToken>()) .Returns(new CodeLensContainer()); var tdi = new TextDocumentIdentifiers(); var collection = new SharedHandlerCollection( SupportedCapabilitiesFixture.AlwaysTrue, tdi, Substitute.For <IResolverContext>(), new LspHandlerTypeDescriptorProvider( new[] { typeof(FoundationTests).Assembly, typeof(LanguageServer).Assembly, typeof(LanguageClient).Assembly, typeof(IRegistrationManager).Assembly, typeof(LspRequestRouter).Assembly } ) ) { textDocumentSyncHandler, textDocumentSyncHandler2, codeActionHandler, codeActionHandler2 }; AutoSubstitute.Provide <IHandlerCollection>(collection); AutoSubstitute.Provide <IEnumerable <ILspHandlerDescriptor> >(collection); AutoSubstitute.Provide <IHandlerMatcher>(new TextDocumentMatcher(LoggerFactory.CreateLogger <TextDocumentMatcher>(), tdi)); var mediator = AutoSubstitute.Resolve <LspRequestRouter>(); var id = Guid.NewGuid().ToString(); var @params = new CodeLensParams { TextDocument = new TextDocumentIdentifier(new Uri("file:///c:/test/123.cs")) }; var request = new Request( id, TextDocumentNames.CodeLens, JObject.Parse(JsonConvert.SerializeObject(@params, new Serializer(ClientVersion.Lsp3).Settings)) ); await mediator.RouteRequest(mediator.GetDescriptors(request), request, CancellationToken.None); await codeActionHandler2.Received(0).Handle(Arg.Any <CodeLensParams>(), Arg.Any <CancellationToken>()); await codeActionHandler.Received(1).Handle(Arg.Any <CodeLensParams>(), Arg.Any <CancellationToken>()); }
public async Task Initialize_Interface_Is_Supported_On_Handlers() { var onLanguageClientInitialize = Substitute.For(new[] { typeof(IOnLanguageClientInitialize), typeof(PublishDiagnosticsHandler) }, Array.Empty <object>()) as IOnLanguageClientInitialize; var onLanguageServerInitialize = Substitute.For(new[] { typeof(IOnLanguageServerInitialize), typeof(CompletionHandler) }, new object[] { new CompletionRegistrationOptions() }) as IOnLanguageServerInitialize; var(client, server) = await Initialize( options => options.AddHandler(onLanguageClientInitialize as IJsonRpcHandler), options => options.AddHandler(onLanguageServerInitialize as IJsonRpcHandler) ); await onLanguageClientInitialize.Received(1).OnInitialize(client, client.ClientSettings, Arg.Any <CancellationToken>()); await onLanguageServerInitialize.Received(1).OnInitialize(server, server.ClientSettings, Arg.Any <CancellationToken>()); }
public async Task Initialize_Delegate_Is_Supported() { var onLanguageClientInitialize = Substitute.For <OnLanguageClientInitializeDelegate>(); var onLanguageServerInitialize = Substitute.For <OnLanguageServerInitializeDelegate>(); var(client, server) = await Initialize( options => options.OnInitialize(onLanguageClientInitialize), options => options.OnInitialize(onLanguageServerInitialize) ); await onLanguageClientInitialize.Received(1).Invoke(client, client.ClientSettings, Arg.Any <CancellationToken>()); await onLanguageServerInitialize.Received(1).Invoke(server, server.ClientSettings, Arg.Any <CancellationToken>()); }
public async Task Initialize_Interface_Is_Supported() { var onLanguageClientInitialize = Substitute.For <IOnLanguageClientInitialize>(); var onLanguageServerInitialize = Substitute.For <IOnLanguageServerInitialize>(); var(client, server) = await Initialize( options => options.Services.AddSingleton(onLanguageClientInitialize), options => options.Services.AddSingleton(onLanguageServerInitialize) ); await onLanguageClientInitialize.Received(1).OnInitialize(client, client.ClientSettings, Arg.Any <CancellationToken>()); await onLanguageServerInitialize.Received(1).OnInitialize(server, server.ClientSettings, Arg.Any <CancellationToken>()); }
public static IEnumerable <object[]> Should_DealWithClassesThatImplementMultipleHandlers_WithoutConflictingRegistrations_Data() { var codeLensHandler = Substitute.For(new[] { typeof(ICodeLensHandler), typeof(ICodeLensResolveHandler), typeof(ICanBeIdentifiedHandler) }, new object[0]); ((ICodeLensHandler)codeLensHandler).GetRegistrationOptions(Arg.Any <CodeLensCapability>(), Arg.Any <ClientCapabilities>()) .Returns( new CodeLensRegistrationOptions { DocumentSelector = new DocumentSelector() } ); yield return(new[] { TextDocumentNames.CodeLensResolve, codeLensHandler }); var documentLinkHandler = Substitute.For(new[] { typeof(IDocumentLinkHandler), typeof(IDocumentLinkResolveHandler), typeof(ICanBeIdentifiedHandler) }, new object[0]); ((IDocumentLinkHandler)documentLinkHandler).GetRegistrationOptions(Arg.Any <DocumentLinkCapability>(), Arg.Any <ClientCapabilities>()) .Returns( new DocumentLinkRegistrationOptions { DocumentSelector = new DocumentSelector() } ); yield return(new[] { TextDocumentNames.DocumentLinkResolve, documentLinkHandler }); var completionHandler = Substitute.For(new[] { typeof(ICompletionHandler), typeof(ICompletionResolveHandler), typeof(ICanBeIdentifiedHandler) }, new object[0]); ((ICompletionHandler)completionHandler).GetRegistrationOptions(Arg.Any <CompletionCapability>(), Arg.Any <ClientCapabilities>()) .Returns( new CompletionRegistrationOptions { DocumentSelector = new DocumentSelector() } ); yield return(new[] { TextDocumentNames.CompletionResolve, completionHandler }); }
public void Should_Create_Usable_Logger() { AutoSubstitute.Resolve <Impl>(); AutoSubstitute.Resolve <ITestOutputHelper>().Received().WriteLine(Arg.Any <string>()); }
public void SetUp() { var bootstrapper = new IntegrationTestBootstrapper(); var container = bootstrapper.ConfigureContainer(); _th = container.GetInstance <TestHelper>(); _th.InitTempFolder("DevicesGeneralTests"); _singleTempOutputfile = new[] { @"output1.pdf" }; _multipleTempOutputFiles = new[] { @"output1.png", @"output2.png", @"output3.png" }; _multipleTempOutputFilesWithTwoDigits = new[] { @"output1.png", @"output2.png", @"output3.png", @"output4.png", @"output5.png", @"output6.png", @"output7.png", @"output8.png", @"output9.png", @"output10.png" }; _countRetypeOutputFilename = 0; _cancelRetypeFilename = false; _pathUtil = new PathUtil(new PathWrap(), new DirectoryWrap()); _queryRetypeFileName = Substitute.For <IRetypeFileNameQuery>(); _queryRetypeFileName.RetypeFileNameQuery(Arg.Any <string>(), Arg.Any <OutputFormat>(), Arg.Any <RetypeReason>()).Returns(RetypeOutputFilename); }
public async Task Initialize_Interface_Is_Supported_On_Handlers_After_Startup() { var onLanguageClientInitialize = (IOnLanguageClientInitialize)Substitute.For(new[] { typeof(IOnLanguageClientInitialize), typeof(PublishDiagnosticsHandlerBase) }, Array.Empty <object>()); var onLanguageServerInitialize = (IOnLanguageServerInitialize)Substitute.For(new[] { typeof(IOnLanguageServerInitialize), typeof(CompletionHandlerBase) }, new object[] { }); var(client, server) = await Initialize(o => { }, o => { }); await onLanguageClientInitialize.Received(0).OnInitialize(client, client.ClientSettings, Arg.Any <CancellationToken>()); await onLanguageServerInitialize.Received(0).OnInitialize(server, server.ClientSettings, Arg.Any <CancellationToken>()); client.Register(r => r.AddHandler((IJsonRpcHandler)onLanguageClientInitialize !)); server.Register(r => r.AddHandler((IJsonRpcHandler)onLanguageServerInitialize !)); await onLanguageClientInitialize.Received(1).OnInitialize(client, client.ClientSettings, Arg.Any <CancellationToken>()); await onLanguageServerInitialize.Received(1).OnInitialize(server, server.ClientSettings, Arg.Any <CancellationToken>()); }
public async Task Initialized_Interface_Is_Supported_On_Handlers() { var onLanguageClientInitialized = (IOnLanguageClientInitialized)Substitute.For(new[] { typeof(IOnLanguageClientInitialized), typeof(PublishDiagnosticsHandlerBase) }, Array.Empty <object>()); var onLanguageServerInitialized = (IOnLanguageServerInitialized)Substitute.For(new[] { typeof(IOnLanguageServerInitialized), typeof(CompletionHandlerBase) }, new object[] { }); var(client, server) = await Initialize( options => options.AddHandler((IJsonRpcHandler)onLanguageClientInitialized !), options => options.AddHandler((IJsonRpcHandler)onLanguageServerInitialized !) ); await onLanguageClientInitialized.Received(1).OnInitialized(client, client.ClientSettings, client.ServerSettings, Arg.Any <CancellationToken>()); await onLanguageServerInitialized.Received(1).OnInitialized(server, server.ClientSettings, server.ServerSettings, Arg.Any <CancellationToken>()); }