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

}

}

}

相关推荐
willow9 小时前
html5基础整理
html
anOnion3 天前
构建无障碍组件之Radio group pattern
前端·html·交互设计
前端Hardy3 天前
HTML&CSS&JS:丝滑无卡顿的明暗主题切换
javascript·css·html
前端Hardy4 天前
HTML&CSS&JS:基于定位的实时天气卡片
javascript·css·html
前端Hardy4 天前
HTML&CSS:纯CSS实现随机转盘抽奖机——无JS,全靠现代CSS黑科技!
css·html
DeathGhost4 天前
分享URL地址到微信朋友圈没有缩略图?
前端·html
修炼前端秘籍的小帅5 天前
Stitch——Google热门的免费AI UI设计工具
前端·人工智能·ui
王码码20355 天前
Flutter for OpenHarmony:socket_io_client 实时通信的事实标准(Node.js 后端的最佳拍档) 深度解析与鸿蒙适配指南
android·flutter·ui·华为·node.js·harmonyos
前端Hardy5 天前
HTML&CSS:高颜值产品卡片页面,支持主题切换
css·html
Never_Satisfied5 天前
在HTML & CSS中,nth-child、nth-of-type详解
前端·css·html