Ejemplo n.º 1
0
        public async Task ShouldDownloadReadme()
        {
            // arrange
            var readme     = "![](./img1.png)\n![](./img2.png)";
            var img1Bytes  = new byte[] { 255, 1 };
            var img2Bytes  = new byte[] { 255, 2 };
            var httpClient = CreateMockedHttpClient(new Dictionary <string, HttpContent>
            {
                { "https://example.com/t/readme.md", new StringContent(readme) },
                { "https://example.com/t/img1.png", new ByteArrayContent(img1Bytes) },
                { "https://example.com/t/img2.png", new ByteArrayContent(img2Bytes) },
            });
            var sut = new ReadmeService(httpClient);

            // act
            var result = await sut.DownloadReadme("https://example.com/t/readme.md");

            //assert
            Assert.AreEqual(readme, result.Readme);
            Assert.That(result.Images, Is.EqualTo(new Dictionary <string, byte[]>
            {
                { "./img1.png", img1Bytes },
                { "./img2.png", img2Bytes },
            }));
        }
Ejemplo n.º 2
0
        public void ShouldUseConditionalTags()
        {
            // arrange
            var    sut   = new ReadmeService();
            string input = LoadReadme();

            // act
            var result = sut.MdToXaml("http://example.com", input);

            Console.WriteLine(result);

            // assert
            Assert.IsTrue(result.Contains("this text will be included in GitHub and HunterPie"));
            Assert.IsTrue(result.Contains("this text will be included only in HunterPie"));
            Assert.IsFalse(result.Contains("this text will be included only in GitHub"));
        }
Ejemplo n.º 3
0
        public void ShouldReplaceImageLinksWithAbsoluteLink()
        {
            // arrange
            var sut   = new ReadmeService();
            var input = LoadReadme();

            // act
            var result = sut.MdToXaml("http://example.com/t", input);

            Console.WriteLine(result);

            // assert
            Assert.IsTrue(result.Contains("https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png"));
            Assert.IsTrue(result.Contains("http://example.com/t/relative1.png"));
            Assert.IsTrue(result.Contains("http://example.com/t/relative2.png"));
            Assert.IsTrue(result.Contains("http://example.com/t/relative3.png"));
        }
Ejemplo n.º 4
0
        public RegistryPluginViewModel(PluginRegistryEntry entry, IPluginListProxy pluginList, ReadmeService readmeService, HttpClient http)
        {
            this.entry         = entry;
            this.pluginList    = pluginList;
            this.readmeService = readmeService;
            this.http          = http;

            DownloadCommand = new ArglessRelayCommand(
                () => CanInstall && IsVersionOk, DownloadPlugin
                );
            DeleteCommand = new ArglessRelayCommand(
                () => CanDelete, Delete
                );
            DownloadImage();
            LastUpdateLong  = PluginViewModelHelper.FormatLongDate(entry.ReleaseDate);
            LastUpdateShort = PluginViewModelHelper.FormatShortDate(entry.ReleaseDate);
            Actions         = new ObservableCollection <PluginActionViewModel>(GetActions());
        }
Ejemplo n.º 5
0
        public void ShouldFindAllImagesLinks()
        {
            // arrange
            var    sut   = new ReadmeService();
            string input = LoadReadme();

            // act
            var result = sut.FindImageLinks("http://example.com/t", input);

            // assert
            var expected = new Dictionary <string, string>
            {
                {
                    "https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png",
                    "https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png"
                },
                { "./relative1.png", "http://example.com/t/relative1.png" },
                { "./relative2.png", "http://example.com/t/relative2.png" },
                { "relative3.png", "http://example.com/t/relative3.png" },
            };

            Assert.That(result, Is.EqualTo(expected));
        }