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());

}

}

}

相关推荐
不说别的就是很菜1 天前
【前端面试】HTML篇
前端·html
我命由我123451 天前
CesiumJS 案例 P35:添加图片图层(添加图片数据)
开发语言·前端·javascript·css·html·html5·js
q***7482 天前
私有化部署DeepSeek并SpringBoot集成使用(附UI界面使用教程-支持语音、图片)
spring boot·后端·ui
www_stdio2 天前
使用 Ajax 实现异步数据请求:从原理到实践
javascript·ajax·html
Lhuu(重开版2 天前
html语法
前端·html
小只笨笨狗~2 天前
css-文字背景渐变色
前端·css·html
paopao_wu2 天前
DeepSeek-OCR实战(03):本地部署+简单UI测试
ui·ocr
Access开发易登软件2 天前
Access导出带图表的 HTML 报表:技术实现详解
数据库·后端·html·vba·导出·access
顾安r2 天前
11.8 脚本网页 打砖块max
服务器·前端·html·css3
lpfasd1232 天前
Valdi:Snapchat 开源的新一代跨平台 UI 框架
ui·开源