Skip to content

Commit

Permalink
Add some test on request type.
Browse files Browse the repository at this point in the history
  • Loading branch information
ngraziano committed Nov 19, 2024
1 parent fefdc83 commit 62f553a
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion RTSP.Tests/Messages/RTSPMessageTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
using NUnit.Framework.Internal.Builders;

namespace Rtsp.Messages.Tests
{
Expand Down Expand Up @@ -50,5 +55,32 @@ public void SeqWrite()

Assert.That(oneMessage.Headers["CSeq"], Is.EqualTo("123"));
}
#if NET8_0_OR_GREATER
[Test]
[GenericTestCase<RtspRequestOptions>(RtspRequest.RequestType.OPTIONS)]
[GenericTestCase<RtspRequestDescribe>(RtspRequest.RequestType.DESCRIBE)]
[GenericTestCase<RtspRequestSetup>(RtspRequest.RequestType.SETUP)]
[GenericTestCase<RtspRequestPlay>(RtspRequest.RequestType.PLAY)]
[GenericTestCase<RtspRequestPause>(RtspRequest.RequestType.PAUSE)]
[GenericTestCase<RtspRequestTeardown>(RtspRequest.RequestType.TEARDOWN)]
[GenericTestCase<RtspRequestGetParameter>(RtspRequest.RequestType.GET_PARAMETER)]
[GenericTestCase<RtspRequestAnnounce>(RtspRequest.RequestType.ANNOUNCE)]
[GenericTestCase<RtspRequestRecord>(RtspRequest.RequestType.RECORD)]
public void CheckRequestType<T>(RtspRequest.RequestType expectedType) where T : RtspRequest, new()
{
RtspRequest onMessage = new T();
Assert.That(onMessage.RequestTyped, Is.EqualTo(expectedType));
}

[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
private class GenericTestCaseAttribute<T>(params object[] arguments) : TestCaseAttribute(arguments), ITestBuilder
{
IEnumerable<TestMethod> ITestBuilder.BuildFrom(IMethodInfo method, Test? suite)
{
var testedMethod = method.IsGenericMethodDefinition ? method.MakeGenericMethod(typeof(T)) : method;
return BuildFrom(testedMethod, suite);
}
}
#endif
}
}

0 comments on commit 62f553a

Please # to comment.