Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FolkerKinzel committed Jan 23, 2025
1 parent f255a28 commit 9b6a84d
Show file tree
Hide file tree
Showing 9 changed files with 311 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
namespace FolkerKinzel.VCards.BuilderParts.Tests;
using FolkerKinzel.VCards.Extensions;
using FolkerKinzel.VCards.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FolkerKinzel.VCards.BuilderParts.Tests;

[TestClass]
public class RelationBuilderTests
Expand Down Expand Up @@ -101,6 +105,26 @@ public void SetIndexesTest2()
[ExpectedException(typeof(InvalidOperationException))]
public void AddTest4() => new RelationBuilder().Add((VCard?)null);

[TestMethod]
public void AddTest5()
{
var vc = VCardBuilder.Create().Relations.Add((Relation?)null).VCard;

var relation = vc.Relations.FirstOrNull(skipEmptyItems:false);
Assert.IsNotNull(relation);
Assert.IsTrue(relation.IsEmpty);
}

[TestMethod]
public void AddTest6()
{
var vc = VCardBuilder.Create().Relations.Add((ContactID?)null).VCard;

var relation = vc.Relations.FirstOrNull(skipEmptyItems: false);
Assert.IsNotNull(relation);
Assert.IsTrue(relation.IsEmpty);
}

[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
public void ClearTest1() => new RelationBuilder().Clear();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using FolkerKinzel.VCards.Models.Properties;
using FolkerKinzel.VCards.Extensions;
using FolkerKinzel.VCards.Models.Properties;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FolkerKinzel.VCards.BuilderParts.Tests;

Expand Down Expand Up @@ -93,7 +95,16 @@ public void SetIndexesTest2()

[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
public void AddTest2() => new StringCollectionBuilder().Add(Enumerable.Empty<string>());
public void AddTest2() => new StringCollectionBuilder().Add([]);

[TestMethod]
public void AddTest3()
{
var vc = VCardBuilder.Create().NickNames.Add((string[]?)null).VCard;
var nickName = vc.NickNames.FirstOrNull(skipEmptyItems:false);
Assert.IsNotNull(nickName);
Assert.IsTrue(nickName.IsEmpty);
}

[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using FolkerKinzel.VCards.Models;
using FolkerKinzel.VCards.Extensions;
using FolkerKinzel.VCards.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FolkerKinzel.VCards.BuilderParts.Tests;

Expand Down Expand Up @@ -93,6 +95,16 @@ public void SetIndexesTest2()
[ExpectedException(typeof(InvalidOperationException))]
public void AddTest2() => new TimeZoneBuilder().Add("Europe/Berlin");

[TestMethod]
public void AddTest3()
{
var vc = VCardBuilder.Create().TimeZones.Add((string?)null!).VCard;
var timeZone = vc.TimeZones.FirstOrNull(skipEmptyItems: false);

Assert.IsNotNull(timeZone);
Assert.IsTrue(timeZone.IsEmpty);
}

[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
public void ClearTest1() => new TimeZoneBuilder().Clear();
Expand Down
85 changes: 85 additions & 0 deletions src/FolkerKinzel.VCards.Tests/Models/ContactIDTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ public class ContactIDTests
[ExpectedException(typeof(ArgumentException))]
public void CreateTest2() => ContactID.Create(new Uri("../relative", UriKind.Relative));

[TestMethod]
public void CreateTest3()
{
var id = ContactID.Create(new Uri("urn:uuid:A0CD4379-64AB-4BFA-9CEC-66DC76CA585E", UriKind.Absolute));
Assert.IsNotNull(id.Guid);
}

[TestMethod]
public void CreateTest4()
{
var id = ContactID.Create(new Uri("urn:uuid:blabla", UriKind.Absolute));
Assert.IsNotNull(id.Uri);
}

[TestMethod]
public void ToStringTest1() => Assert.IsNotNull(ContactID.Empty.ToString());

Expand Down Expand Up @@ -77,6 +91,52 @@ public void ConvertTest1()
Assert.AreEqual(test, result);
}

[TestMethod]
public void ConvertTest1b()
{
const string test = "test";
string? result = null;

result = ContactID.Create(new Uri("http://folker.com/")).Convert(test, null!, (guid, str) => str, null!);

Assert.AreEqual(test, result);
}

[TestMethod]
public void ConvertTest1c()
{
const string test = "test";
string? result = null;

result = ContactID.Create("Hi").Convert(test, null!, null!, (guid, str) => str);

Assert.AreEqual(test, result);
}

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ConvertTest2() => _ = ContactID.Create().Convert<string, string>("", null!, null!, null!);

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ConvertTest3() => _ = ContactID.Create(new Uri("http://folker.com/")).Convert<string, string>("", null!, null!, null!);

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ConvertTest4() => _ = ContactID.Create("Hi").Convert<string, string>("", null!, null!, null!);

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ConvertTest5() => _ = ContactID.Create().Convert<string>(null!, null!, null!);

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ConvertTest6() => _ = ContactID.Create(new Uri("http://folker.com/")).Convert<string>(null!, null!, null!);

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ConvertTest7() => _ = ContactID.Create("Hi").Convert<string>(null!, null!, null!);

[TestMethod]
public void EqualsTest1()
{
Expand All @@ -91,6 +151,31 @@ public void EqualsTest1()

Assert.IsFalse(o1.Equals(42));
}

[TestMethod]
public void EqualsTest2()
{
var uid1 = ContactID.Create();
ContactID? uid2 = null;
Assert.IsFalse(uid1.Equals(uid2));
}

[TestMethod]
public void EqualsTest3()
{
var uid1 = ContactID.Create("Hi");
ContactID? uid2 = ContactID.Create();
Assert.IsFalse(uid1.Equals(uid2));
}

[TestMethod]
public void EqualityTest4()
{
const string test = "http://folker.com/";
var uid1 = ContactID.Create(test);
var uid2 = ContactID.Create(new Uri(test, UriKind.Absolute));
Assert.IsTrue(uid1.Equals(uid2));
}
}


112 changes: 111 additions & 1 deletion src/FolkerKinzel.VCards.Tests/Models/DateAndOrTimeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public void ValueTest2()
Assert.IsTrue(rel.TryAsDateTimeOffset(out _));
}


[TestMethod]
public void ValueTest3()
{
Expand Down Expand Up @@ -159,6 +158,36 @@ public void ConvertTest1()

[TestMethod]
public void ConvertTest2()
{
const int expected = 42;
DateAndOrTime rel = DateTimeOffset.Now;

int result = rel.Convert(null!, s => expected, null!, null!);
Assert.AreEqual(expected, result);
}

[TestMethod]
public void ConvertTest3()
{
const int expected = 42;
DateAndOrTime rel = TimeOnly.FromDateTime(DateTime.Now);

int result = rel.Convert(null!, null!, s => expected, null!);
Assert.AreEqual(expected, result);
}

[TestMethod]
public void ConvertTest4()
{
const int expected = 42;
DateAndOrTime rel = "Midnight";

int result = rel.Convert(null!, null!, null!, s => expected);
Assert.AreEqual(expected, result);
}

[TestMethod]
public void ConvertTest5()
{
const string test = "test";
string? result = null;
Expand All @@ -168,6 +197,79 @@ public void ConvertTest2()
Assert.AreEqual(test, result);
}

[TestMethod]
public void ConvertTest6()
{
const string test = "test";
string? result = null;

result = DateAndOrTime.Create(DateTimeOffset.Now).Convert(test, null!, (guid, str) => str, null!, null!);

Assert.AreEqual(test, result);
}

[TestMethod]
public void ConvertTest7()
{
const string test = "test";
string? result = null;

result = DateAndOrTime.Create(TimeOnly.FromDateTime(DateTime.Now)).Convert(test, null!, null!, (guid, str) => str, null!);

Assert.AreEqual(test, result);
}

[TestMethod]
public void ConvertTest8()
{
const string test = "test";
string? result = null;

result = DateAndOrTime.Create("Midnight").Convert(test, null!, null!, null!, (guid, str) => str);

Assert.AreEqual(test, result);
}

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ConvertTest9()
=> _ = DateAndOrTime.Create(DateOnly.FromDateTime(DateTime.Now)).Convert<string, string>("", null!, null!, null!, null!);

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ConvertTest10()
=> _ = DateAndOrTime.Create(DateTimeOffset.Now).Convert<string, string>("", null!, null!, null!, null!);

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ConvertTest11()
=> _ = DateAndOrTime.Create(TimeOnly.FromDateTime(DateTime.Now)).Convert<string, string>("", null!, null!, null!, null!);

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ConvertTest12()
=> _ = DateAndOrTime.Create("Midnight").Convert<string, string>("", null!, null!, null!, null!);

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ConvertTest13()
=> _ = DateAndOrTime.Create(DateOnly.FromDateTime(DateTime.Now)).Convert<string>(null!, null!, null!, null!);

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ConvertTest14()
=> _ = DateAndOrTime.Create(DateTimeOffset.Now).Convert<string>(null!, null!, null!, null!);

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ConvertTest15()
=> _ = DateAndOrTime.Create(TimeOnly.FromDateTime(DateTime.Now)).Convert<string>(null!, null!, null!, null!);

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ConvertTest16()
=> _ = DateAndOrTime.Create("Midnight").Convert<string>(null!, null!, null!, null!);

[TestMethod]
public void TryAsDateTest1()
=> Assert.IsFalse(DateAndOrTime.Create(new DateTimeOffset(2, 1, 1, 17, 24, 32, TimeSpan.FromHours(1))).TryAsDateOnly(out _));
Expand Down Expand Up @@ -204,4 +306,12 @@ public void EqualsTest1()
Assert.IsTrue(daot != null);
Assert.IsFalse(daot.Equals(42));
}

[TestMethod]
public void AsStringTest1()
{
var daot = DateAndOrTime.Create(2, 4);
string str = daot.AsString(CultureInfo.InvariantCulture);
Assert.AreEqual("02/04", str);
}
}
Loading

0 comments on commit 9b6a84d

Please sign in to comment.