You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
997 B

using System.Security.Cryptography;
using Newtonsoft.Json;
namespace Infrastructure.Tests;
public class GenericTests
{
[Fact]
public void ValueConvertTest()
{
const string value = "7";
var convertedValue = Convert<long>(value);
Assert.Equal(7, convertedValue);
}
private static T Convert<T>(string value) where T : IEquatable<T>
{
return (T)System.Convert.ChangeType(value, typeof(T));
}
[Fact]
public void DefaultValueTest()
{
const long value = 0L;
long? nullableValue = null;
Assert.Equal(default, value);
Assert.Null(nullableValue);
}
[Fact]
public void HashTest()
{
var json = JsonConvert.SerializeObject(323234L);
var hashBytes = MD5.HashData(Encoding.ASCII.GetBytes(json));
var hashString = BitConverter.ToString(hashBytes).Replace("-", "").ToLowerInvariant();
Assert.NotEmpty(hashString);
Assert.NotNull(hashString);
}
}