コード例 #1
0
        public void AddInJsonTest(Student alumno)
        {
            var jsonFormat = FormatFactory.CreateFormat(Enums.TipoArchivo.json, stringPointer);

            jsonFormat.Add(alumno);
            stringPointer += ".json";
            Assert.True(File.Exists(stringPointer));
            var alumnoInFile = JsonConvert.DeserializeObject <List <Student> >(File.ReadAllText(stringPointer)).Where(a => a.GUID == alumno.GUID).First();

            Assert.Equal(alumnoInFile, alumno);
        }
コード例 #2
0
        public void AddInTxtTest(Student alumno)
        {
            var txtFormat = FormatFactory.CreateFormat(Enums.TipoArchivo.txt, stringPointer);

            txtFormat.Add(alumno);
            stringPointer += ".txt";
            Assert.True(File.Exists(stringPointer));
            var txtString      = File.ReadAllText(stringPointer);
            var alumnoSplitted = txtString.Split(',');
            var alumnoInFile   = new Student(Guid.Parse(alumnoSplitted.First()), Convert.ToInt32(alumnoSplitted[1]), alumnoSplitted[2], alumnoSplitted[3], alumnoSplitted.Last());

            Assert.Equal(alumno, alumnoInFile);
        }
コード例 #3
0
    static void Main(String[] args)
    {
        String  formatName1 = Console.ReadLine(), formatName2 = Console.ReadLine();
        AFormat format = FormatFactory.CreateFormat(formatName1);

        if (formatName1 == formatName2)
        {
            format.Output(new ConsoleOutput());
        }
        else
        {
            format.TransformTo(formatName2).Output(new ConsoleOutput());
        }
    }
コード例 #4
0
        public void AddInXmlTest(Student alumno)
        {
            var xmlFormat = FormatFactory.CreateFormat(Enums.TipoArchivo.xml, stringPointer);

            xmlFormat.Add(alumno);
            stringPointer += ".xml";
            Assert.True(File.Exists(stringPointer));
            List <Student> alumnosInFile;
            Student        alumnoInFile;

            using (Stream reader = File.OpenRead(stringPointer))
            {
                var xmlSerializer = new XmlSerializer(typeof(List <Student>));
                alumnosInFile = xmlSerializer.Deserialize(reader) as List <Student>;
                alumnoInFile  = alumnosInFile.Where(a => a.GUID == alumno.GUID).First();
            }
            Assert.Equal(alumno, alumnoInFile);
        }
コード例 #5
0
        private async Task ExecuteWebhook(EventInfo request)
        {
            var hooks = Plugin.Instance.Configuration.Hooks
                        .Where(h => h.Events.Contains(request.Event));

            foreach (var hook in hooks)
            {
                if (!string.IsNullOrEmpty(hook.UserId) && request.User.Id.ToString("N") != hook.UserId)
                {
                    continue;
                }

                var formatter = _formatFactory.CreateFormat(hook.Format);
                try
                {
                    await formatter.Format(new Uri(hook.Url), request);
                }
                catch (Exception e)
                {
                    _logger.LogWarning(e, "Error during executing webhook: {0}", hook.Url);
                }
            }
        }
コード例 #6
0
 public void FactoryReturnsXml()
 {
     Assert.IsType <XmlFormat>(FormatFactory.CreateFormat(Enums.TipoArchivo.xml, "prueba"));
 }
コード例 #7
0
 public void FactoryReturnsTxt()
 {
     Assert.IsType <TxtFormat>(FormatFactory.CreateFormat(Enums.TipoArchivo.txt, "prueba"));
 }
コード例 #8
0
 public void FactoryReturnsJson()
 {
     Assert.IsType <JsonFormat>(FormatFactory.CreateFormat(Enums.TipoArchivo.json, "prueba"));
 }