Skip to content

Commit

Permalink
Merge pull request #185 from Flexberry/fix-webfile-compare
Browse files Browse the repository at this point in the history
Fix IComparableType implementation in WebFile class.
  • Loading branch information
Bratchikov Igor authored Jun 8, 2021
2 parents 1f456c2 + 8544965 commit e9463a7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
9 changes: 8 additions & 1 deletion ICSSoft.STORMNET.UserDataTypes/WebFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,14 @@ public int Compare(object x)
{
if (x != null && x is WebFile file)
{
if (file.Url == Url)
if (file.Url == null && Url == null)
{
if (file.Name == Name)
{
return 0;
}
}
else if (file.Url == Url)
{
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,28 @@ public void WebFileCompareTest()
const string File1 = "file1";
const string File2 = "file2";

var file = new WebFile()
var file00 = new WebFile()
{ Name = File1, Url = GetFileUrl(Dir1, File1) };
var file1 = new WebFile()
{ Name = File1, Url = GetFileUrl(Dir1, File1) };
var file2 = new WebFile()
var file01 = new WebFile()
{ Name = File2, Url = GetFileUrl(Dir1, File2) };
var file3 = new WebFile()
var file02 = new WebFile()
{ Name = File1, Url = GetFileUrl(Dir2, File1) };
var file4 = new WebFile()
var file03 = new WebFile()
{ Name = File2, Url = GetFileUrl(Dir2, File2) };
var file10 = new WebFile()
{ Name = File1 };
var file11 = new WebFile()
{ Name = File2 };

Assert.Equal(0, file00.Compare(file00));
Assert.NotEqual(0, file00.Compare(file01));
Assert.NotEqual(0, file00.Compare(file02));
Assert.NotEqual(0, file00.Compare(file03));

Assert.NotEqual(0, file00.Compare(file10));

Assert.Equal(0, file.Compare(file));
Assert.Equal(0, file.Compare(file1));
Assert.NotEqual(0, file.Compare(file2));
Assert.NotEqual(0, file.Compare(file3));
Assert.NotEqual(0, file.Compare(file4));
Assert.Equal(0, file10.Compare(file10));
Assert.NotEqual(0, file10.Compare(file11));
}

private string GetFileUrl(string dirName, string fileName)
Expand Down

0 comments on commit e9463a7

Please sign in to comment.