public void Should_map_sucessfully()
        {
            string hostname = "hostname";
            var clientName = "someClient";
            var freq = 100;
            var configMapper = new ConfigMapper(hostname, this.stop, this.dataClientFactory, this.graphiteClientFactory, this.log, configRepository);
            var taskSets = new List<TaskSet>();
            var taskSet = new TaskSet { Frequency = freq, Tasks = new List<Task>() };
            string name = new Guid().ToString();
            Job job = new WmiClient();
            job.ClientName = clientName;

            configRepository.Expect(y => y.GetJob(name)).Return(job);
            configRepository.Expect(y => y.GetClient(clientName)).Return(new GraphiteTcpClient());

            taskSet.Tasks.Add(new Task() { JobName = name });
            taskSets.Add(taskSet);
            //Test
            var taskList = configMapper.Map(taskSets);
            //Assert
            Assert.That(taskList.Count, Is.EqualTo(1));
            Assert.That(taskList[0].Frequency, Is.EqualTo(freq));
            Assert.That(taskList[0].Tasks.Count, Is.EqualTo(1));
            Assert.That(taskList[0].Tasks[0].GetType(), Is.EqualTo(typeof(RunableRunTask)));
            configRepository.VerifyAllExpectations();
        }
 public void Should_map_sucessfully()
 {
     string hostname = "hostname";
     var client = "someClient";
     var freq = 100;
     var configMapper = new ConfigMapper(hostname, stop, dataClientFactory, graphiteClientFactory, log);
     var taskSet = new List<SqlToGraphiteConfigTemplatesWorkItemsTaskSet>();
     var x = new SqlToGraphiteConfigTemplatesWorkItemsTaskSet { frequency = freq.ToString(), Task = new SqlToGraphiteConfigTemplatesWorkItemsTaskSetTask[1] };
     x.Task[0] = new SqlToGraphiteConfigTemplatesWorkItemsTaskSetTask
     {
         client = client,
         connectionstring = "cs",
         name = "name",
         path = "path",
         port = "1234",
         sql = "sql",
         type = "type"
     };
     taskSet.Add(x);
     var clients = new GraphiteClients();
     clients.Add(client, "1234");
     var taskList  = configMapper.Map(taskSet, clients);
     Assert.That(taskList.Count, Is.EqualTo(1));
     Assert.That(taskList[0].Frequency, Is.EqualTo(freq));
     Assert.That(taskList[0].Tasks.Count, Is.EqualTo(1));
     Assert.That(taskList[0].Tasks[0].GetType(), Is.EqualTo(typeof(Task)));
 }
Exemplo n.º 3
0
        /// <summary>
        /// Registers all the necessary components to use the low level HareDu Broker, Diagnostic, and Snapshotting APIs.
        /// </summary>
        /// <param name="services"></param>
        /// <param name="settingsFile">The full path of where the configuration settings file is located.</param>
        /// <param name="configSection">The section found within the configuration file.</param>
        /// <returns></returns>
        public static IServiceCollection AddHareDu(this IServiceCollection services, string settingsFile, string configSection)
        {
            var internalConfig = new InternalHareDuConfig();

            IConfiguration configuration = new ConfigurationBuilder()
                                           .AddJsonFile(settingsFile, false)
                                           .Build();

            configuration.Bind(configSection, internalConfig);

            HareDuConfig config = ConfigMapper.Map(internalConfig);

            services.AddSingleton(config);
            services.AddSingleton <IBrokerObjectFactory, BrokerObjectFactory>();
            services.AddSingleton <IScanner, Scanner>();
            services.AddSingleton <IKnowledgeBaseProvider, KnowledgeBaseProvider>();
            services.AddSingleton <IScannerFactory, ScannerFactory>();
            services.AddSingleton <IScannerResultAnalyzer, ScannerResultAnalyzer>();
            services.AddSingleton <ISnapshotFactory>(x => new SnapshotFactory(x.GetService <IBrokerObjectFactory>()));
            services.AddSingleton <ISnapshotWriter, SnapshotWriter>();
            services.AddSingleton <IDiagnosticReportFormatter, DiagnosticReportTextFormatter>();
            services.AddSingleton <IDiagnosticWriter, DiagnosticWriter>();

            return(services);
        }
Exemplo n.º 4
0
        public override ResponseBase ExecuteRequest()
        {
            CustomerDTO         CustomerDTO    = new CustomerDTO();
            AddCustomerResponse responseObject = new AddCustomerResponse();

            try
            {
                Customer CUSTOMER = new Customer();

                using (CustomerDemoEntities ctx = new CustomerDemoEntities())
                {
                    var _customer = ctx.Customers.Where(c => c.Name == customer.Name).FirstOrDefault();
                    if (_customer == null)
                    {
                        if (customer.PhoneNumbers.Count > 0)
                        {
                            List <PhoneNumber> phoneNumbers = new List <PhoneNumber>();
                            for (int i = 0; i < customer.PhoneNumbers.Count; i++)
                            {
                                PhoneNumber phoneNumber = new PhoneNumber();
                                phoneNumber.Number = customer.PhoneNumbers[i].Number;
                                phoneNumbers.Add(phoneNumber);
                                ctx.PhoneNumbers.Add(phoneNumber);
                            }
                            CUSTOMER.PhoneNumbers = phoneNumbers;
                        }
                        CUSTOMER.Name      = customer.Name;
                        CUSTOMER.BirthDate = customer.BirthDate;
                        CUSTOMER.Gender    = customer.Gender;
                        CUSTOMER.Email     = customer.Email;
                        CUSTOMER.Address   = customer.Address;
                        CUSTOMER.Notes     = customer.Notes;

                        ctx.Customers.Add(CUSTOMER);
                        ctx.SaveChanges();

                        customer.ID = CUSTOMER.ID;
                        CustomerDTO = ConfigMapper.Map <Customer, CustomerDTO>(CUSTOMER);

                        responseObject.Message   = "Customer Added Successufully";
                        responseObject.IsSuccess = true;
                        responseObject.customer  = CustomerDTO;
                    }
                    else
                    {
                        responseObject.IsSuccess = false;
                        responseObject.Message   = "Customer already exist";
                    }
                }
            }
            catch (Exception e)
            {
                responseObject.IsSuccess = false;
                responseObject.Message   = e.Message;
            }

            return(responseObject);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Registers all the necessary components to use the low level HareDu Broker, Diagnostic, and Snapshotting APIs.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="settingsFile">The full path of where the configuration settings file is located.</param>
        /// <param name="configSection">The section found within the configuration file.</param>
        /// <returns></returns>
        public static ContainerBuilder AddHareDu(this ContainerBuilder builder, string settingsFile, string configSection)
        {
            builder.Register(x =>
            {
                var internalConfig = new InternalHareDuConfig();

                IConfiguration configuration = new ConfigurationBuilder()
                                               .AddJsonFile(settingsFile, false)
                                               .Build();

                configuration.Bind(configSection, internalConfig);

                HareDuConfig config = ConfigMapper.Map(internalConfig);

                return(config);
            })
            .SingleInstance();

            builder.RegisterType <BrokerObjectFactory>()
            .As <IBrokerObjectFactory>()
            .SingleInstance();

            builder.RegisterType <Scanner>()
            .As <IScanner>()
            .SingleInstance();

            builder.RegisterType <KnowledgeBaseProvider>()
            .As <IKnowledgeBaseProvider>()
            .SingleInstance();

            builder.RegisterType <ScannerFactory>()
            .As <IScannerFactory>()
            .SingleInstance();

            builder.RegisterType <ScannerResultAnalyzer>()
            .As <IScannerResultAnalyzer>()
            .SingleInstance();

            builder.RegisterType <SnapshotWriter>()
            .As <ISnapshotWriter>()
            .SingleInstance();

            builder.RegisterType <DiagnosticReportTextFormatter>()
            .As <IDiagnosticReportFormatter>()
            .SingleInstance();

            builder.RegisterType <DiagnosticWriter>()
            .As <IDiagnosticWriter>()
            .SingleInstance();

            builder.Register(x => new SnapshotFactory(x.Resolve <IBrokerObjectFactory>()))
            .As <ISnapshotFactory>()
            .SingleInstance();

            return(builder);
        }
Exemplo n.º 6
0
        public void Map_Simple_PrivateProperty_Exception()
        {
            var value        = "some value";
            var configMapper = new ConfigMapper <ClassSimple>();

            var path = new List <string>
            {
                "ClassName",
                "PropStringPrivate",
            };

            Assert.Throws <NullReferenceException>(() => configMapper.Map(path, value));
        }
Exemplo n.º 7
0
        public void Map_Simple_WrongTypeProperty_Exception()
        {
            var fakeValue    = 10;
            var configMapper = new ConfigMapper <ClassSimple>();

            var path = new List <string>
            {
                "ClassName",
                "PropStringPublic",
            };

            Assert.Throws <DataException>(() => configMapper.Map(path, fakeValue));
        }
Exemplo n.º 8
0
        public void Init()
        {
            var services = new ServiceCollection();

            services.AddSingleton <IKnowledgeBaseProvider, KnowledgeBaseProvider>();

            var internalConfig = new InternalHareDuConfig();

            IConfiguration configuration = new ConfigurationBuilder()
                                           .AddJsonFile($"{TestContext.CurrentContext.TestDirectory}/appsettings.json", false)
                                           .Build();

            configuration.Bind("HareDuConfig", internalConfig);

            HareDuConfig config = ConfigMapper.Map(internalConfig);

            services.AddSingleton(config);

            _provider = services.BuildServiceProvider();

            var knowledgeBaseProvider = _provider.GetService <IKnowledgeBaseProvider>();

            _probes = new List <DiagnosticProbe>
            {
                new HighConnectionCreationRateProbe(config.Diagnostics, knowledgeBaseProvider),
                new HighConnectionClosureRateProbe(config.Diagnostics, knowledgeBaseProvider),
                new UnlimitedPrefetchCountProbe(knowledgeBaseProvider),
                new ChannelThrottlingProbe(knowledgeBaseProvider),
                new ChannelLimitReachedProbe(knowledgeBaseProvider),
                new BlockedConnectionProbe(knowledgeBaseProvider),
                new QueueGrowthProbe(knowledgeBaseProvider),
                new MessagePagingProbe(knowledgeBaseProvider),
                new RedeliveredMessagesProbe(config.Diagnostics, knowledgeBaseProvider),
                new ConsumerUtilizationProbe(config.Diagnostics, knowledgeBaseProvider),
                new UnroutableMessageProbe(knowledgeBaseProvider),
                new QueueLowFlowProbe(config.Diagnostics, knowledgeBaseProvider),
                new QueueNoFlowProbe(knowledgeBaseProvider),
                new QueueHighFlowProbe(config.Diagnostics, knowledgeBaseProvider),
                new RuntimeProcessLimitProbe(config.Diagnostics, knowledgeBaseProvider),
                new SocketDescriptorThrottlingProbe(config.Diagnostics, knowledgeBaseProvider),
                new NetworkPartitionProbe(knowledgeBaseProvider),
                new MemoryAlarmProbe(knowledgeBaseProvider),
                new DiskAlarmProbe(knowledgeBaseProvider),
                new AvailableCpuCoresProbe(knowledgeBaseProvider),
                new FileDescriptorThrottlingProbe(config.Diagnostics, knowledgeBaseProvider)
            };
        }
Exemplo n.º 9
0
 public IActionResult post(ItemDTO model)
 {
     try
     {
         using (var db = new StepperTaskDBContext())
         {
             Items item = ConfigMapper.Map <ItemDTO, Items>(model);
             db.Items.Add(item);
             db.SaveChanges();
             return(Ok(item));
         }
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
Exemplo n.º 10
0
        public void Init()
        {
            var services = new ServiceCollection();

            services.AddSingleton <IKnowledgeBaseProvider, KnowledgeBaseProvider>();

            var internalConfig = new InternalHareDuConfig();

            IConfiguration configuration = new ConfigurationBuilder()
                                           .AddJsonFile($"{TestContext.CurrentContext.TestDirectory}/appsettings.json", false)
                                           .Build();

            configuration.Bind("HareDuConfig", internalConfig);

            HareDuConfig config = ConfigMapper.Map(internalConfig);

            services.AddSingleton(config);

            _provider = services.BuildServiceProvider();
        }
 public void Should_throw_exception_if_graphite_client_is_unknown()
 {
     string hostname = "hostname";
     var configMapper = new ConfigMapper(hostname, stop, dataClientFactory, graphiteClientFactory, log);
     var taskSet = new List<SqlToGraphiteConfigTemplatesWorkItemsTaskSet>();
     var x = new SqlToGraphiteConfigTemplatesWorkItemsTaskSet { frequency = "100", Task = new SqlToGraphiteConfigTemplatesWorkItemsTaskSetTask[1] };
     x.Task[0] = new SqlToGraphiteConfigTemplatesWorkItemsTaskSetTask
         {
             client = "client",
             connectionstring = "cs",
             name = "name",
             path = "path",
             port = "1234",
             sql = "sql",
             type = "typr"
         };
     taskSet.Add(x);
     var clients = new GraphiteClients();
     var ex = Assert.Throws<ClientNotFoundException>(() => configMapper.Map(taskSet, clients));
     Assert.That(ex.Message, Is.EqualTo("Client client is not known add this into the conifiguration xml"));
 }
Exemplo n.º 12
0
        public void Map_Simple_SuccessMap()
        {
            var value        = "some value";
            var configMapper = new ConfigMapper <ClassSimple>();

            var path = new List <string>
            {
                "ClassName",
                "PropStringPublic",
            };

            configMapper.Map(path, value);

            var expected = new ClassSimple()
            {
                PropStringPublic = value
            };

            var result = configMapper.GetResultObject();

            result.Should().BeEquivalentTo(expected);
        }
Exemplo n.º 13
0
 private static void RegisterServices(IKernel kernel)
 {
     kernel.Bind <IGuidGenerator>().ToMethod(context => new GuidGenerator(HttpContext.Current.Server.MapPath("~/words.txt"))).InSingletonScope();
     kernel.Bind <IAppSettings>().ToMethod(context => ConfigMapper.Map <IAppSettings>());
 }
        public void Should_throw_exception_if_graphite_client_is_unknown()
        {
            string clientName = "notKnown";
            string jobName = "someJob";
            var job = new WmiClient();
            var msg = "some exception message";
            job.ClientName = clientName;
            job.Name = jobName;
            configRepository.Expect(x => x.GetClient(clientName)).Throw(new ClientNotFoundException(msg));
            configRepository.Expect(x => x.GetJob(jobName)).Return(job);
            string hostname = "hostname";
            var configMapper = new ConfigMapper(hostname, this.stop, this.dataClientFactory, this.graphiteClientFactory, this.log, configRepository);
            var taskSets = new List<TaskSet>();
            var taskSet = new TaskSet { Frequency = 100, Tasks = new List<Task>() };
            var t = new Task { JobName = jobName };

            taskSet.Tasks.Add(t);

            taskSets.Add(taskSet);
            //Test
            var ex = Assert.Throws<ClientNotFoundException>(() => configMapper.Map(taskSets));
            //Assert
            Assert.That(ex.Message, Is.EqualTo(msg));
        }
Exemplo n.º 15
0
        public void Map_Nested_SuccessMap()
        {
            var valueString = "some string value";
            var valueInt    = 10;
            var valueDouble = 1.4;
            var valueLong   = -15;
            var valueBool   = true;

            var configMapper = new ConfigMapper <ClassDoubleNested>();

            configMapper.Map(new List <string> {
                "ClassDoubleNested", "PropInt"
            }, valueInt);
            configMapper.Map(new List <string> {
                "ClassDoubleNested", "PropString"
            }, valueString);
            configMapper.Map(new List <string> {
                "ClassDoubleNested", "PropClassNested1", "PropDouble"
            }, valueDouble);
            configMapper.Map(new List <string> {
                "ClassDoubleNested", "PropClassNested1", "PropLong"
            }, valueLong);
            configMapper.Map(new List <string> {
                "ClassDoubleNested", "PropClassNested1", "PropClass", "PropBool"
            }, valueBool);
            configMapper.Map(new List <string> {
                "ClassDoubleNested", "PropClassNested2", "PropDouble"
            }, valueDouble);
            configMapper.Map(new List <string> {
                "ClassDoubleNested", "PropClassNested2", "PropLong"
            }, valueLong);
            configMapper.Map(new List <string> {
                "ClassDoubleNested", "PropClassNested2", "PropClass", "PropBool"
            }, valueBool);

            var expected = new ClassDoubleNested()
            {
                PropInt          = valueInt,
                PropString       = valueString,
                PropClassNested1 = new ClassNested()
                {
                    PropDouble = valueDouble,
                    PropLong   = valueLong,
                    PropClass  = new Class()
                    {
                        PropBool = valueBool
                    }
                },
                PropClassNested2 = new ClassNested()
                {
                    PropDouble = valueDouble,
                    PropLong   = valueLong,
                    PropClass  = new Class()
                    {
                        PropBool = valueBool
                    }
                }
            };

            var result = configMapper.GetResultObject();

            result.Should().BeEquivalentTo(expected);
        }