目录
1 TestFilterOnProxyWithoutTarget
1.1 Test_ex_thrown_from_filters
1.2 Test_catching_ex_thrown_from_filters
1.2.1 // Exceptions are handled
using Flatwhite.Core.Tests.Attributes;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Moq;
using System;
using System.Threading.Tasks;
using Xunit;
namespace Flatwhite.Core.Tests
{
public class TestFilterOnProxyWithoutTarget
{
[Fact]
public async Task Test_ex_thrown_from_filters()
{
var serviceCollection = new ServiceCollection();
serviceCollection.UseFlatwhiteFilters();
serviceCollection.AddSingleton(Mock.Of
serviceCollection.AddProxyWithoutTarget
var sp = serviceCollection.BuildServiceProvider();
var proxy = sp.GetRequiredService
var ex = Assert.Throws
Assert.Equal($"{nameof(BadMethodFilterAttribute)}.{nameof(BadMethodFilterAttribute.OnMethodExecuting)}", ex.Message);
ex = await Assert.ThrowsAsync
Assert.Equal($"{nameof(BadMethodFilterAttribute)}.{nameof(BadMethodFilterAttribute.OnMethodExecutingAsync)}", ex.Message);
}
[Fact]
public async Task Test_catching_ex_thrown_from_filters()
{
var serviceCollection = new ServiceCollection();
serviceCollection.UseFlatwhiteFilters();
serviceCollection.AddProxyWithoutTarget
var sp = serviceCollection.BuildServiceProvider();
var proxy = sp.GetRequiredService
proxy.DeleteBySku(Guid.NewGuid());
await proxy.DeleteBySkuAsync(Guid.NewGuid());
}
}
}