public void Should_get_taskLists_from_templates_for_default_and_hostname_not_all()
        {
            var data = new List<WorkItems>();
            var workItem1 = new WorkItems { RoleName = "default", TaskSet = new List<TaskSet>() };
            workItem1.TaskSet.Add(new TaskSet { Frequency = 123 });

            var workItem2 = new WorkItems { RoleName = "webserver", TaskSet = new List<TaskSet>() };
            workItem2.TaskSet.Add(new TaskSet { Frequency = 124 });

            var workItem3 = new WorkItems { RoleName = "sqlserver", TaskSet = new List<TaskSet>() };
            workItem3.TaskSet.Add(new TaskSet { Frequency = 125 });

            data.Add(workItem1);
            data.Add(workItem2);
            data.Add(workItem3);

            var templates = new Templates1(data);
            var roles = new List<string> { "webserver", "default" };
            //Test
            var result = templates.GetTaskSetList(roles);
            //Assert
            Assert.That(result.Count, Is.EqualTo(2));
            Assert.That(result[0].Frequency, Is.EqualTo(123));
            Assert.That(result[1].Frequency, Is.EqualTo(124));
        }
        public void Should_not_merge_taskLists_from_templates_with_the_same_freq()
        {
            var data = new List<WorkItems>();
            var workItem1 = new WorkItems { RoleName = "default", TaskSet = new List<TaskSet>() };
            var ts1 = new TaskSet
                {
                    Frequency = 123,
                    Tasks = new List<Task> { new Task() { JobName = "a" } }
                };

            workItem1.TaskSet.Add(ts1);

            var workItem2 = new WorkItems { RoleName = "webserver", TaskSet = new List<TaskSet>() };
            var ts2 = new TaskSet
            {
                Frequency = 123,
                Tasks = new List<Task> { new Task() { JobName = "b" } }
            };

            workItem2.TaskSet.Add(ts2);

            data.Add(workItem1);
            data.Add(workItem2);

            var templates = new Templates1(data);
            var roles = new List<string> { "webserver", "default" };
            //Test
            var result = templates.GetTaskSetList(roles);
            //Assert
            Assert.That(result.Count, Is.EqualTo(2));
            Assert.That(result[0].Frequency, Is.EqualTo(123));
            Assert.That(result[0].Tasks.Count, Is.EqualTo(1));
            Assert.That(result[0].Tasks[0].JobName, Is.EqualTo("a"));
            Assert.That(result[1].Frequency, Is.EqualTo(123));
            Assert.That(result[1].Tasks.Count, Is.EqualTo(1));
            Assert.That(result[1].Tasks[0].JobName, Is.EqualTo("b"));
        }
 private bool AddTaskToNewFrequency(TaskDetails taskProperties, WorkItems template)
 {
     template.TaskSet.Add(this.CreateTaskSetItem(taskProperties));
     return true;
 }
        private bool AddIfRolesAreTheSame(TaskDetails taskProperties, bool added, WorkItems template)
        {
            if (template.RoleName == taskProperties.Role)
            {
                foreach (var t in template.TaskSet)
                {
                    added = AddTaskIfFrequencyIsTheSame(taskProperties, t);
                }

                if (!added)
                {
                    added = this.AddTaskToNewFrequency(taskProperties, template);
                }
            }

            return added;
        }
 public void AddWorkItem(WorkItems workItem)
 {
     this.masterConfig.Templates[0].WorkItems.Add(workItem);
 }
        public void AddTask(TaskDetails taskProperties)
        {
            var added = false;
            foreach (var template in this.masterConfig.Templates)
            {
                foreach (var wi in template.WorkItems)
                {
                    added = this.AddIfRolesAreTheSame(taskProperties, added, wi);
                }
            }

            if (!added)
            {
                var taskSetItem = CreateTaskSetItem(taskProperties);
                if (masterConfig.Templates.Count == 0)
                {
                    masterConfig.Templates.Add(new Template());
                }

                var workItem = new WorkItems { RoleName = taskProperties.Role, TaskSet = new List<TaskSet> { taskSetItem } };
                this.masterConfig.Templates[0].WorkItems.Add(workItem);
            }
        }
 public void AddNewRole(string roleName)
 {
     var wi = new WorkItems { RoleName = roleName, TaskSet = new List<TaskSet>() };
     this.masterConfig.Templates[0].WorkItems.Add(wi);
 }
 private Template CreateSingleRoleAndJob(string jobName, int frequency, string roleName)
 {
     var ts = new TaskSet { Frequency = frequency, Tasks = new List<Task>() };
     var task = new Task { JobName = jobName };
     ts.Tasks.Add(task);
     var template = new Template();
     var wi = new WorkItems { RoleName = roleName, TaskSet = new List<TaskSet>() };
     wi.TaskSet.Add(ts);
     var wilist = new List<WorkItems> { wi };
     template.WorkItems = wilist;
     this.config.Templates.Add(template);
     return template;
 }
 private Template CreateMultipoleRolesAndJobs(string jobName, string jobName1, int frequency, int frequency1, string roleName)
 {
     var ts1 = new TaskSet { Frequency = frequency, Tasks = new List<Task>() };
     var ts2 = new TaskSet { Frequency = frequency1, Tasks = new List<Task>() };
     var task = new Task { JobName = jobName };
     ts1.Tasks.Add(task);
     var task1 = new Task { JobName = jobName1 };
     ts2.Tasks.Add(task1);
     var template = new Template();
     var wi = new WorkItems { RoleName = roleName, TaskSet = new List<TaskSet>() };
     wi.TaskSet.Add(ts1);
     wi.TaskSet.Add(ts2);
     var wilist = new List<WorkItems> { wi };
     template.WorkItems = wilist;
     this.config.Templates.Add(template);
     return template;
 }
        public void Should_generate_test_config_file()
        {
            try
            {
                var log = LogManager.GetLogger("log");
                var encryption = new Encryption();
                var simpleCs = encryption.Encrypt("some Cs");

                log4net.Config.XmlConfigurator.Configure();

                var job1 = new WmiClient { ClientName = "GraphiteTcpClient", Name = "GetNumberOfTransactionsASecond", Hostname = simpleCs, Sql = "some sql" };
                var job2 = new WmiClient { ClientName = "GraphiteUdpClient", Name = "GetNumberOfDeliveryies", Hostname = simpleCs, Sql = "some sql1" };
                var client1 = new GraphiteTcpClient { ClientName = "GraphiteTcpClient", Port = 2003, Hostname = "metrics.london.ttldev.local" };
                var client2 = new GraphiteUdpClient { ClientName = "GraphiteUdpClient", Port = 2003, Hostname = "metrics.london.ttldev.local" };

                var config = new SqlToGraphiteConfig(new AssemblyResolver(new DirectoryImpl(), log), log);
                config.Jobs.Add(job1);
                config.Jobs.Add(job2);

                var host1 = new Host { Name = "TTL001121" };
                var host2 = new Host { Name = "Server1" };
                var role1 = new Role { Name = "ProductionTests" };
                var role2 = new Role { Name = "default" };
                var role3 = new Role { Name = "SqlTests" };

                host1.Roles.Add(role1);
                host1.Roles.Add(role2);
                host2.Roles.Add(role2);
                host2.Roles.Add(role3);
                config.Hosts.Add(host1);
                config.Hosts.Add(host2);

                var template = new Template();
                var wi = new WorkItems { RoleName = role1.Name, TaskSet = new List<TaskSet>() };
                var taskSet = new TaskSet { Frequency = 1000 };
                taskSet.Tasks.Add(new Task { JobName = job1.Name });
                wi.TaskSet.Add(taskSet);
                template.WorkItems.Add(wi);

                var wi1 = new WorkItems { RoleName = role2.Name, TaskSet = new List<TaskSet>() };
                var taskSet1 = new TaskSet { Frequency = 2000 };
                taskSet1.Tasks.Add(new Task { JobName = job2.Name });
                wi1.TaskSet.Add(taskSet1);
                template.WorkItems.Add(wi1);

                var wi2 = new WorkItems { RoleName = role3.Name, TaskSet = new List<TaskSet>() };
                var taskSet2 = new TaskSet { Frequency = 3000 };
                wi2.TaskSet.Add(taskSet2);
                template.WorkItems.Add(wi2);

                config.Templates.Add(template);
                config.Clients = new ListOfUniqueType<Client> { client1, client2 };
                //var genericSerializer = new GenericSerializer(Global.GetNameSpace());
                //string xml = genericSerializer.Serialize(config);
                //Console.WriteLine(xml);
                //var sqlToGraphiteConfig = genericSerializer.Deserialize<SqlToGraphiteConfig>(xml);
                //foreach (var job in sqlToGraphiteConfig.Jobs)
                //{
                    //Console.WriteLine(job.Type);
                //}
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
 private static WorkItems CreateWorkItems(string taskName, string roleName, int freq)
 {
     var wi = new WorkItems { RoleName = roleName };
     var ts = new TaskSet { Frequency = freq };
     var task = new Task { JobName = taskName };
     ts.Tasks.Add(task);
     wi.TaskSet.Add(ts);
     return wi;
 }