mirror of
https://github.com/volodymyrsmirnov/MalwareMultiScan.git
synced 2025-08-25 22:01:16 +00:00
finished unit tests and docstrings
This commit is contained in:
57
MalwareMultiScan.Tests/Api/AttributesTests.cs
Normal file
57
MalwareMultiScan.Tests/Api/AttributesTests.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
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())
|
||||
})
|
||||
{
|
||||
["MaxFileSize"] = "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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user