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

}

}

}

相关推荐
十一.3666 小时前
131-133 定时器的应用
前端·javascript·html
inferno10 小时前
HTML基础(第一部分)
前端·html
UI设计兰亭妙微13 小时前
兰亭妙微ui设计公司分享:移动端界面用户友好型设计的核心思路
ui·移动端界面设计
十一.36614 小时前
127-130 定时器的简介,切换图片练习,修改div移动练习,延时调用
前端·javascript·html
青稞社区.14 小时前
小米大模型 Plus 团队提出BTL-UI:基于直觉-思考-关联的GUI Agent推理
人工智能·ui
weixin_5316518115 小时前
@clack/prompts 命令行终端中构建交互式用户界面
ui
Larry_Yanan16 小时前
Qt多进程(四)QTcpSocket
开发语言·c++·qt·ui
龙仔CLL17 小时前
vue2项目使用zoom解决pc端浏览器百分比缩放,布局样式不兼容问题
vue.js·html·zoom
_Kayo_19 小时前
HTML 拖放API
前端·javascript·html
wtrees_松阳19 小时前
【弦断处见真章】:鸿蒙UI三重境之《UIContext》心法探幽
ui·华为·harmonyos