Upgrade to MSTest 4

This commit is contained in:
Andy Howard
2026-09-14 18:31:46 +01:00
parent de59098961
commit 7651e8824f
7 changed files with 58 additions and 62 deletions
+2 -2
View File
@@ -10,8 +10,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.10.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.10.1" />
<PackageReference Include="MSTest.TestAdapter" Version="4.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="4.4.0" />
<PackageReference Include="coverlet.collector" Version="10.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -1,4 +1,4 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sarand.Net.Standard.Base.Bus;
using Sarand.Net.Standard.Base.Utils;
using System;
@@ -21,11 +21,11 @@ namespace Sacs.UnitTests.Net.Standard.Base.Bus
public void SysId_CTR_Void ()
{
Assert.IsNotNull(new SysId());
Assert.AreEqual(new SysId().ToInt(), 0);
Assert.AreEqual(0, new SysId().ToInt());
Assert.IsTrue(String.IsNullOrEmpty(new SysId().ToString()));
Assert.IsTrue(StringUtil.IsEmpty(new SysId().ToString()));
Assert.AreEqual(new SysId().ToString(), "");
Assert.AreEqual(new SysId().ToString(), string.Empty);
Assert.AreEqual("", new SysId().ToString());
Assert.AreEqual(string.Empty, new SysId().ToString());
}
[TestMethod]
@@ -1,4 +1,4 @@
using System;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sarand.Net.Standard.Base.Utils;
@@ -168,7 +168,7 @@ namespace Sarand.UnitTests.Core.Base.Utils
// Random date between 0AD and 3000AD (or thereabouts):
DateTime date = new DateTime(random.Next(0, 365 * 3000) * TimeSpan.TicksPerDay);
//Trace.WriteLine("DateUtil_Tester.DateTime_StartOfWeek Date=" + date.Format("ddd d-MMM-yyyy") + ", Start of week=" + date.StartOfWeek().Format("ddd d-MMM-yyyy"));
Assert.AreEqual(date.StartOfWeek().Format("ddd"), "Sun");
Assert.AreEqual("Sun", date.StartOfWeek().Format("ddd"));
}
}
// DateUtil.StartOfWeek
@@ -180,7 +180,7 @@ namespace Sarand.UnitTests.Core.Base.Utils
// Random date between 0AD and 3000AD (or thereabouts):
DateTime date = new DateTime(random.Next(0, 365 * 3000) * TimeSpan.TicksPerDay);
//Trace.WriteLine("DateUtil_Tester.DateTime_StartOfWorkingWeek Date=" + date.Format("ddd d-MMM-yyyy") + ", Start of week=" + date.StartOfWorkingWeek().Format("ddd d-MMM-yyyy"));
Assert.AreEqual(date.StartOfWorkingWeek().Format("ddd"), "Mon");
Assert.AreEqual("Mon", date.StartOfWorkingWeek().Format("ddd"));
}
}
@@ -198,7 +198,7 @@ namespace Sarand.UnitTests.Core.Base.Utils
public void DateTime_DaysInMonth ()
{
DateTime dt20160723 = new DateTime(2016, 7, 23);
Assert.AreEqual(dt20160723.DaysInMonth(), 31);
Assert.AreEqual(31, dt20160723.DaysInMonth());
}
// DateUtil.EndOfMonth
[TestMethod]
@@ -217,11 +217,11 @@ namespace Sarand.UnitTests.Core.Base.Utils
DateTime dt20160723 = new DateTime(2016, 7, 23);
DateTime dt20160723172829 = new DateTime(2016, 7, 23, 17, 28, 39);
Assert.AreEqual(dt20160723.Format("dd/MM/yyyy"), "23/07/2016");
Assert.AreEqual(dt20160723.Format("dd/MM/yyyy HH:mm:ss"), "23/07/2016 00:00:00");
Assert.AreEqual("23/07/2016", dt20160723.Format("dd/MM/yyyy"));
Assert.AreEqual("23/07/2016 00:00:00", dt20160723.Format("dd/MM/yyyy HH:mm:ss"));
Assert.AreEqual(dt20160723172829.Format("dd/MM/yyyy"), "23/07/2016");
Assert.AreEqual(dt20160723172829.Format("dd/MM/yyyy HH:mm:ss"), "23/07/2016 17:28:39");
Assert.AreEqual("23/07/2016", dt20160723172829.Format("dd/MM/yyyy"));
Assert.AreEqual("23/07/2016 17:28:39", dt20160723172829.Format("dd/MM/yyyy HH:mm:ss"));
}
//-------------------------------------------------------------------
@@ -61,7 +61,7 @@ namespace Sarand.UnitTests.Core.Base.Utils
Assert.AreEqual(SaMessageLevel.Debug, EnumUtil.StartsWith<SaMessageLevel>("DEB", SaMessageLevel.Error));
Assert.AreEqual(SaMessageLevel.Debug, EnumUtil.StartsWith<SaMessageLevel>("DEBU", SaMessageLevel.Error));
Assert.AreEqual(SaMessageLevel.Debug, EnumUtil.StartsWith<SaMessageLevel>("DEBUG", SaMessageLevel.Error));
Assert.AreEqual(EnumUtil.StartsWith<SaMessageLevel>("Err", SaMessageLevel.Error), SaMessageLevel.Error);
Assert.AreEqual(SaMessageLevel.Error, EnumUtil.StartsWith<SaMessageLevel>("Err", SaMessageLevel.Error));
Assert.AreEqual(SaMessageLevel.None, EnumUtil.StartsWith<SaMessageLevel>("", SaMessageLevel.Error));
Assert.AreEqual(SaMessageLevel.Error, EnumUtil.StartsWith<SaMessageLevel>("ABC", SaMessageLevel.Error));
}
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -9,13 +9,12 @@ namespace Sarand.UnitTests.Core.Base.Utils
[TestClass]
public class StringUtil_Tester
{
//-------------------------------------------------------------------
// Data members.
// --- Data Members ---
private Random random = new Random();
//-------------------------------------------------------------------
// Properties.
//-------------------------------------------------------------------
// --- Empty and Blank Values ---
[TestMethod]
public void StringUtil_IsEmpty()
{
@@ -45,9 +44,8 @@ namespace Sarand.UnitTests.Core.Base.Utils
Assert.AreEqual(false, "Abc".IsBlank());
}
//-------------------------------------------------------------------
// Regular Expression Matching.
//-------------------------------------------------------------------
// --- Regular Expression Matching ---
[TestMethod]
public void StringUtil_IsMatch()
{
@@ -135,9 +133,8 @@ namespace Sarand.UnitTests.Core.Base.Utils
Assert.AreEqual(2, "ABCDEFGHICDEJKL".MatchesCount(new Regex("CDE")));
}
//-------------------------------------------------------------------
// Padding.
//-------------------------------------------------------------------
// --- Padding ---
[TestMethod]
public void StringUtil_PadLeft()
{
@@ -174,50 +171,49 @@ namespace Sarand.UnitTests.Core.Base.Utils
Assert.AreEqual("12300", "123".PadRight(5, '0'));
}
//-------------------------------------------------------------------
// S u b S t r i n g
//-------------------------------------------------------------------
// --- Safe Substrings ---
[TestMethod]
public void StringUtil_SubstringSafe()
{
Assert.AreEqual(StringUtil.SubstringSafe(null, 0), "");
Assert.AreEqual(StringUtil.SubstringSafe("", 0), "");
Assert.AreEqual("".SubstringSafe(0), "");
Assert.AreEqual("", StringUtil.SubstringSafe(null, 0));
Assert.AreEqual("", StringUtil.SubstringSafe("", 0));
Assert.AreEqual("", "".SubstringSafe(0));
// Right portion from start position.
Assert.AreEqual("abc".SubstringSafe(-3), "abc");
Assert.AreEqual("abc".SubstringSafe(-2), "abc");
Assert.AreEqual("abc".SubstringSafe(-1), "abc");
Assert.AreEqual("abc".SubstringSafe(0), "abc");
Assert.AreEqual("abc".SubstringSafe(1), "bc");
Assert.AreEqual("abc".SubstringSafe(2), "c");
Assert.AreEqual("abc".SubstringSafe(3), "");
Assert.AreEqual("abc", "abc".SubstringSafe(-3));
Assert.AreEqual("abc", "abc".SubstringSafe(-2));
Assert.AreEqual("abc", "abc".SubstringSafe(-1));
Assert.AreEqual("abc", "abc".SubstringSafe(0));
Assert.AreEqual("bc", "abc".SubstringSafe(1));
Assert.AreEqual("c", "abc".SubstringSafe(2));
Assert.AreEqual("", "abc".SubstringSafe(3));
// Zero length.
Assert.AreEqual(StringUtil.SubstringSafe(null, 0, 0), "");
Assert.AreEqual(StringUtil.SubstringSafe("", 0, 0), "");
Assert.AreEqual("".SubstringSafe(0, 0), "");
Assert.AreEqual("abc".SubstringSafe(-1, 0), "");
Assert.AreEqual("abc".SubstringSafe(0, 0), "");
Assert.AreEqual("abc".SubstringSafe(1, 0), "");
Assert.AreEqual("abc".SubstringSafe(2, 0), "");
Assert.AreEqual("abc".SubstringSafe(3, 0), "");
Assert.AreEqual("abc".SubstringSafe(4, 0), "");
Assert.AreEqual("", StringUtil.SubstringSafe(null, 0, 0));
Assert.AreEqual("", StringUtil.SubstringSafe("", 0, 0));
Assert.AreEqual("", "".SubstringSafe(0, 0));
Assert.AreEqual("", "abc".SubstringSafe(-1, 0));
Assert.AreEqual("", "abc".SubstringSafe(0, 0));
Assert.AreEqual("", "abc".SubstringSafe(1, 0));
Assert.AreEqual("", "abc".SubstringSafe(2, 0));
Assert.AreEqual("", "abc".SubstringSafe(3, 0));
Assert.AreEqual("", "abc".SubstringSafe(4, 0));
// Mid portion.
Assert.AreEqual("abcde".SubstringSafe(0, 3), "abc");
Assert.AreEqual("abcde".SubstringSafe(1, 3), "bcd");
Assert.AreEqual("abcde".SubstringSafe(2, 3), "cde");
Assert.AreEqual("abc", "abcde".SubstringSafe(0, 3));
Assert.AreEqual("bcd", "abcde".SubstringSafe(1, 3));
Assert.AreEqual("cde", "abcde".SubstringSafe(2, 3));
// Excessive length.
Assert.AreEqual("abcde".SubstringSafe(-1, 12), "abcde");
Assert.AreEqual("abcde".SubstringSafe(0, 12), "abcde");
Assert.AreEqual("abcde".SubstringSafe(1, 12), "bcde");
Assert.AreEqual("abcde".SubstringSafe(2, 12), "cde");
Assert.AreEqual("abcde".SubstringSafe(3, 12), "de");
Assert.AreEqual("abcde".SubstringSafe(4, 12), "e");
Assert.AreEqual("abcde".SubstringSafe(5, 12), "");
Assert.AreEqual("abcde", "abcde".SubstringSafe(-1, 12));
Assert.AreEqual("abcde", "abcde".SubstringSafe(0, 12));
Assert.AreEqual("bcde", "abcde".SubstringSafe(1, 12));
Assert.AreEqual("cde", "abcde".SubstringSafe(2, 12));
Assert.AreEqual("de", "abcde".SubstringSafe(3, 12));
Assert.AreEqual("e", "abcde".SubstringSafe(4, 12));
Assert.AreEqual("", "abcde".SubstringSafe(5, 12));
}
//-------------------------------------------------------------------
// --- The End ---
}
}