public async Task AddOutbound_WithMultipleBrokers_MessagesCorrectlyRouted() { var serviceProvider = ServiceProviderHelper.GetServiceProvider( services => services .AddFakeLogger() .AddSilverback() .WithConnectionToMessageBroker( options => options .AddBroker <TestBroker>() .AddBroker <TestOtherBroker>()) .AddEndpoints( endpoints => endpoints .AddOutbound <TestEventOne>(new TestProducerEndpoint("test1")) .AddOutbound <TestEventTwo>(new TestOtherProducerEndpoint("test2")))); var broker = serviceProvider.GetRequiredService <TestBroker>(); await broker.ConnectAsync(); var otherBroker = serviceProvider.GetRequiredService <TestOtherBroker>(); await otherBroker.ConnectAsync(); var publisher = serviceProvider.GetRequiredService <IPublisher>(); await publisher.PublishAsync(new TestEventOne()); await publisher.PublishAsync(new TestEventOne()); await publisher.PublishAsync(new TestEventTwo()); await publisher.PublishAsync(new TestEventTwo()); await publisher.PublishAsync(new TestEventTwo()); broker.ProducedMessages.Should().HaveCount(2); otherBroker.ProducedMessages.Should().HaveCount(3); }
public async Task StartAsync_ApplicationStopping_BrokerGracefullyDisconnectedRegardlessOfMode( BrokerConnectionMode mode) { var appStoppingTokenSource = new CancellationTokenSource(); var appStoppedTokenSource = new CancellationTokenSource(); var lifetimeEvents = Substitute.For <IHostApplicationLifetime>(); lifetimeEvents.ApplicationStopping.Returns(appStoppingTokenSource.Token); lifetimeEvents.ApplicationStopped.Returns(appStoppedTokenSource.Token); var serviceProvider = ServiceProviderHelper.GetServiceProvider( services => services .AddTransient(_ => lifetimeEvents) .AddFakeLogger() .AddSilverback() .WithConnectionToMessageBroker( options => options .AddBroker <TestBroker>() .WithConnectionOptions( new BrokerConnectionOptions { Mode = mode }))); var service = serviceProvider.GetServices <IHostedService>().OfType <BrokerConnectorService>().Single(); await service.StartAsync(CancellationToken.None); var testBroker = serviceProvider.GetRequiredService <TestBroker>(); await testBroker.ConnectAsync(); testBroker.IsConnected.Should().BeTrue(); appStoppingTokenSource.Cancel(); appStoppedTokenSource.Cancel(); testBroker.IsConnected.Should().BeFalse(); }
public async Task AddOutbound_MultipleEndpoints_MessagesCorrectlyRouted() { var serviceProvider = ServiceProviderHelper.GetServiceProvider( services => services .AddFakeLogger() .AddSilverback() .WithConnectionToMessageBroker(options => options.AddBroker <TestBroker>()) .AddEndpoints( endpoints => endpoints .AddOutbound <TestEventOne>(new TestProducerEndpoint("test1")) .AddOutbound <IIntegrationEvent>(new TestProducerEndpoint("test2")))); var broker = serviceProvider.GetRequiredService <TestBroker>(); await broker.ConnectAsync(); var publisher = serviceProvider.GetRequiredService <IPublisher>(); // -> to both endpoints await publisher.PublishAsync(new TestEventOne()); await publisher.PublishAsync(new TestEventOne()); // -> to test2 await publisher.PublishAsync(new TestEventTwo()); await publisher.PublishAsync(new TestEventTwo()); await publisher.PublishAsync(new TestEventTwo()); // -> to nowhere await publisher.PublishAsync(new TestInternalEventOne()); broker.ProducedMessages.Should().HaveCount(7); broker.ProducedMessages.Count(x => x.Endpoint.Name == "test1").Should().Be(2); broker.ProducedMessages.Count(x => x.Endpoint.Name == "test2").Should().Be(5); }
public void AddDelegateSubscriber_FuncReturningTask_MatchingMessagesReceived() { int received = 0; Task Receive(TestEventOne message) { received++; return(Task.CompletedTask); } var serviceProvider = ServiceProviderHelper.GetServiceProvider( services => services .AddFakeLogger() .AddSilverback() .AddDelegateSubscriber((Func <TestEventOne, Task>)Receive)); var publisher = serviceProvider.GetRequiredService <IPublisher>(); publisher.Publish(new TestEventOne()); publisher.Publish(new TestEventTwo()); publisher.Publish(new TestEventOne()); received.Should().Be(2); }
public void SetSite() { // Create the package IVsPackage package = new AnkhSvnPackage() as IVsPackage; Assert.IsNotNull(package, "The object does not implement IVsPackage"); var statusCache = new Mock <ISvnStatusCache>(); var regEditors = new Mock <SVsRegisterEditors>().As <IVsRegisterEditors>(); var vsShell = new Mock <SVsShell>().As <IVsShell>(); object r = @"SOFTWARE\Microsoft\VisualStudio\8.0"; vsShell.Setup(x => x.GetProperty((int)__VSSPROPID.VSSPROPID_VirtualRegistryRoot, out r)).Returns(VSErr.S_OK); var vsTextMgr = new Mock <SVsTextManager>().As <IVsTextManager>(); var monitorSelection = new Mock <IVsMonitorSelection>(); var olMgr = new Mock <SOleComponentManager>().As <IOleComponentManager>(); var outputWindow = new Mock <SVsOutputWindow>().As <IVsOutputWindow>(); using (ServiceProviderHelper.AddService(typeof(SVsOutputWindow), outputWindow.Object)) using (ServiceProviderHelper.AddService(typeof(SOleComponentManager), olMgr.Object)) using (ServiceProviderHelper.AddService(typeof(IVsMonitorSelection), monitorSelection.Object)) using (ServiceProviderHelper.AddService(typeof(SVsTextManager), vsTextMgr.Object)) using (ServiceProviderHelper.AddService(typeof(SVsShell), vsShell.Object)) using (ServiceProviderHelper.AddService(typeof(SVsRegisterEditors), regEditors.Object)) using (ServiceProviderHelper.AddService(typeof(ISvnStatusCache), statusCache.Object)) using (ServiceProviderHelper.SetSite(package)) { // Unsite the package Assert.AreEqual(0, package.SetSite(null), "SetSite(null) did not return S_OK"); } }
public async Task CheckHealthAsync_ConsumerWithFriendlyName_FriendlyNameAddedToDescription() { var statusInfo = Substitute.For <IConsumerStatusInfo>(); statusInfo.Status.Returns(ConsumerStatus.Connected); var consumer = Substitute.For <IConsumer>(); consumer.StatusInfo.Returns(statusInfo); consumer.Id.Returns(new InstanceIdentifier(Guid.Empty)); consumer.Endpoint.Returns(new TestConsumerEndpoint("topic1") { FriendlyName = "friendly-one" }); var broker = Substitute.For <IBroker>(); broker.ProducerEndpointType.Returns(typeof(TestProducerEndpoint)); broker.ConsumerEndpointType.Returns(typeof(TestConsumerEndpoint)); broker.Consumers.Returns(new[] { consumer }); var serviceProvider = ServiceProviderHelper.GetServiceProvider( services => services .AddSilverback() .Services .AddSingleton <IBrokerCollection>(new BrokerCollection(new[] { broker })) .AddHealthChecks() .AddConsumersCheck()); var(healthCheck, context) = GetHealthCheck(serviceProvider); var result = await healthCheck.CheckHealthAsync(context); result.Status.Should().Be(HealthStatus.Unhealthy); result.Description.Should().Be( $"One or more consumers are not connected:{Environment.NewLine}" + "- friendly-one (topic1) [00000000-0000-0000-0000-000000000000]"); }
public async Task AddInbound_WithMessageTypeParameter_TypedDefaultSerializerSet() { var serviceProvider = ServiceProviderHelper.GetServiceProvider( services => services .AddFakeLogger() .AddSilverback() .WithConnectionToMessageBroker(broker => broker.AddMqtt()) .AddMqttEndpoints( endpoints => endpoints .Configure( config => config .WithClientId("test") .ConnectViaTcp("mqtt-broker")) .AddInbound( typeof(TestEventOne), endpoint => endpoint .ConsumeFrom("test")))); var broker = serviceProvider.GetRequiredService <MqttBroker>(); await broker.ConnectAsync(); broker.Consumers[0].Endpoint.Serializer.Should().BeOfType <JsonMessageSerializer <TestEventOne> >(); }
public void SetUp() { // Create the package package = new AnkhSvnPackage(); var statusCache = new Mock <ISvnStatusCache>(); var regEditors = new Mock <SVsRegisterEditors>().As <IVsRegisterEditors>(); var vsShell = new Mock <SVsShell>().As <IVsShell>(); object r = @"SOFTWARE\Microsoft\VisualStudio\8.0"; vsShell.Setup(x => x.GetProperty((int)__VSSPROPID.VSSPROPID_VirtualRegistryRoot, out r)).Returns(VSErr.S_OK); var vsTextMgr = new Mock <SVsTextManager>().As <IVsTextManager>(); var monitorSelection = new Mock <IVsMonitorSelection>(); var olMgr = new Mock <SOleComponentManager>().As <IOleComponentManager>(); var outputWindow = new Mock <SVsOutputWindow>().As <IVsOutputWindow>(); ServiceProviderHelper.AddService(typeof(IAnkhPackage), package); ServiceProviderHelper.AddService(typeof(SVsOutputWindow), outputWindow.Object); ServiceProviderHelper.AddService(typeof(SOleComponentManager), olMgr.Object); ServiceProviderHelper.AddService(typeof(IVsMonitorSelection), monitorSelection.Object); ServiceProviderHelper.AddService(typeof(SVsTextManager), vsTextMgr.Object); ServiceProviderHelper.AddService(typeof(SVsShell), vsShell.Object); ServiceProviderHelper.AddService(typeof(SVsRegisterEditors), regEditors.Object); ServiceProviderHelper.AddService(typeof(ISvnStatusCache), statusCache.Object); var uiService = new Mock <IUIService>(); uiService.Setup(x => x.ShowDialog(It.IsAny <Form>())).Returns(DialogResult.OK); ServiceProviderHelper.AddService(typeof(IUIService), uiService.Object); }
public async Task StartAsync_ConnectAtStartup_BrokersConnected() { var serviceProvider = ServiceProviderHelper.GetServiceProvider( services => services .AddTransient(_ => Substitute.For <IHostApplicationLifetime>()) .AddFakeLogger() .AddSilverback() .WithConnectionToMessageBroker( options => options .AddBroker <TestBroker>() .AddBroker <TestOtherBroker>() .WithConnectionOptions( new BrokerConnectionOptions { Mode = BrokerConnectionMode.Startup }))); var service = serviceProvider.GetServices <IHostedService>().OfType <BrokerConnectorService>().Single(); await service.StartAsync(CancellationToken.None); var brokers = serviceProvider.GetRequiredService <IBrokerCollection>(); brokers.ForEach(broker => broker.IsConnected.Should().BeTrue()); }
// ReSharper disable once MemberCanBePrivate.Global public WakaTime(IServiceProvider serviceProvider, Configuration configuration) { _configuration = configuration; Config = new ConfigFile(); Config.Read(); _pythonCliParameters = new PythonCliParameters(); _dependencies = new Dependencies(); if (string.IsNullOrEmpty(_configuration.PluginVersion)) { _configuration.PluginVersion = Constants.PluginVersion; } if (Logger == null) { Logger = new Logger(); } if (serviceProvider != null) { IsAsyncLoadSupported = ServiceProviderHelper.IsAsyncPackageSupported(serviceProvider); } }
public async Task AddSubscribers_Interface_MessagesReceived() { var testService1 = new TestServiceOne(); var testService2 = new TestServiceTwo(); var serviceProvider = ServiceProviderHelper.GetServiceProvider( services => services .AddFakeLogger() .AddSilverback() .AddSubscribers <IService>() .Services .AddSingleton <IService>(testService1) .AddSingleton(testService1) .AddSingleton <IService>(testService2) .AddSingleton(testService2)); var publisher = serviceProvider.GetRequiredService <IPublisher>(); publisher.Publish(new TestCommandOne()); await publisher.PublishAsync(new TestCommandTwo()); testService1.ReceivedMessagesCount.Should().BeGreaterThan(0); testService2.ReceivedMessagesCount.Should().BeGreaterThan(0); }
public OutboxWorkerTests() { var serviceProvider = ServiceProviderHelper.GetServiceProvider( services => services .AddSilverback() .WithConnectionToMessageBroker( options => options .AddBroker <TestBroker>() .AddOutbox <InMemoryOutbox>() .AddOutboxWorker()) .AddEndpoints( endpoints => endpoints .AddOutbound <TestEventOne>(new TestProducerEndpoint("topic1")) .AddOutbound <TestEventTwo>(new TestProducerEndpoint("topic2")) .AddOutbound <TestEventThree>(new TestProducerEndpoint("topic3a")) .AddOutbound <TestEventThree>(new TestProducerEndpoint("topic3b")))); _broker = serviceProvider.GetRequiredService <TestBroker>(); _broker.ConnectAsync().Wait(); _worker = serviceProvider.GetRequiredService <IOutboxWorker>(); _outboxWriter = serviceProvider.GetRequiredService <IOutboxWriter>(); _sampleOutboundEnvelope = new OutboundEnvelope <TestEventOne>( new TestEventOne { Content = "Test" }, null, new TestProducerEndpoint("topic1")); _sampleOutboundEnvelope.RawMessage = AsyncHelper.RunSynchronously( () => new JsonMessageSerializer().SerializeAsync( _sampleOutboundEnvelope.Message, _sampleOutboundEnvelope.Headers, MessageSerializationContext.Empty)); }
public IntegrationLoggingBenchmark() { var serviceProvider = ServiceProviderHelper.GetServiceProvider( services => services .AddFakeLogger() .AddSilverback() .WithConnectionToMessageBroker(broker => broker.AddKafka())); _inboundLogger = serviceProvider.GetRequiredService <IInboundLogger <IntegrationLoggingBenchmark> >(); _outboundLogger = serviceProvider.GetRequiredService <IOutboundLogger <IntegrationLoggingBenchmark> >(); _inboundEnvelope = new RawInboundEnvelope( Array.Empty <byte>(), new MessageHeaderCollection { new("Test", "Test"), new(DefaultMessageHeaders.FailedAttempts, "1"), new(DefaultMessageHeaders.MessageType, "Something.Xy"), new(DefaultMessageHeaders.MessageId, "1234"), new(KafkaMessageHeaders.KafkaMessageKey, "key1234") },
public async Task Publish_ToNonExclusiveDelegateSubscribers_InvokedInParallel() { var parallel = new ParallelTestingUtil(); var serviceProvider = ServiceProviderHelper.GetServiceProvider( services => services .AddFakeLogger() .AddSilverback() .AddDelegateSubscriber( (ICommand _) => parallel.DoWork(), new SubscriptionOptions { Exclusive = false }) .AddDelegateSubscriber( (ICommand _) => parallel.DoWorkAsync(), new SubscriptionOptions { Exclusive = false })); var publisher = serviceProvider.GetRequiredService <IPublisher>(); publisher.Publish(new TestCommandOne()); await publisher.PublishAsync(new TestCommandOne()); parallel.Steps.Should().BeEquivalentTo(1, 1, 3, 3); }
public async Task AddInbound_WithMultipleBrokers_ConsumersCorrectlyConnected() { var serviceProvider = ServiceProviderHelper.GetServiceProvider( services => services .AddSilverback() .WithConnectionToMessageBroker( options => options .AddBroker <TestBroker>() .AddBroker <TestOtherBroker>()) .AddEndpoints( endpoints => endpoints .AddInbound(new TestConsumerEndpoint("test1")) .AddInbound(new TestOtherConsumerEndpoint("test2")))); var broker = serviceProvider.GetRequiredService <TestBroker>(); await broker.ConnectAsync(); var otherBroker = serviceProvider.GetRequiredService <TestOtherBroker>(); await otherBroker.ConnectAsync(); broker.Consumers.Should().HaveCount(1); otherBroker.Consumers.Should().HaveCount(1); }
void IPexExplorationPackage.Initialize(IPexExplorationEngine host) { //This is required to invoke the initialize() method of InsufficientObjectFactoryObserver var observer = ServiceProviderHelper.GetService <InsufficientObjectFactoryObserver>(host); }
public void Setup() { Services = ServiceProviderHelper.GetServices(); }
public ActionResult UploadExcel(HttpPostedFileBase FileUpload) { ServiceProviderHelper serviceProviderHelper = new ServiceProviderHelper(); string viewName = ""; try { if (FileUpload != null) { if (FileUpload.ContentType == "application/vnd.ms-excel" || FileUpload.ContentType == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { string filename = Path.GetFileName(FileUpload.FileName); if (filename.EndsWith(".xlsx") || filename.EndsWith(".xls")) { string targetpath = Server.MapPath("~/UploadExcel/"); FileUpload.SaveAs(targetpath + filename); string pathToExcelFile = targetpath + filename; var excelFile = new ExcelQueryFactory(pathToExcelFile);// var providerList = from provider in excelFile.Worksheet <ServiceProviderEntity>("ProviderList") select provider; var issueList = from issue in excelFile.Worksheet <IssuesEntity>("IssueList") select issue; //ValidateExcelFile(); List <ServiceProviderEntity> serviceProviderEntityList = new List <ServiceProviderEntity>(); foreach (var provider in providerList) { if (provider.Name != null) { ServiceProviderEntity serviceProviderEntity = new ServiceProviderEntity(); serviceProviderEntity.VendorCode = provider.VendorCode; serviceProviderEntity.Name = provider.Name; serviceProviderEntity.Status = provider.Status; serviceProviderEntity.GoLiveDate = provider.GoLiveDate; serviceProviderEntity.ProjectManager = provider.ProjectManager; serviceProviderEntity.Phase = provider.Phase; serviceProviderEntity.Fees = provider.Fees; serviceProviderEntity.Type = provider.Type; serviceProviderEntity.Update = provider.Update; //serviceProviderEntity.IssuesList = issueList == null ? null : new List<IssuesEntity>() { new IssuesEntity() { Item = issueList.Where(x => x.ServiceProviderCode == provider.ServiceProviderCode).Select(y => y.Item).FirstOrDefault(), Issue = issueList.Where(x => x.ServiceProviderCode == provider.ServiceProviderCode).Select(y => y.Issue).FirstOrDefault(), Owner = issueList.Where(x => x.ServiceProviderCode == provider.ServiceProviderCode).Select(y => y.Owner).FirstOrDefault() } }; List <IssuesEntity> IssuesEntityList = new List <IssuesEntity>(); foreach (var issue in issueList.Where(i => i.VendorCode == provider.VendorCode)) { if (issue.Issue != null) { IssuesEntity issuesEntity = new IssuesEntity(); issuesEntity.VendorCode = issue.VendorCode; issuesEntity.Item = issue.Item; issuesEntity.Issue = issue.Issue; issuesEntity.Owner = issue.Owner; IssuesEntityList.Add(issuesEntity); } } if (IssuesEntityList.Count > 0) { serviceProviderEntity.IssuesList = IssuesEntityList; } serviceProviderEntityList.Add(serviceProviderEntity); } } if (serviceProviderEntityList.Count > 0) { serviceProviderHelper.AddProvider(serviceProviderEntityList); EmailSetting emailSetting = new EmailSetting(); string Body = System.IO.File.ReadAllText(System.Web.Hosting.HostingEnvironment.MapPath("~/EmailTemplates/ExcelUploadMail.html")); bool isMailSend = emailSetting.SendMail(Convert.ToString(Session["EmailID"]), "", "Provider Details Upload Notification", Body.Replace("currDate", DateTime.Now.ToString("MMMM dd, yyyy"))); viewName = "uploadconfirmation"; } } else { TempData["Message"] = "Only Excel file format is allowed"; viewName = "AdminDashboard"; } } else { TempData["Message"] = "Only Excel file format is allowed"; viewName = "AdminDashboard"; } } else { TempData["Message"] = "Please select file."; viewName = "AdminDashboard"; } } catch (Exception ex) { TempData["Message"] = "some issue occured. please try again"; viewName = "AdminDashboard"; } return(RedirectToAction(viewName)); }
public void Cleanup() { ServiceProviderHelper.DisposeServices(); }
public void TearDown() { ServiceProviderHelper.DisposeServices(); }
public void Setup() { Services = ServiceProviderHelper.GetWorkItemMigrationProcessor(); }
public static IApplicationBuilder UseStaticServiceProvider(this IApplicationBuilder app) { ServiceProviderHelper.Configure(app.ApplicationServices); return(app); }
public async Task PublishAsync_MultipleSubscriberClasses_OnlyNeededTypesResolved() { var resolved = 0; var serviceProvider = ServiceProviderHelper.GetServiceProvider( builder => builder .AddFakeLogger() .AddSilverback() .AddScopedSubscriber( _ => { resolved++; return(new TestServiceOne()); }) .AddScopedSubscriber( _ => { resolved++; return(new TestServiceTwo()); })); await serviceProvider.GetServices <IHostedService>() .OfType <SubscribedMethodsLoaderService>() .Single() .StartAsync(CancellationToken.None); resolved.Should().Be(2); // Publish single message resolved = 0; using (var scope = serviceProvider.CreateScope()) { await scope.ServiceProvider.GetRequiredService <IPublisher>() .PublishAsync(new TestCommandOne()); } resolved.Should().Be(1); // Publish enumerable of messages resolved = 0; using (var scope = serviceProvider.CreateScope()) { await scope.ServiceProvider.GetRequiredService <IPublisher>() .PublishAsync(new TestCommandOne()); } resolved.Should().Be(1); // Publish stream resolved = 0; using (var scope = serviceProvider.CreateScope()) { await scope.ServiceProvider.GetRequiredService <IPublisher>() .PublishAsync(new MessageStreamProvider <TestCommandOne>()); } resolved.Should().Be(0); }
public async Task PublishAsync_MultipleSubscriberClasses_OnlyNeededTypesResolvedAfterFirstPublish() { var resolved = 0; var serviceProvider = ServiceProviderHelper.GetServiceProvider( builder => builder .AddFakeLogger() .AddSilverback() .AddScopedSubscriber( _ => { resolved++; return(new TestServiceOne()); }) .AddScopedSubscriber( _ => { resolved++; return(new TestServiceTwo()); })); using (var scope = serviceProvider.CreateScope()) { await scope.ServiceProvider.GetRequiredService <IPublisher>() .PublishAsync(new TestCommandOne()); } resolved.Should().Be(2); // Publish single message resolved = 0; using (var scope = serviceProvider.CreateScope()) { await scope.ServiceProvider.GetRequiredService <IPublisher>() .PublishAsync(new TestCommandOne()); } resolved.Should().Be(1); // Publish enumerable of messages resolved = 0; using (var scope = serviceProvider.CreateScope()) { await scope.ServiceProvider.GetRequiredService <IPublisher>() .PublishAsync(new TestCommandOne()); } resolved.Should().Be(1); // Publish stream resolved = 0; using (var scope = serviceProvider.CreateScope()) { await scope.ServiceProvider.GetRequiredService <IPublisher>() .PublishAsync(new[] { new MessageStreamProvider <TestCommandOne>() }); } resolved.Should().Be(0); }
public static IServiceProvider UseStaticServiceProvider(this IServiceProvider serviceProvider) { ServiceProviderHelper.Configure(serviceProvider); return(serviceProvider); }
public CategoriesController() { _categoryService = ServiceProviderHelper.GetService <ICategoryService>(); }
public static ServiceProvider UseStartupAndBuild <TStartup>(this ServiceProviderServiceBuilder serviceProviderServiceBuilder) where TStartup : class, IStartup { var serviceProvider = serviceProviderServiceBuilder.UseStartupAndBuild <TStartup>(ServiceProviderHelper.GetNewEmptyServiceProvider()); return(serviceProvider); }
void IPexExplorationPackage.Initialize( IPexExplorationEngine host) { var observer = ServiceProviderHelper.GetService <InsufficientObjectFactoryObserver>(host); }