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

}

}

}

相关推荐
anOnion8 小时前
构建无障碍组件之Slider Pattern
前端·html·交互设计
就叫_这个吧11 小时前
HTML常用标签及举例使用
前端·html
许彰午15 小时前
状态模式实战——Row对象的状态机
java·ui·状态模式
zhbi9815 小时前
LVGL8.3标签Label高级应用
ui·lvgl
就叫_这个吧16 小时前
JavaScript中常用事件示例展示附源码
开发语言·javascript·html
scan72417 小时前
大模型只是知道要调用工具,本身不
前端·javascript·html
像风一样的男人@17 小时前
warning: could not find UI helper ‘git-credential-manager-ui‘
git·ui
ZC跨境爬虫18 小时前
跟着 MDN 学CSS day_34:(CSS 布局全面解析)
前端·css·ui·html·tensorflow
ZC跨境爬虫20 小时前
跟着 MDN 学CSS day_32:(Web字体深度解析与实践指南)
前端·javascript·css·ui·html
ZC跨境爬虫20 小时前
跟着 MDN 学CSS day_35:浮动布局完全指南
前端·css·ui·html·tensorflow