TestFilterOnProxyWithoutTarget

目录

1 TestFilterOnProxyWithoutTarget

1.1 Test_ex_thrown_from_filters

1.2 Test_catching_ex_thrown_from_filters

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

serviceCollection.AddProxyWithoutTarget(ServiceLifetime.Singleton);

var sp = serviceCollection.BuildServiceProvider();

var proxy = sp.GetRequiredService();

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

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

ex = await Assert.ThrowsAsync(() => 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(ServiceLifetime.Singleton);

var sp = serviceCollection.BuildServiceProvider();

var proxy = sp.GetRequiredService();

      1. // Exceptions are handled 

proxy.DeleteBySku(Guid.NewGuid());

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

}

}

}

你可能感兴趣的:(Flatwhite,xhtml,ui,html)