Exemplo n.º 1
0
        async public Task TestShiftSubtitle()
        {
            var inputPath  = @"C:\Users\Fabio\source\repos\graph\SubtitleTimeshift.Tests\The.Matrix.1999.BluRay.720p.Malay.srt";
            var outputPath = @"C:\Users\Fabio\source\repos\graph\SubtitleTimeshift.Tests\The.Matrix.1999.BluRay.720p.Malay - Copy.srt";
            var assertPath = @"C:\Users\Fabio\source\repos\graph\SubtitleTimeshift.Tests\The.Matrix.1999.BluRay.720p.Malay - Assert.srt";

            var timeSpan = TimeSpan.FromMilliseconds(123.0);
            var encoding = System.Text.Encoding.UTF8;

            using (var inputStream = new FileStream(inputPath, FileMode.Open, FileAccess.Read))
                using (var outputStream = new FileStream(outputPath, FileMode.Truncate, FileAccess.ReadWrite))
                {
                    await Shifter.Shift(inputStream, outputStream, timeSpan, encoding);
                }

            using (var outputStream = new FileStream(outputPath, FileMode.Open, FileAccess.Read))
                using (var outputReader = new StreamReader(outputPath, encoding, true))
                    using (var assertStream = new FileStream(assertPath, FileMode.Open, FileAccess.Read))
                        using (var assertReader = new StreamReader(assertStream, encoding, true))
                        {
                            var assertLine = default(string);
                            var outputLine = default(string);

                            while (null != (assertLine = await assertReader.ReadLineAsync()))
                            {
                                Assert.IsFalse(outputReader.EndOfStream);
                                outputLine = await outputReader.ReadLineAsync();

                                Assert.AreEqual(assertLine, outputLine);
                            }
                        }
        }
Exemplo n.º 2
0
        public void TestShiftSubtitle()
        {
            var inputPath  = "The.Matrix.1999.BluRay.720p.Malay.srt";
            var outputPath = "The.Matrix.1999.BluRay.720p.Malay - Copy.srt";
            var assertPath = "The.Matrix.1999.BluRay.720p.Malay - Assert.srt";

            var timeSpan = TimeSpan.FromMilliseconds(123);
            var encoding = System.Text.Encoding.UTF8;

            using (var inputStream = new FileStream(inputPath, FileMode.Open, FileAccess.Read))
                using (var outputStream = new FileStream(outputPath, FileMode.Truncate, FileAccess.ReadWrite))
                {
                    Shifter.Shift(inputStream, outputStream, timeSpan, encoding);
                }

            using (var outputStream = new FileStream(outputPath, FileMode.Open, FileAccess.Read))
                using (var outputReader = new StreamReader(outputPath, encoding, true))
                    using (var assertStream = new FileStream(assertPath, FileMode.Open, FileAccess.Read))
                        using (var assertReader = new StreamReader(assertStream, encoding, true))
                        {
                            var assertLine = default(string);
                            var outputLine = default(string);

                            while (null != (assertLine = assertReader.ReadLine()))
                            {
                                Assert.IsFalse(outputReader.EndOfStream);
                                outputLine = outputReader.ReadLine();
                                Assert.AreEqual(assertLine, outputLine);
                            }
                        }
        }
Exemplo n.º 3
0
        public void ShiftWorksOnSamples()
        {
            var shifter = new Shifter();
            var shifted = shifter.Shift("qzmt-zixmtkozy-ivhz", 343);

            Assert.Equal("very encrypted name", shifted);
        }
Exemplo n.º 4
0
        public async Task TestShiftSubtitle()
        {
            var root       = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName;
            var inputPath  = Path.Combine(root, "The.Matrix.1999.BluRay.720p.Malay.srt");
            var outputPath = Path.Combine(root, "The.Matrix.1999.BluRay.720p.Malay - Copy.srt");
            var assertPath = Path.Combine(root, "The.Matrix.1999.BluRay.720p.Malay - Assert.srt");
            var timeSpan   = TimeSpan.FromMilliseconds(123);
            var encoding   = System.Text.Encoding.UTF8;

            using (var inputStream = new FileStream(inputPath, FileMode.Open, FileAccess.Read))
                using (var outputStream = new FileStream(outputPath, FileMode.Truncate, FileAccess.ReadWrite))
                {
                    await Shifter.Shift(inputStream, outputStream, timeSpan, encoding);
                }

            using (var outputStream = new FileStream(outputPath, FileMode.Open, FileAccess.Read))
                using (var outputReader = new StreamReader(outputPath, encoding, true))
                    using (var assertStream = new FileStream(assertPath, FileMode.Open, FileAccess.Read))
                        using (var assertReader = new StreamReader(assertStream, encoding, true))
                        {
                            var assertLine = default(string);
                            var outputLine = default(string);

                            while (null != (assertLine = await assertReader.ReadLineAsync()))
                            {
                                Assert.False(outputReader.EndOfStream);
                                outputLine = await outputReader.ReadLineAsync();

                                Assert.Equal(assertLine, outputLine);
                            }
                        }
        }
Exemplo n.º 5
0
        public string Solve(string[] input)
        {
            var parser    = new EntryParser();
            var list      = input.Select(parser.Parse);
            var cc        = new ChecksumComputer();
            var realRooms = list.Where(r => r.DeclaredChecksum == cc.Compute(r.EncryptedName));
            var shifter   = new Shifter();
            var decrypted = realRooms.Select(r => new { name = shifter.Shift(r.EncryptedName, r.SectorId), r.SectorId });
            var northPole = decrypted.FirstOrDefault(x => x.name.Contains("northpole"));

            return(northPole?.SectorId.ToString() ?? "Not found");
        }