public void SampleTransformer_Transform_Success() { var readerId = "2"; var transformer = ComponentRegistration.CreateInstance <ITransformer>(TYPE_SAMPLE_TRANSFORMER); var config = ConfigurationTests.CreateTransformerConfig("4", ConfigurationTests.CreateMapperConfig("3", "4"), readerId); var handler = new MockTransformationHandler(); transformer.Configure(config, handler); var dataPoint = new KeyValuePair <string, object>("ABC", "Some Value"); var dataRow = new EntityCollection(); dataRow.Entities.Add(dataPoint.Key, dataPoint.Value); var data = new List <IEntityCollection>(); data.Add(dataRow); transformer.HandleData(readerId, data, new Dictionary <string, string>()).Wait(); handler.Invoked.Should().BeTrue(); handler.SenderId.Should().Equals(readerId); handler.Data.Count.Should().Equals(1); foreach (var row in handler.Data) { row.GetType().Should().Be(typeof(MockEntity)); } }
public void when_publish_with_invalid_arguments_it_should_fail() { var apiProducerMock = new Mock <IApiProducer>(); apiProducerMock .Setup(producer => producer.Publish(It.IsAny <MessagePublishingContext>(), It.IsAny <CancellationToken>())) .Returns(() => Task.CompletedTask); var producerRegistryMock = new Mock <IProducerRegistry>(); producerRegistryMock.Setup(registry => registry.Get(It.IsAny <IEgressApi>())).Returns(() => apiProducerMock.Object); var driver = new BrokerEgressKafkaDriver( ConfigurationTests.CreateBrokerEgressKafkaDriverConfiguration(new List <MessagePublishingContext>()), producerRegistryMock.Object); driver.Initialize( new[] { MakeApi() }, MakeServiceProvider()); // ReSharper disable once AssignNullToNotNullAttribute Func <Task> sut = () => driver.Publish(context: null, CancellationToken.None); sut.Should().ThrowExactly <ArgumentNullException>(); }
public async Task when_publish_using_initialized_driver_it_should_publish_to_api_publisher() { var published = 0; var apiProducerMock = new Mock <IApiProducer>(); apiProducerMock .Setup(producer => producer.Publish(It.IsAny <MessagePublishingContext>(), It.IsAny <CancellationToken>())) .Callback(() => published++) .Returns(() => Task.CompletedTask); var producerRegistryMock = new Mock <IProducerRegistry>(); producerRegistryMock.Setup(registry => registry.Get(It.IsAny <IEgressApi>())).Returns(() => apiProducerMock.Object); var driver = new BrokerEgressKafkaDriver( ConfigurationTests.CreateBrokerEgressKafkaDriverConfiguration(new List <MessagePublishingContext>()), producerRegistryMock.Object); driver.Initialize( new[] { MakeApi() }, MakeServiceProvider()); await driver.Publish(MakeContext(), CancellationToken.None); published.Should().Be(expected: 1, "message should be published"); }
public void LogPublisher_Publish_Success() { var currentDirectory = Directory.GetCurrentDirectory(); var fileName = string.Format(CultureInfo.InvariantCulture, "{0}\\test.log", currentDirectory); var outFileName = string.Format(CultureInfo.InvariantCulture, "{0}\\test.log.txt", currentDirectory); File.Delete(outFileName); var publisher = ComponentRegistration.CreateInstance <IPublisher>("Collector.SDK.Samples.Publishers.LogPublisher, Collector.SDK.Samples.Publishers"); var config = ConfigurationTests.CreateEndPointConfig("1", "FileName", fileName); config.Properties.Add(CollectorConstants.KEY_FOLDER, currentDirectory); publisher.Configure("5", config); var entity = new MockEntity(); entity.XYZ = "123"; entity.ABC = "789"; var data = new List <object>(); data.Add(entity); var context = new Dictionary <string, string>(); context.Add(CollectorConstants.KEY_FILENAME, fileName); publisher.PublishData("3", data, context).Wait(); File.Exists(outFileName).Should().BeTrue(); var text = File.ReadAllText(outFileName); text.Should().Contain("\"XYZ\":\"123\""); }
public void when_publishing_to_not_initialized_driver_it_should_fail() { var driver = new BrokerEgressKafkaDriver( ConfigurationTests.CreateBrokerEgressKafkaDriverConfiguration(), new Mock <IProducerRegistry>().Object); Func <Task> sut = () => driver.Publish(MakeContext(), CancellationToken.None); sut.Should().ThrowExactly <PoezdOperationException>() .Where( exception => exception.Message.Contains("initialized", StringComparison.InvariantCultureIgnoreCase), "not initialized driver can not publish messages"); }
public void when_some_required_property_not_set_it_should_be_not_validated() { ConfigurationTests.CreateBrokerIngressKafkaDriverConfigurationWithout(configuration => configuration.ConsumerConfig = null) .Validate().Should().HaveCount(expected: 1); ConfigurationTests.CreateBrokerIngressKafkaDriverConfigurationWithout(configuration => configuration.ConsumerConfiguratorType = null) .Validate().Should().HaveCount(expected: 1); ConfigurationTests.CreateBrokerIngressKafkaDriverConfigurationWithout(configuration => configuration.HeaderValueCodecType = null) .Validate().Should().HaveCount(expected: 1); ConfigurationTests.CreateBrokerIngressKafkaDriverConfigurationWithout(configuration => configuration.ConsumerFactoryType = null) .Validate().Should().HaveCount(expected: 1); ConfigurationTests.CreateBrokerIngressKafkaDriverConfigurationWithout(configuration => configuration.DeserializerFactoryType = null) .Validate().Should().HaveCount(expected: 1); }
public void when_initializing_twice_it_should_fail() { var publishedMessages = new List <MessagePublishingContext>(); var driver = new BrokerEgressKafkaDriver( ConfigurationTests.CreateBrokerEgressKafkaDriverConfiguration(publishedMessages), new Mock <IProducerRegistry>().Object); Action sut = () => driver.Initialize( new IEgressApi[0], MakeServiceProvider()); sut.Should().NotThrow(); sut.Should().ThrowExactly <PoezdOperationException>().Where(exception => exception.Message.Contains("already initialized")); }
private void DoTestConfiguration() { TestInProgress = true; ConfigurationTests.Clear(); SetConfigFields(); System.Threading.Tasks.Task <List <ConfigurationTest> > .Factory.StartNew(() => { var result = _config.TestConfiguration(); var testModels = new List <ConfigurationTest>(); testModels.Add(new ConfigurationTest( result.Contains(Configuration.TestConfigResult.RootDirectoryVisible), "Root directory seems to be visible by the program.", "Root directory is not visible by the program or does not exists." )); testModels.Add(new ConfigurationTest( result.Contains(Configuration.TestConfigResult.RemoteDirectoryVisible), "Remote directory seems to be visible by the program.", "Remote directory is not visible by the program or does not exists." )); testModels.Add(new ConfigurationTest( result.Contains(Configuration.TestConfigResult.WriteRights), "The program have write permission in remote directory.", "The program does not have write permission in remote directory." )); testModels.Add(new ConfigurationTest( result.Contains(Configuration.TestConfigResult.DeleteRights), "The program have delete permission in remote directory.", "The program does not have delete permission in remote directory." )); if (result.Contains(Configuration.TestConfigResult.UnknownError)) { testModels.Add(new ConfigurationTest( "An unknown error occured, please check the logs." )); } return(testModels); }) .ContinueWith(task => { Application.Current.Dispatcher.Invoke(() => { ConfigurationTests.AddRange(task.Result); ShowTestResults = true; TestInProgress = false; }); }); }
public void when_initializing_with_invalid_arguments_it_should_fail() { var publishedMessages = new List <MessagePublishingContext>(); var driver = new BrokerEgressKafkaDriver( ConfigurationTests.CreateBrokerEgressKafkaDriverConfiguration(publishedMessages), new Mock <IProducerRegistry>().Object); var apis = new IEgressApi[0]; var serviceProvider = Mock.Of <IDiContainerAdapter>(); Action sut = () => driver.Initialize( apis, serviceProvider); apis = null; sut.Should().ThrowExactly <ArgumentNullException>() .Which.ParamName.Should().Be("apis", "null is an invalid APIs"); apis = new IEgressApi[0]; serviceProvider = null; sut.Should().ThrowExactly <ArgumentNullException>() .Which.ParamName.Should().Be("serviceProvider", "null is an invalid service provider"); }
public void LogPublisher_Publish_Success() { var currentDirectory = Directory.GetCurrentDirectory(); //var outFileName = string.Format(CultureInfo.InvariantCulture, "{0}\\publisher-log.txt", currentDirectory); var outFileName = string.Format("{0}\\publisher-log-{1}{2}{3}{4}{5}.txt", currentDirectory, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Year, DateTime.Now.Hour, DateTime.Now.Minute); var publisher = ComponentRegistration.CreateInstance <IPublisher>("Collector.SDK.Samples.Publishers.LogPublisher, Core.Collector.SDK.Samples"); var config = ConfigurationTests.CreateEndPointConfig("1", CollectorConstants.KEY_FOLDER, currentDirectory); publisher.Configure("5", config); var entity = new LogEntry() { DateTime = DateTime.Now, DateTimeUTC = DateTime.Now.ToUniversalTime(), Type = "INFO", Module = "SomeModuleName", Message = "Some log message" }; var data = new List <object>(); data.Add(entity); var context = new Dictionary <string, string>(); publisher.PublishData("3", data, context).Wait(); File.Exists(outFileName).Should().BeTrue(); var text = File.ReadAllText(outFileName); //text.Should().Contain("\"TYPE\":\"INFO\""); text.Should().Contain("\"Module\":\"SomeModuleName\""); text.Should().Contain("\"Message\":\"Some log message\""); }
public void when_all_required_properties_set_it_should_be_valid() { var sut = ConfigurationTests.CreateBrokerIngressKafkaDriverConfiguration(); sut.Validate().Should().BeEmpty("configured with no errors"); }