diff --git a/starsky/starskytest/starsky.foundation.search/Services/SearchServiceTest.cs b/starsky/starskytest/starsky.foundation.search/Services/SearchServiceTest.cs index b1796518f4..3743c87aa7 100644 --- a/starsky/starskytest/starsky.foundation.search/Services/SearchServiceTest.cs +++ b/starsky/starskytest/starsky.foundation.search/Services/SearchServiceTest.cs @@ -1042,7 +1042,6 @@ public async Task SearchService_Search_Percentage() [TestMethod] - [ExpectedException(typeof(ArgumentException))] public async Task SearchService_Search_ToLong_ArgumentException() { const string longTestText = @@ -1084,7 +1083,7 @@ public async Task SearchService_Search_ToLong_ArgumentException() " elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Lorem ipsum dolor sit" + " amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna "; - await _search.Search(longTestText); + await Assert.ThrowsExceptionAsync(() => _search.Search(longTestText)); // Expect ArgumentException } } diff --git a/starsky/starskytest/starsky.foundation.storage/Exceptions/DecodingExceptionTest.cs b/starsky/starskytest/starsky.foundation.storage/Exceptions/DecodingExceptionTest.cs index 0ce042a390..2633ec311d 100644 --- a/starsky/starskytest/starsky.foundation.storage/Exceptions/DecodingExceptionTest.cs +++ b/starsky/starskytest/starsky.foundation.storage/Exceptions/DecodingExceptionTest.cs @@ -5,38 +5,46 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using starsky.foundation.storage.Exceptions; -namespace starskytest.starsky.foundation.storage.Exceptions +namespace starskytest.starsky.foundation.storage.Exceptions; + +[TestClass] +public sealed class DecodingExceptionTest { - [TestClass] - public sealed class DecodingExceptionTest + [TestMethod] + public void DecodingException() { - [TestMethod] - [ExpectedException(typeof(DecodingException))] - public void DecodingException() - { + // Arrange #pragma warning disable SYSLIB0050 - var info = new SerializationInfo(typeof(Exception), - new FormatterConverter()); - info.AddValue("Message", ""); - info.AddValue("InnerException", new Exception()); - info.AddValue("HelpURL", ""); - info.AddValue("StackTraceString", ""); - info.AddValue("RemoteStackTraceString", ""); - info.AddValue("HResult", 1); - info.AddValue("Source", ""); - - var ctor = - typeof(DecodingException).GetConstructors(BindingFlags.Instance | - BindingFlags.NonPublic | BindingFlags.InvokeMethod).FirstOrDefault(); - var instance = - ( DecodingException? ) ctor?.Invoke(new object[] - { - info, - new StreamingContext(StreamingContextStates.All) - }); - - throw instance!; + var info = new SerializationInfo(typeof(Exception), new FormatterConverter()); #pragma warning restore SYSLIB0050 + info.AddValue("Message", ""); + info.AddValue("InnerException", new Exception()); + info.AddValue("HelpURL", ""); + info.AddValue("StackTraceString", ""); + info.AddValue("RemoteStackTraceString", ""); + info.AddValue("HResult", 1); + info.AddValue("Source", ""); + + var ctor = typeof(DecodingException).GetConstructors(BindingFlags.Instance | + BindingFlags.NonPublic) + .FirstOrDefault(); + + if (ctor == null) + { + Assert.Fail("No suitable constructor found for DecodingException."); } + + // Act & Assert + var ex = Assert.ThrowsException(() => + { + var instance = (DecodingException)ctor.Invoke(new object[] + { + info, new StreamingContext(StreamingContextStates.All) + }); + throw instance; + }); + + // Optionally verify the exception message or other properties + Assert.IsTrue(ex.ToString().Contains("System.Exception")); } }