using NUnit.Framework; using System.Collections.Generic; [TestFixture] public class TestClass { [Test] public void TestMaxValueInList() { Listnums = new List { 3, 7, 2, 9, 5 }; int maxVal = nums.Max(); Assert.AreEqual(9, maxVal); } }
[Test] public void TestMaxValueInEmptyList() { ListThis example tests what happens when List Max is called on an empty list. It uses an NUnit assertion to check that an exception is thrown, specifically an InvalidOperationException. Overall, List Max is a useful method provided by the NUnit.Framework library for finding the maximum value in a list of integers.emptyList = new List (); Assert.Throws (() => emptyList.Max()); }