csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.7 KiB
64 lines
1.7 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using Avalonia.Platform;
|
|
using Avalonia.Utilities;
|
|
using Moq;
|
|
|
|
namespace Avalonia.UnitTests
|
|
{
|
|
public class MockAssetLoader : IAssetLoader
|
|
{
|
|
private Dictionary<Uri, string> _assets;
|
|
|
|
public MockAssetLoader(params (string, string)[] assets)
|
|
{
|
|
_assets = assets.ToDictionary(x => new Uri(x.Item1, UriKind.RelativeOrAbsolute), x => x.Item2);
|
|
}
|
|
|
|
public bool Exists(Uri uri, Uri? baseUri = null)
|
|
{
|
|
return _assets.ContainsKey(uri);
|
|
}
|
|
|
|
public Stream Open(Uri uri, Uri? baseUri = null)
|
|
{
|
|
return new MemoryStream(Encoding.UTF8.GetBytes(_assets[uri]));
|
|
}
|
|
|
|
public (Stream stream, Assembly assembly) OpenAndGetAssembly(Uri uri, Uri? baseUri = null)
|
|
{
|
|
return (Open(uri, baseUri), Mock.Of<Assembly>());
|
|
}
|
|
|
|
public Assembly? GetAssembly(Uri uri, Uri? baseUri = null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
public IEnumerable<Uri> GetAssets(Uri uri, Uri? baseUri)
|
|
{
|
|
var absPath = uri.GetUnescapeAbsolutePath();
|
|
return _assets.Keys.Where(
|
|
x => x.GetUnescapeAbsolutePath().IndexOf(absPath, StringComparison.Ordinal) >= 0);
|
|
}
|
|
|
|
public void InvalidateAssemblyCache(string name)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public void InvalidateAssemblyCache()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public void SetDefaultAssembly(Assembly asm)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|
|
|