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.
421 lines
12 KiB
421 lines
12 KiB
1 year ago
|
using Recyclarr.TrashGuide.CustomFormat;
|
||
2 years ago
|
|
||
2 years ago
|
namespace Recyclarr.Cli.Tests.Pipelines.CustomFormat.Models;
|
||
2 years ago
|
|
||
|
[TestFixture]
|
||
|
public class CustomFormatDataComparerTest
|
||
|
{
|
||
|
[Test]
|
||
|
public void Custom_formats_equal()
|
||
|
{
|
||
|
var a = new CustomFormatData
|
||
|
{
|
||
|
Name = "EVO (no WEBDL)",
|
||
|
IncludeCustomFormatWhenRenaming = false,
|
||
|
Specifications = new[]
|
||
|
{
|
||
|
new CustomFormatSpecificationData
|
||
|
{
|
||
|
Name = "EVO",
|
||
|
Implementation = "ReleaseTitleSpecification",
|
||
|
Negate = false,
|
||
|
Required = true,
|
||
2 years ago
|
Fields = new[]
|
||
2 years ago
|
{
|
||
2 years ago
|
new CustomFormatFieldData
|
||
|
{
|
||
|
Value = "\\bEVO(TGX)?\\b"
|
||
|
}
|
||
2 years ago
|
}
|
||
|
},
|
||
|
new CustomFormatSpecificationData
|
||
|
{
|
||
|
Name = "WEBDL",
|
||
|
Implementation = "SourceSpecification",
|
||
|
Negate = true,
|
||
|
Required = true,
|
||
2 years ago
|
Fields = new[]
|
||
2 years ago
|
{
|
||
2 years ago
|
new CustomFormatFieldData
|
||
|
{
|
||
|
Value = 7
|
||
|
}
|
||
2 years ago
|
}
|
||
|
},
|
||
|
new CustomFormatSpecificationData
|
||
|
{
|
||
|
Name = "WEBRIP",
|
||
|
Implementation = "SourceSpecification",
|
||
|
Negate = true,
|
||
|
Required = true,
|
||
2 years ago
|
Fields = new[]
|
||
2 years ago
|
{
|
||
2 years ago
|
new CustomFormatFieldData
|
||
|
{
|
||
|
Value = 8
|
||
|
}
|
||
2 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
var b = new CustomFormatData
|
||
|
{
|
||
|
Name = "EVO (no WEBDL)",
|
||
|
IncludeCustomFormatWhenRenaming = false,
|
||
|
Specifications = new[]
|
||
|
{
|
||
|
new CustomFormatSpecificationData
|
||
|
{
|
||
|
Name = "EVO",
|
||
|
Implementation = "ReleaseTitleSpecification",
|
||
|
Negate = false,
|
||
|
Required = true,
|
||
2 years ago
|
Fields = new[]
|
||
2 years ago
|
{
|
||
2 years ago
|
new CustomFormatFieldData
|
||
|
{
|
||
|
Value = "\\bEVO(TGX)?\\b"
|
||
|
}
|
||
2 years ago
|
}
|
||
|
},
|
||
|
new CustomFormatSpecificationData
|
||
|
{
|
||
|
Name = "WEBDL",
|
||
|
Implementation = "SourceSpecification",
|
||
|
Negate = true,
|
||
|
Required = true,
|
||
2 years ago
|
Fields = new[]
|
||
2 years ago
|
{
|
||
2 years ago
|
new CustomFormatFieldData
|
||
|
{
|
||
|
Value = 7
|
||
|
}
|
||
2 years ago
|
}
|
||
|
},
|
||
|
new CustomFormatSpecificationData
|
||
|
{
|
||
|
Name = "WEBRIP",
|
||
|
Implementation = "SourceSpecification",
|
||
|
Negate = true,
|
||
|
Required = true,
|
||
2 years ago
|
Fields = new[]
|
||
2 years ago
|
{
|
||
2 years ago
|
new CustomFormatFieldData
|
||
|
{
|
||
|
Value = 8
|
||
|
}
|
||
2 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
2 years ago
|
a.Should().BeEquivalentTo(b, o => o.Using(CustomFormatData.Comparer));
|
||
2 years ago
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Custom_formats_not_equal_when_field_value_different()
|
||
|
{
|
||
|
var a = new CustomFormatData
|
||
|
{
|
||
|
Name = "EVO (no WEBDL)",
|
||
|
IncludeCustomFormatWhenRenaming = false,
|
||
|
Specifications = new[]
|
||
|
{
|
||
|
new CustomFormatSpecificationData
|
||
|
{
|
||
|
Name = "EVO",
|
||
|
Implementation = "ReleaseTitleSpecification",
|
||
|
Negate = false,
|
||
|
Required = true,
|
||
2 years ago
|
Fields = new[]
|
||
2 years ago
|
{
|
||
2 years ago
|
new CustomFormatFieldData
|
||
|
{
|
||
|
Value = "\\bEVO(TGX)?\\b"
|
||
|
}
|
||
2 years ago
|
}
|
||
|
},
|
||
|
new CustomFormatSpecificationData
|
||
|
{
|
||
|
Name = "WEBDL",
|
||
|
Implementation = "SourceSpecification",
|
||
|
Negate = true,
|
||
|
Required = true,
|
||
2 years ago
|
Fields = new[]
|
||
2 years ago
|
{
|
||
2 years ago
|
new CustomFormatFieldData
|
||
|
{
|
||
|
Value = 7
|
||
|
}
|
||
2 years ago
|
}
|
||
|
},
|
||
|
new CustomFormatSpecificationData
|
||
|
{
|
||
|
Name = "WEBRIP",
|
||
|
Implementation = "SourceSpecification",
|
||
|
Negate = true,
|
||
|
Required = true,
|
||
2 years ago
|
Fields = new[]
|
||
2 years ago
|
{
|
||
2 years ago
|
new CustomFormatFieldData
|
||
|
{
|
||
|
Value = 8
|
||
|
}
|
||
2 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
var b = new CustomFormatData
|
||
|
{
|
||
|
Name = "EVO (no WEBDL)",
|
||
|
IncludeCustomFormatWhenRenaming = false,
|
||
|
Specifications = new[]
|
||
|
{
|
||
|
new CustomFormatSpecificationData
|
||
|
{
|
||
|
Name = "EVO",
|
||
|
Implementation = "ReleaseTitleSpecification",
|
||
|
Negate = false,
|
||
|
Required = true,
|
||
2 years ago
|
Fields = new[]
|
||
2 years ago
|
{
|
||
2 years ago
|
new CustomFormatFieldData
|
||
|
{
|
||
|
Value = "\\bEVO(TGX)?\\b"
|
||
|
}
|
||
2 years ago
|
}
|
||
|
},
|
||
|
new CustomFormatSpecificationData
|
||
|
{
|
||
|
Name = "WEBDL",
|
||
|
Implementation = "SourceSpecification",
|
||
|
Negate = true,
|
||
|
Required = true,
|
||
2 years ago
|
Fields = new[]
|
||
2 years ago
|
{
|
||
2 years ago
|
new CustomFormatFieldData
|
||
|
{
|
||
|
Value = 10 // this is different
|
||
|
}
|
||
2 years ago
|
}
|
||
|
},
|
||
|
new CustomFormatSpecificationData
|
||
|
{
|
||
|
Name = "WEBRIP",
|
||
|
Implementation = "SourceSpecification",
|
||
|
Negate = true,
|
||
|
Required = true,
|
||
2 years ago
|
Fields = new[]
|
||
2 years ago
|
{
|
||
2 years ago
|
new CustomFormatFieldData
|
||
|
{
|
||
|
Value = 8
|
||
|
}
|
||
2 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
var result = CustomFormatData.Comparer.Equals(a, b);
|
||
|
|
||
|
result.Should().BeFalse();
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Equal_when_ignored_fields_are_different()
|
||
|
{
|
||
|
var a = new CustomFormatData
|
||
|
{
|
||
|
TrashId = "a",
|
||
1 year ago
|
TrashScores = {["default"] = 1},
|
||
2 years ago
|
Category = "one"
|
||
|
};
|
||
|
|
||
|
var b = new CustomFormatData
|
||
|
{
|
||
|
TrashId = "b",
|
||
1 year ago
|
TrashScores = {["default"] = 2},
|
||
2 years ago
|
Category = "two"
|
||
|
};
|
||
|
|
||
|
var result = CustomFormatData.Comparer.Equals(a, b);
|
||
|
|
||
|
result.Should().BeTrue();
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Not_equal_when_right_is_null()
|
||
|
{
|
||
|
var a = new CustomFormatData();
|
||
|
var b = (CustomFormatData?) null;
|
||
|
|
||
|
var result = CustomFormatData.Comparer.Equals(a, b);
|
||
|
|
||
|
result.Should().BeFalse();
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Not_equal_when_left_is_null()
|
||
|
{
|
||
|
var a = (CustomFormatData?) null;
|
||
|
var b = new CustomFormatData();
|
||
|
|
||
|
var result = CustomFormatData.Comparer.Equals(a, b);
|
||
|
|
||
|
result.Should().BeFalse();
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Equal_for_same_reference()
|
||
|
{
|
||
|
var a = new CustomFormatData();
|
||
|
|
||
|
var result = CustomFormatData.Comparer.Equals(a, a);
|
||
|
|
||
|
result.Should().BeTrue();
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Not_equal_when_different_spec_count()
|
||
|
{
|
||
|
var a = new CustomFormatData
|
||
|
{
|
||
|
Name = "EVO (no WEBDL)",
|
||
|
IncludeCustomFormatWhenRenaming = false,
|
||
|
Specifications = new[]
|
||
|
{
|
||
|
new CustomFormatSpecificationData(),
|
||
|
new CustomFormatSpecificationData()
|
||
|
}
|
||
|
};
|
||
|
|
||
|
var b = new CustomFormatData
|
||
|
{
|
||
|
Name = "EVO (no WEBDL)",
|
||
|
IncludeCustomFormatWhenRenaming = false,
|
||
|
Specifications = new[]
|
||
|
{
|
||
|
new CustomFormatSpecificationData(),
|
||
|
new CustomFormatSpecificationData(),
|
||
|
new CustomFormatSpecificationData()
|
||
|
}
|
||
|
};
|
||
|
|
||
|
var result = CustomFormatData.Comparer.Equals(a, b);
|
||
|
|
||
|
result.Should().BeFalse();
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Not_equal_when_non_matching_spec_names()
|
||
|
{
|
||
|
var a = new CustomFormatData
|
||
|
{
|
||
|
Name = "EVO (no WEBDL)",
|
||
|
IncludeCustomFormatWhenRenaming = false,
|
||
|
Specifications = new[]
|
||
|
{
|
||
|
new CustomFormatSpecificationData
|
||
|
{
|
||
|
Name = "EVO",
|
||
|
Implementation = "ReleaseTitleSpecification",
|
||
|
Negate = false,
|
||
|
Required = true,
|
||
2 years ago
|
Fields = new[]
|
||
2 years ago
|
{
|
||
2 years ago
|
new CustomFormatFieldData
|
||
|
{
|
||
|
Value = "\\bEVO(TGX)?\\b"
|
||
|
}
|
||
2 years ago
|
}
|
||
|
},
|
||
|
new CustomFormatSpecificationData
|
||
|
{
|
||
|
Name = "WEBDL",
|
||
|
Implementation = "SourceSpecification",
|
||
|
Negate = true,
|
||
|
Required = true,
|
||
2 years ago
|
Fields = new[]
|
||
2 years ago
|
{
|
||
2 years ago
|
new CustomFormatFieldData
|
||
|
{
|
||
|
Value = 7
|
||
|
}
|
||
2 years ago
|
}
|
||
|
},
|
||
|
new CustomFormatSpecificationData
|
||
|
{
|
||
|
Name = "WEBRIP",
|
||
|
Implementation = "SourceSpecification",
|
||
|
Negate = true,
|
||
|
Required = true,
|
||
2 years ago
|
Fields = new[]
|
||
2 years ago
|
{
|
||
2 years ago
|
new CustomFormatFieldData
|
||
|
{
|
||
|
Value = 8
|
||
|
}
|
||
2 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
var b = new CustomFormatData
|
||
|
{
|
||
|
Name = "EVO (no WEBDL)",
|
||
|
IncludeCustomFormatWhenRenaming = false,
|
||
|
Specifications = new[]
|
||
|
{
|
||
|
new CustomFormatSpecificationData
|
||
|
{
|
||
|
Name = "EVO",
|
||
|
Implementation = "ReleaseTitleSpecification",
|
||
|
Negate = false,
|
||
|
Required = true,
|
||
2 years ago
|
Fields = new[]
|
||
2 years ago
|
{
|
||
2 years ago
|
new CustomFormatFieldData
|
||
|
{
|
||
|
Value = "\\bEVO(TGX)?\\b"
|
||
|
}
|
||
2 years ago
|
}
|
||
|
},
|
||
|
new CustomFormatSpecificationData
|
||
|
{
|
||
|
Name = "WEBDL",
|
||
|
Implementation = "SourceSpecification",
|
||
|
Negate = true,
|
||
|
Required = true,
|
||
2 years ago
|
Fields = new[]
|
||
2 years ago
|
{
|
||
2 years ago
|
new CustomFormatFieldData
|
||
|
{
|
||
|
Value = 7
|
||
|
}
|
||
2 years ago
|
}
|
||
|
},
|
||
|
new CustomFormatSpecificationData
|
||
|
{
|
||
|
Name = "WEBRIP2", // This name is different
|
||
|
Implementation = "SourceSpecification",
|
||
|
Negate = true,
|
||
|
Required = true,
|
||
2 years ago
|
Fields = new[]
|
||
2 years ago
|
{
|
||
2 years ago
|
new CustomFormatFieldData
|
||
|
{
|
||
|
Value = 8
|
||
|
}
|
||
2 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
var result = CustomFormatData.Comparer.Equals(a, b);
|
||
|
|
||
|
result.Should().BeFalse();
|
||
|
}
|
||
|
}
|