27 lines
899 B
C#
27 lines
899 B
C#
using Lazy.Captcha.Core;
|
|
using Microsoft.Extensions.Caching.Distributed;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Jiaowu.Api.Tests;
|
|
|
|
public sealed class LazyCaptchaIntegrationTests
|
|
{
|
|
[Fact]
|
|
public void Generated_code_is_valid_once_and_returns_image_bytes()
|
|
{
|
|
var services = new ServiceCollection();
|
|
services.AddDistributedMemoryCache();
|
|
services.AddCaptcha(new ConfigurationBuilder().Build());
|
|
using var provider = services.BuildServiceProvider();
|
|
var captcha = provider.GetRequiredService<ICaptcha>();
|
|
var id = Guid.NewGuid().ToString("N");
|
|
|
|
var generated = captcha.Generate(id, expirySeconds: 120);
|
|
|
|
Assert.NotEmpty(generated.Bytes);
|
|
Assert.True(captcha.Validate(id, generated.Code));
|
|
Assert.False(captcha.Validate(id, generated.Code));
|
|
}
|
|
}
|