TestFilterOnProxyWithoutTarget

目录

[1 TestFilterOnProxyWithoutTarget](#1 TestFilterOnProxyWithoutTarget)

[1.1 Test_ex_thrown_from_filters](#1.1 Test_ex_thrown_from_filters)

[1.2 Test_catching_ex_thrown_from_filters](#1.2 Test_catching_ex_thrown_from_filters)

[1.2.1 // Exceptions are handled](#1.2.1 // Exceptions are handled)

  1. TestFilterOnProxyWithoutTarget

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

{

    1. Test_ex_thrown_from_filters

Fact

public async Task Test_ex_thrown_from_filters()

{

var serviceCollection = new ServiceCollection();

serviceCollection.UseFlatwhiteFilters();

serviceCollection.AddSingleton(Mock.Of<ILogger>());

serviceCollection.AddProxyWithoutTarget<IProductService>(ServiceLifetime.Singleton);

var sp = serviceCollection.BuildServiceProvider();

var proxy = sp.GetRequiredService<IProductService>();

var ex = Assert.Throws<Exception>(() => proxy.Delete(1));

Assert.Equal($"{nameof(BadMethodFilterAttribute)}.{nameof(BadMethodFilterAttribute.OnMethodExecuting)}", ex.Message);

ex = await Assert.ThrowsAsync<Exception>(() => proxy.DeleteAsync(1));

Assert.Equal($"{nameof(BadMethodFilterAttribute)}.{nameof(BadMethodFilterAttribute.OnMethodExecutingAsync)}", ex.Message);

}

    1. Test_catching_ex_thrown_from_filters

Fact

public async Task Test_catching_ex_thrown_from_filters()

{

var serviceCollection = new ServiceCollection();

serviceCollection.UseFlatwhiteFilters();

serviceCollection.AddProxyWithoutTarget<IProductService>(ServiceLifetime.Singleton);

var sp = serviceCollection.BuildServiceProvider();

var proxy = sp.GetRequiredService<IProductService>();

      1. // Exceptions are handled

proxy.DeleteBySku(Guid.NewGuid());

await proxy.DeleteBySkuAsync(Guid.NewGuid());

}

}

}

相关推荐
前端架构师-老李12 小时前
HTML与CSS基础第四课—strong、em、b、i 各表示什么
前端·css·html
reasonsummer14 小时前
【教学类-07-12】20261028大3班破译电话号码html(手机按钮版本)
python·html
砚凝霜15 小时前
CTF Misc 签到 GXUST·CTF:查看源码 + HTML 注释 + Base64 解码(附 Base64 原理)
前端·html
喜欢吃豆16 小时前
我开源了 Agent UI Lab 用交互实验理解 AG-UI A2UI 与 MCP Apps
ui·开源·大模型·交互
染指11101 天前
158.Agent-LangGraph-子图(共享状态和不共享状态模式)
开发语言·人工智能·python·ui·agent·agents
夜雪一千1 天前
标题特殊符号数据清洗实战:解决HTML实体、零宽字符、Emoji乱码踩坑
前端·html
wuyk5552 天前
PyQt6-第14讲-数据库与Excel双向同步
数据库·python·ui·excel·pyqt
前端架构师-老李2 天前
HTML与CSS基础第二课—初识HTML
前端·css·html
腾讯端服务2 天前
一码Duo端-Kuikly-iOS折叠屏新UI适配实践
android·ui·ios·kotlin·鸿蒙