mirror of
https://github.com/volodymyrsmirnov/MalwareMultiScan.git
synced 2025-08-23 21:12:22 +00:00
57 lines
2.0 KiB
C#
57 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using MalwareMultiScan.Api.Attributes;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Configuration.Memory;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
|
|
namespace MalwareMultiScan.Tests.Api
|
|
{
|
|
public class AttributesTests
|
|
{
|
|
[Test]
|
|
public void TestIsHttpUrlAttribute()
|
|
{
|
|
var attribute = new IsHttpUrlAttribute();
|
|
|
|
Assert.True(attribute.IsValid("http://test.com/file.zip"));
|
|
Assert.True(attribute.IsValid("https://test.com/file.zip"));
|
|
Assert.True(attribute.IsValid("HTTPS://test.com"));
|
|
Assert.False(attribute.IsValid(null));
|
|
Assert.False(attribute.IsValid(string.Empty));
|
|
Assert.False(attribute.IsValid("test"));
|
|
Assert.False(attribute.IsValid("ftp://test.com"));
|
|
}
|
|
|
|
[Test]
|
|
public void TestMaxFileSizeAttribute()
|
|
{
|
|
var attribute = new MaxFileSizeAttribute();
|
|
|
|
var configuration = new ConfigurationRoot(new List<IConfigurationProvider>
|
|
{
|
|
new MemoryConfigurationProvider(new MemoryConfigurationSource())
|
|
})
|
|
{
|
|
["FILE_SIZE_LIMIT"] = "100"
|
|
};
|
|
|
|
var context = new ValidationContext(
|
|
string.Empty, Mock.Of<IServiceProvider>(x =>
|
|
x.GetService(typeof(IConfiguration)) == configuration
|
|
), null);
|
|
|
|
Assert.True(attribute.GetValidationResult(
|
|
Mock.Of<IFormFile>(x => x.Length == 10), context) == ValidationResult.Success);
|
|
|
|
Assert.True(attribute.GetValidationResult(
|
|
Mock.Of<IFormFile>(x => x.Length == 100), context) == ValidationResult.Success);
|
|
|
|
Assert.False(attribute.GetValidationResult(
|
|
Mock.Of<IFormFile>(x => x.Length == 101), context) == ValidationResult.Success);
|
|
}
|
|
}
|
|
} |