public void When_GetUri()
        {
            var image = new LogoSource(new Uri(Helpers.Sample));

            // Should be the same thing.
            Assert.IsTrue(image.GetSourceUri().ToString() == Helpers.Sample);
        }
        public async Task When_GetStream()
        {
            LogoSource image = null;

            try
            {
                var directData = await PrepareDataAsync().ConfigureAwait(false);

                var imageStream = new MemoryStream(directData);
                image = new LogoSource(imageStream);

                var stream = await image.GetStreamAsync();

                var data = stream.ReadToEnd();

                Assert.IsTrue(directData.SequenceEqual(data));

                image.Dispose();
                stream.Dispose();
            }
            finally
            {
                image?.Dispose();
            }
        }
        public async Task When_GetStream()
        {
            LogoSource image = null;

            try
            {
                image = new LogoSource(new Uri(AssetPath));
                var stream = await image.GetStreamAsync();

                var data = stream.ReadToEnd();
                stream.Dispose();

                var client   = new HttpClient();
                var request  = new HttpRequestMessage(HttpMethod.Get, Helpers.Sample);
                var response = await client.SendAsync(request);

                var directData = await response.Content.ReadAsByteArrayAsync();

                response.Dispose();
                client.Dispose();

                Assert.IsTrue(directData.SequenceEqual(data));
            }
            finally
            {
                image?.Dispose();
            }
        }
        private async void ToasterUrl_Click(object sender, RoutedEventArgs args)
        {
            var notification = new ToastNotification();

            notification.Title   = "Toaster with image from Url";
            notification.Message = "Hello world!";
            var logoSource = new LogoSource(new Uri(sample));

            notification.AppLogoOverride = logoSource;
            await notification.Show().ConfigureAwait(false);

            logoSource.Dispose();
        }
        public async Task When_GetDataUrl()
        {
            LogoSource image = null;

            try
            {
                image = new LogoSource(new Uri(Helpers.Sample));
                var dataUrl = await image.GetDataUrlAsync();

                Assert.IsTrue(dataUrl == Helpers.DataUrl);
            }
            finally
            {
                image?.Dispose();
            }
        }
        private async void ToasterResource_Click(object sender, RoutedEventArgs args)
        {
            var notification = new ToastNotification();

            notification.Title   = "Toaster with image from package";
            notification.Message = "Hello world!";
#if __ANDROID__
            var logoSource = new LogoSource(new Uri("ms-appx:///sample.png"));
#else
            var logoSource = new LogoSource(new Uri("ms-appx:///Assets/sample.png"));
#endif
            notification.AppLogoOverride = logoSource;
            await notification.Show().ConfigureAwait(false);

            logoSource.Dispose();
        }
        public void When_GetUri()
        {
            LogoSource image = null;

            try
            {
                image = new LogoSource(new Uri(AssetPath));

                // Should be the same thing.
                Assert.IsTrue(image.GetSourceUri().ToString() == AssetPath);
            }
            finally
            {
                image?.Dispose();
            }
        }
        public async Task When_GetStorageFile()
        {
            LogoSource image = null;

            try
            {
                var directData = await PrepareDataAsync().ConfigureAwait(false);

                var imageStream = new MemoryStream(directData);
                image = new LogoSource(imageStream);

                var file = await image.GetStorageFileAsync().ConfigureAwait(false);

                var folder = await file.GetParentAsync();

                var name   = file.Name;
                var stream = await file.OpenStreamForReadAsync();

                var fileData = stream.ReadToEnd();

                Assert.IsTrue(fileData.SequenceEqual(directData));

                imageStream.Dispose();
                stream.Dispose();
                image.Dispose();
                image = null;

                // Wait for the file to finish deleting...
                await Task.Delay(2000).ConfigureAwait(false);

                try
                {
                    var file2 = await folder.GetItemAsync(name);

                    Assert.IsNull(file2);
                }
                catch (FileNotFoundException)
                {
                    // This is expected.
                    Assert.IsTrue(true);
                }
            }
            finally
            {
                image?.Dispose();
            }
        }
        public async Task When_GetStorageFile()
        {
            LogoSource image = null;

            try
            {
                image = new LogoSource(new Uri(AssetPath));

                var file = await image.GetStorageFileAsync().ConfigureAwait(false);

                var folder = await file.GetParentAsync();

                var name   = file.Name;
                var stream = await file.OpenStreamForReadAsync();

                var fileData = $"data:;base64,{Convert.ToBase64String(stream.ReadToEnd())}";

                System.Diagnostics.Debug.WriteLine(file.Name);
                System.Diagnostics.Debug.WriteLine(folder.Name);
                Assert.IsTrue(fileData == Helpers.DataUrl);

                stream.Dispose();
                image.Dispose();

                // Wait for the file to delete.
                await Task.Delay(2000).ConfigureAwait(false);

                image = null;
                try
                {
                    var file2 = await folder.GetItemAsync(name);

                    Assert.IsNull(file2);
                }
                catch (FileNotFoundException)
                {
                    // This is expected.
                    Assert.IsTrue(true);
                }
            }
            finally
            {
                image?.Dispose();
            }
        }
        public async Task When_GetStorageFile()
        {
            LogoSource image = null;

            try
            {
                using var wc = new WebClient();
                byte[] directData = wc.DownloadData(Helpers.Sample);

                using var imageStream = new MemoryStream(directData);
                image = new LogoSource(imageStream);

                var file = await image.GetStorageFileAsync().ConfigureAwait(false);

                var folder = await file.GetParentAsync();

                var name   = file.Name;
                var stream = await file.OpenStreamForReadAsync();

                var fileData = stream.ReadToEnd();

                Assert.IsTrue(fileData.SequenceEqual(directData));

                stream.Dispose();
                image.Dispose();
                image = null;
                try
                {
                    var file2 = await folder.GetItemAsync(name);

                    Assert.IsNull(file2);
                }
                catch (FileNotFoundException)
                {
                    // This is expected.
                    Assert.Pass();
                }
            }
            finally
            {
                image?.Dispose();
            }
        }
        public async Task When_GetUri()
        {
            LogoSource image = null;

            try
            {
                var directData = await PrepareDataAsync().ConfigureAwait(false);

                var imageStream = new MemoryStream(directData);
                image = new LogoSource(imageStream);

                // Logos created from stream must be null.
                Assert.IsTrue(image.GetSourceUri() == null);
                imageStream.Dispose();
            }
            finally
            {
                image?.Dispose();
            }
        }
        public void When_GetUri()
        {
            LogoSource image = null;

            try
            {
                using var wc = new WebClient();
                byte[] directData = wc.DownloadData(Helpers.Sample);

                using var imageStream = new MemoryStream(directData);
                image = new LogoSource(imageStream);

                // Logos created from stream must be null.
                Assert.IsTrue(image.GetSourceUri() == null);
            }
            finally
            {
                image?.Dispose();
            }
        }
        public async Task When_GetDataUrl()
        {
            LogoSource image = null;

            try
            {
                var directData = await PrepareDataAsync().ConfigureAwait(false);

                var imageStream = new MemoryStream(directData);
                image = new LogoSource(imageStream);

                var dataUrl = await image.GetDataUrlAsync();

                Assert.IsTrue(dataUrl == Helpers.DataUrl);
                imageStream.Dispose();
            }
            finally
            {
                image?.Dispose();
            }
        }
        public async Task When_GetStream()
        {
            LogoSource image = null;

            try
            {
                image            = new LogoSource(new Uri(Helpers.Sample));
                using var stream = await image.GetStreamAsync();

                var data = stream.ReadToEnd();

                using var wc = new WebClient();
                var directData = wc.DownloadData(Helpers.Sample);

                Assert.IsTrue(directData.SequenceEqual(data));
            }
            finally
            {
                image?.Dispose();
            }
        }
        public async Task When_GetDataUrl()
        {
            LogoSource image = null;

            try
            {
                using var wc = new WebClient();
                byte[] directData = wc.DownloadData(Helpers.Sample);

                using var imageStream = new MemoryStream(directData);
                image = new LogoSource(imageStream);

                var dataUrl = await image.GetDataUrlAsync();

                Assert.IsTrue(dataUrl == Helpers.DataUrl);
            }
            finally
            {
                image?.Dispose();
            }
        }
        private async void ToasterStream_Click(object sender, RoutedEventArgs args)
        {
#if __WASM__
            var data = await WasmWebClient.DownloadDataTaskAsync(sample);
#else
            var request        = WebRequest.CreateHttp(sample);
            var response       = request.GetResponse();
            var responseStream = response.GetResponseStream();
            var data           = ReadToEnd(responseStream);
            responseStream.Dispose();
            response.Dispose();
#endif

            var notification = new ToastNotification();
            notification.Title   = "Toaster with image from stream";
            notification.Message = "Hello world!";
            var logoSource = new LogoSource(new MemoryStream(data));
            notification.AppLogoOverride = logoSource;
            await notification.Show().ConfigureAwait(false);

            logoSource.Dispose();
        }
        private async Task<byte[]> RetrieveLogoFromSelectedApi(LogoSource logoSource, string attributeValue)
        {
            var baseAddress = string.Empty;
            var relativeAddress = string.Empty;
            switch (logoSource)
            {
                case LogoSource.Clearbit:
                    baseAddress = "https://logo.clearbit.com/";
                    if (attributeValue.IndexOf("http") > -1)
                        relativeAddress = string.Format("{0}?size=144",new Uri(attributeValue).Host);
                    break;
                case LogoSource.Gravatar:
                    baseAddress = "http://www.gravatar.com/";
                    relativeAddress = string.Format("/avatar/{0}?s=144&&d=404", CalculateMD5Hash(attributeValue));
                    break;
                case LogoSource.Twitter:
                    baseAddress = "https://twitter.com/";
                    relativeAddress = string.Format("/{0}/profile_image?size=normal", attributeValue);
                    break;
            }
            if ((string.IsNullOrEmpty(baseAddress) || string.IsNullOrEmpty(relativeAddress))
                && logoSource == LogoSource.Folder && !string.IsNullOrEmpty(selectedFolder))
            {
                foreach (var imageType in imageTypes)
                {
                    var imageFullPath = string.Format("{0}.{1}", Path.Combine(selectedFolder, attributeValue),imageType);
                    if (File.Exists(imageFullPath))
                    {
                        return File.ReadAllBytes(imageFullPath);
                    }
                }
                return null;
            }
            else
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(baseAddress);
                    client.DefaultRequestHeaders.Accept.Clear();

                    HttpResponseMessage response = await client.GetAsync(relativeAddress);
                    if (response.IsSuccessStatusCode)
                    {
                        var r = await response.Content.ReadAsByteArrayAsync();
                        return r;
                    }
                    return null;
                }
            }
        }