Skip to content

Commit

Permalink
Added more TNEF tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jstedfast committed Jun 24, 2024
1 parent a464d61 commit 84c4cae
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 32 deletions.
91 changes: 91 additions & 0 deletions UnitTests/Tnef/TnefNameIdTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//
// TnefNameIdTests.cs
//
// Author: Jeffrey Stedfast <jestedfa@microsoft.com>
//
// Copyright (c) 2013-2024 .NET Foundation and Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

using MimeKit.Tnef;

namespace UnitTests.Tnef {
[TestFixture]
public class TnefNameIdTests
{
[Test]
public void TestConstructors ()
{
var guid = Guid.NewGuid ();
var tnef1 = new TnefNameId (guid, 17);

Assert.That (tnef1.Kind, Is.EqualTo (TnefNameIdKind.Id), "Kind Id");
Assert.That (tnef1.PropertySetGuid, Is.EqualTo (guid), "PropertySetGuid Id");
Assert.That (tnef1.Id, Is.EqualTo (17), "Id");

tnef1 = new TnefNameId (guid, "name");
Assert.That (tnef1.Kind, Is.EqualTo (TnefNameIdKind.Name), "Kind Name");
Assert.That (tnef1.PropertySetGuid, Is.EqualTo (guid), "PropertySetGuid Name");
Assert.That (tnef1.Name, Is.EqualTo ("name"), "Name");
}

[Test]
public void TestEqualityOfIdAndName ()
{
var guid = Guid.NewGuid ();
var tnef1 = new TnefNameId (guid, 17);
var tnef2 = new TnefNameId (guid, "name");

Assert.That (tnef2.GetHashCode (), Is.Not.EqualTo (tnef1.GetHashCode ()), "GetHashCode Name vs Id");
Assert.That (tnef2, Is.Not.EqualTo (tnef1), "Equal Name vs Id");

Assert.That (tnef1 == tnef2, Is.False, "==");
Assert.That (tnef1 != tnef2, Is.True, "!=");
}

[Test]
public void TestEqualityById ()
{
var guid = Guid.NewGuid ();
var tnef1 = new TnefNameId (guid, 17);
var tnef2 = new TnefNameId (guid, 17);

Assert.That (tnef2.GetHashCode (), Is.EqualTo (tnef1.GetHashCode ()), "GetHashCode");
Assert.That (tnef2, Is.EqualTo (tnef1), "Equals");

Assert.That (tnef1 == tnef2, Is.True, "==");
Assert.That (tnef1 != tnef2, Is.False, "!=");
}

[Test]
public void TestEqualityByName ()
{
var guid = Guid.NewGuid ();
var tnef1 = new TnefNameId (guid, "name");
var tnef2 = new TnefNameId (guid, "name");

Assert.That (tnef2.GetHashCode (), Is.EqualTo (tnef1.GetHashCode ()), "GetHashCode");
Assert.That (tnef2, Is.EqualTo (tnef1), "Equals");

Assert.That (tnef1 == tnef2, Is.True, "==");
Assert.That (tnef1 != tnef2, Is.False, "!=");
}
}
}
71 changes: 71 additions & 0 deletions UnitTests/Tnef/TnefPropertyTagTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// TnefPropertyTagTests.cs
//
// Author: Jeffrey Stedfast <jestedfa@microsoft.com>
//
// Copyright (c) 2013-2024 .NET Foundation and Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

using System.Reflection;

using MimeKit.Tnef;

namespace UnitTests.Tnef {
[TestFixture]
public class TnefPropertyTagTests
{
[Test]
public void TestBuiltIns ()
{
foreach (var field in typeof (TnefPropertyTag).GetFields (BindingFlags.Public | BindingFlags.Static)) {
var propertyTag = (TnefPropertyTag) field.GetValue (null);

Assert.That (propertyTag.IsTnefTypeValid, Is.True, $"{field.Name}.IsTnefTypeValid");

var tag = new TnefPropertyTag (propertyTag.Id, propertyTag.TnefType);

Assert.That (tag.Id, Is.EqualTo (propertyTag.Id), $"{field.Name}.Id #1");
Assert.That (tag.TnefType, Is.EqualTo (propertyTag.TnefType), $"{field.Name}.TnefType #1");
Assert.That (tag.IsNamed, Is.EqualTo (propertyTag.IsNamed), $"{field.Name}.IsNamed #1");
Assert.That (tag.IsMultiValued, Is.EqualTo (propertyTag.IsMultiValued), $"{field.Name}.IsMultiValued #1");
Assert.That (tag.ValueTnefType, Is.EqualTo (propertyTag.ValueTnefType), $"{field.Name}.ValueTnefType #1");

Assert.That (tag.GetHashCode (), Is.EqualTo (propertyTag.GetHashCode ()), $"{field.Name}.GetHashCode #1");
Assert.That (tag, Is.EqualTo (propertyTag), $"{field.Name}.Equals #1");
Assert.That (tag == propertyTag, Is.True, $"{field.Name} == #1");
Assert.That (tag != propertyTag, Is.False, $"{field.Name} != #1");

tag = new TnefPropertyTag ((int) propertyTag);

Assert.That (tag.Id, Is.EqualTo (propertyTag.Id), $"{field.Name}.Id #2");
Assert.That (tag.TnefType, Is.EqualTo (propertyTag.TnefType), $"{field.Name}.TnefType #2");
Assert.That (tag.IsNamed, Is.EqualTo (propertyTag.IsNamed), $"{field.Name}.IsNamed #2");
Assert.That (tag.IsMultiValued, Is.EqualTo (propertyTag.IsMultiValued), $"{field.Name}.IsMultiValued #2");
Assert.That (tag.ValueTnefType, Is.EqualTo (propertyTag.ValueTnefType), $"{field.Name}.ValueTnefType #2");

Assert.That (tag.GetHashCode (), Is.EqualTo (propertyTag.GetHashCode ()), $"{field.Name}.GetHashCode #2");
Assert.That (tag, Is.EqualTo (propertyTag), $"{field.Name}.Equals #2");
Assert.That (tag == propertyTag, Is.True, $"{field.Name} == #2");
Assert.That (tag != propertyTag, Is.False, $"{field.Name} != #2");
}
}
}
}
32 changes: 0 additions & 32 deletions UnitTests/Tnef/TnefTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,37 +1018,5 @@ public void TestRichTextEml ()
Assert.That (appointment2.ContentDisposition.ModificationDate, Is.EqualTo (mtime), "ModificationDate");
Assert.That (appointment2.ContentDisposition.Size, Is.EqualTo (387453), "Size");
}

[Test]
public void TestTnefNameId ()
{
var guid = Guid.NewGuid ();
var tnef1 = new TnefNameId (guid, 17);
var tnef2 = new TnefNameId (guid, 17);

Assert.That (tnef1.Kind, Is.EqualTo (TnefNameIdKind.Id), "Kind Id");
Assert.That (tnef1.PropertySetGuid, Is.EqualTo (guid), "PropertySetGuid Id");
Assert.That (tnef1.Id, Is.EqualTo (17), "Id");

Assert.That (tnef2.GetHashCode (), Is.EqualTo (tnef1.GetHashCode ()), "GetHashCode Id");
Assert.That (tnef2, Is.EqualTo (tnef1), "Equal Id");

tnef1 = new TnefNameId (guid, "name");
Assert.That (tnef1.Kind, Is.EqualTo (TnefNameIdKind.Name), "Kind Name");
Assert.That (tnef1.PropertySetGuid, Is.EqualTo (guid), "PropertySetGuid");
Assert.That (tnef1.Name, Is.EqualTo ("name"), "Name");

Assert.That (tnef2.GetHashCode (), Is.Not.EqualTo (tnef1.GetHashCode ()), "GetHashCode Name vs Id");
Assert.That (tnef2, Is.Not.EqualTo (tnef1), "Equal Name vs Id");

tnef2 = new TnefNameId (guid, "name");
Assert.That (tnef2.GetHashCode (), Is.EqualTo (tnef1.GetHashCode ()), "GetHashCode Name");
Assert.That (tnef2, Is.EqualTo (tnef1), "Equal Name");

Assert.That (tnef1.Equals (new object ()), Is.False, "Equals (object)");

Assert.That (tnef1 == tnef2, Is.True, "==");
Assert.That (tnef1 != tnef2, Is.False, "!=");
}
}
}

0 comments on commit 84c4cae

Please sign in to comment.