当前位置: 首页>>代码示例>>C#>>正文


C# TestContext.Assert方法代码示例

本文整理汇总了C#中TestContext.Assert方法的典型用法代码示例。如果您正苦于以下问题:C# TestContext.Assert方法的具体用法?C# TestContext.Assert怎么用?C# TestContext.Assert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TestContext的用法示例。


在下文中一共展示了TestContext.Assert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnCertificateSelectionCallback

		protected override IClientCertificate OnCertificateSelectionCallback (
			TestContext ctx, string targetHost, ICertificate[] localCertificates,
			ICertificate remoteCertificate, string[] acceptableIssuers)
		{
			LogDebug (ctx, 1, "CertificateSelectionCallback", renegotiationStartedTcs.Task.Status, targetHost,
				localCertificates != null ? localCertificates.Length : -1, remoteCertificate,
				acceptableIssuers != null ? acceptableIssuers.Length : -1);
			if (renegotiationStartedTcs.Task.IsCompleted) {
				ctx.Assert (remoteCertificate, Is.Not.Null, "have remote certificate");
				return ResourceManager.MonkeyCertificate;
			} else {
				ctx.Assert (remoteCertificate, Is.Null, "first call");
				return null;
			}
		}
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:15,代码来源:RenegotiationInstrumentConnectionHandler.cs

示例2: ExpectAlert

		public static void ExpectAlert (TestContext ctx, Task t, AlertDescription expectedAlert, string message)
		{
			ctx.Assert (t.IsFaulted, Is.True, "#1:" + message);
			var baseException = t.Exception.GetBaseException ();
			if (baseException is AggregateException) {
				var aggregate = baseException as AggregateException;
				ctx.Assert (aggregate.InnerExceptions.Count, Is.EqualTo (2), "#2a:" + message);
				var authExcType = aggregate.InnerExceptions [0].GetType ();
				ctx.Assert (authExcType.FullName, Is.EqualTo ("System.Security.Authentication.AuthenticationException"), "#2b:" + message);
				baseException = aggregate.InnerExceptions [1];
			}
			// OpenSsl can't report TlsException's like Mono.
			if (baseException.GetType ().FullName.Equals ("Mono.Security.NewTls.TestProvider.NativeOpenSslException"))
				return;
			ctx.Assert (baseException, Is.InstanceOf<TlsException> (), "#2:" + message);
			var alert = ((TlsException)baseException).Alert;
			ctx.Assert (alert.Level, Is.EqualTo (AlertLevel.Fatal), "#3:" + message);
			ctx.Assert (alert.Description, Is.EqualTo (expectedAlert), "#4:" + message);
		}
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:19,代码来源:MonoConnectionHelper.cs

示例3: TestDecryptWithInvalidPadding

		public void TestDecryptWithInvalidPadding (TestContext ctx, [TestHost] IEncryptionTestHost host)
		{
			var input = GetBuffer (ExtraPaddingResult);

			var modified = new TlsBuffer (input.Size);
			modified.Write (input.Buffer);

			var theOffset = modified.Size - (2 * host.BlockSize) - 5;
			modified.Buffer [theOffset] ^= 0x01;

			input = new BufferOffsetSize (modified.Buffer, 0, modified.Size);

			try {
				host.Decrypt (input);
				ctx.AssertFail ("#1");
			} catch (Exception ex) {
				ctx.Assert (ex, Is.InstanceOf<TlsException> (), "#2");
				var tlsEx = (TlsException)ex;
				ctx.Assert (tlsEx.Alert.Level, Is.EqualTo (AlertLevel.Fatal), "#3");
				ctx.Assert (tlsEx.Alert.Description, Is.EqualTo (AlertDescription.BadRecordMAC), "#4");
			}
		}
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:22,代码来源:TestCbcBlockCipher.cs

示例4: TestDecryptWithExtraPadding

		public void TestDecryptWithExtraPadding (TestContext ctx, [TestHost] IEncryptionTestHost host)
		{
			var input = GetBuffer (ExtraPaddingResult);
			var output = host.Decrypt (input);

			var data = GetBuffer (TestDataName);

			ctx.Assert (output.Size, Is.EqualTo (data.Size), "#1");
			ctx.Assert (TlsBuffer.Compare (output, data), "#2");
		}
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:10,代码来源:TestCbcBlockCipher.cs

示例5: TestEncryptWithExtraPadding

		public void TestEncryptWithExtraPadding (TestContext ctx, [TestHost] IEncryptionTestHost host)
		{
			var buffer = GetBuffer (TestDataName);
			IBufferOffsetSize output;
			try {
				host.Parameters.ExtraPaddingBlocks = 13;
				output = host.Encrypt (buffer);
			} finally {
				host.Parameters.ExtraPaddingBlocks = 0;
			}

			var extraPadding = 13 * 16;
			ctx.Assert (output, Is.Not.Null, "#1");
			ctx.Assert (output.Size, Is.GreaterThanOrEqualTo (buffer.Size + extraPadding + host.MinExtraEncryptedBytes), "#2");
			ctx.Assert (output.Size, Is.LessThanOrEqualTo (buffer.Size + extraPadding + host.MaxExtraEncryptedBytes), "#3");
			WriteAndCheckOutput (ctx, ExtraPaddingResult, output);
		}
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:17,代码来源:TestCbcBlockCipher.cs

示例6: TestDecryptData13

		public void TestDecryptData13 (TestContext ctx, [TestHost] IEncryptionTestHost host)
		{
			var input = GetBuffer (Data13Result);
			var output = host.Decrypt (input);

			ctx.Assert (output.Size, Is.EqualTo (13), "#1");
			ctx.Assert (TlsBuffer.Compare (output, GetBuffer (TestDataName, 0, 13)), "#2");
		}
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:8,代码来源:TestCbcBlockCipher.cs

示例7: RunMainLoopBlob

		async Task RunMainLoopBlob (TestContext ctx, HandshakeInstrumentType type, CancellationToken cancellationToken)
		{
			var expected = Instrumentation.GetTextBuffer (type).GetBuffer ();

			var buffer = new byte [4096];
			int ret = await Server.Stream.ReadAsync (buffer, 0, buffer.Length);
			ctx.Assert (ret, Is.EqualTo (expected.Length));

			buffer = new BufferOffsetSize (buffer, 0, ret).GetBuffer ();

			ctx.Assert (buffer, Is.EqualTo (expected), "blob");

			await Shutdown (ctx, SupportsCleanShutdown, true, cancellationToken);
		}
开发者ID:peterdocter,项目名称:mono-tls,代码行数:14,代码来源:ConnectionInstrumentTestRunner.cs

示例8: TestHelloWorld

		public void TestHelloWorld (TestContext ctx, [TestHost] IEncryptionTestHost host)
		{
			var buffer = GetBuffer (HelloWorldName);
			var output = host.Encrypt (buffer);
			ctx.Assert (output, Is.Not.Null, "#1");
			ctx.Assert (output.Size, Is.GreaterThanOrEqualTo (buffer.Size + host.MinExtraEncryptedBytes), "#2");
			ctx.Assert (output.Size, Is.LessThanOrEqualTo (buffer.Size + host.MaxExtraEncryptedBytes), "#3");
			WriteAndCheckOutput (ctx, HelloWorldResult, output);
		}
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:9,代码来源:TestCbcBlockCipher.cs

示例9: TestInputOffset

		public void TestInputOffset (TestContext ctx, [TestHost] IEncryptionTestHost host)
		{
			var hello = GetBuffer (HelloWorldName);
			var input = new TlsBuffer (hello.Size + MagicDataSize + MagicData2Size);
			input.Write (GetField (MagicDataName));
			var startPos = input.Position;
			input.Write (hello);
			input.Write (GetBuffer (MagicData2Name));

			var output = host.Encrypt (new BufferOffsetSize (input.Buffer, startPos, hello.Size));
			ctx.Assert (output, Is.Not.Null, "#1");
			ctx.Assert (output.Size, Is.GreaterThanOrEqualTo (hello.Size + host.MinExtraEncryptedBytes), "#2");
			ctx.Assert (output.Size, Is.LessThanOrEqualTo (hello.Size + host.MaxExtraEncryptedBytes), "#2");
			CheckOutput (ctx, HelloWorldResult, output);
		}
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:15,代码来源:TestCbcBlockCipher.cs

示例10: TestMultiFragment

		public void TestMultiFragment (TestContext ctx, [TestHost] IEncryptionTestHost host)
		{
			// Padding will push us above the maximum fragment size.
			var size = MAX_FRAGMENT_SIZE - host.MinExtraEncryptedBytes + 1;
			var encryptedSize = host.GetEncryptedSize (size);
			ctx.Assert (encryptedSize, Is.GreaterThan (MAX_FRAGMENT_SIZE));

			var buffer = GetBuffer (MultiFragmentName, 0, size);
			var output = new TlsStream ();
			host.EncryptRecord (ContentType.ApplicationData, buffer, output);
			ctx.Assert (output.Position, Is.GreaterThanOrEqualTo (size + 2 * host.MinExtraEncryptedBytes + 10), "#2a");
			ctx.Assert (output.Position, Is.LessThanOrEqualTo (size + 2 * host.MaxExtraEncryptedBytes + 10), "#2b");
			ctx.Assert (output.Offset, Is.EqualTo (0), "#3");

			output.Position = 0;
			ctx.Assert (output.ReadByte (), Is.EqualTo ((byte)ContentType.ApplicationData), "#4a");
			ctx.Assert (output.ReadInt16 (), Is.EqualTo ((short)TlsProtocolCode.Tls12), "#4b");

			var firstChunkSize = (int)output.ReadInt16 ();
			ctx.Assert (firstChunkSize, Is.GreaterThanOrEqualTo (MAX_FRAGMENT_SIZE - host.MaxExtraEncryptedBytes - 1), "#4c");
			ctx.Assert (firstChunkSize, Is.LessThanOrEqualTo (MAX_FRAGMENT_SIZE), "#4d");

			output.Position += firstChunkSize;

			ctx.Assert (output.ReadByte (), Is.EqualTo ((byte)ContentType.ApplicationData), "#5a");
			ctx.Assert (output.ReadInt16 (), Is.EqualTo ((short)TlsProtocolCode.Tls12), "#5b");

			var secondChunkSize = (int)output.ReadInt16 ();
			ctx.Assert (secondChunkSize, Is.GreaterThanOrEqualTo (encryptedSize - firstChunkSize + host.MinExtraEncryptedBytes), "#5c");
			ctx.Assert (secondChunkSize, Is.LessThanOrEqualTo (encryptedSize - firstChunkSize + host.MaxExtraEncryptedBytes), "#5d");
			output.Position += secondChunkSize;

			WriteAndCheckOutput (ctx, MultiFragmentResult, new BufferOffsetSize (output.Buffer, 0, output.Position));
		}
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:34,代码来源:TestCbcBlockCipher.cs

示例11: TestRecord

		public void TestRecord (TestContext ctx, [TestHost] IEncryptionTestHost host)
		{
			var buffer = GetBuffer (TestDataName);

			var output = new TlsStream ();
			host.EncryptRecord (ContentType.ApplicationData, buffer, output);

			ctx.Assert (output.Position, Is.GreaterThanOrEqualTo (buffer.Size + host.MinExtraEncryptedBytes + 5), "#2a");
			ctx.Assert (output.Position, Is.LessThanOrEqualTo (buffer.Size + host.MaxExtraEncryptedBytes + 5), "#2b");

			var encryptedSize = host.GetEncryptedSize (buffer.Size);
			ctx.Assert (output.Position, Is.EqualTo (encryptedSize + 5), "#2c");

			output.Position = 0;
			ctx.Assert (output.ReadByte (), Is.EqualTo ((byte)ContentType.ApplicationData), "#4a");
			ctx.Assert (output.ReadInt16 (), Is.EqualTo ((short)TlsProtocolCode.Tls12), "#4b");
			ctx.Assert (output.ReadInt16 (), Is.EqualTo ((short)encryptedSize), "#4c");
			output.Position += encryptedSize;

			WriteAndCheckOutput (ctx, RecordResult, new BufferOffsetSize (output.Buffer, 0, output.Position));
		}
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:21,代码来源:TestCbcBlockCipher.cs

示例12: TestData13

		public void TestData13 (TestContext ctx, [TestHost] IEncryptionTestHost host)
		{
			var buffer = GetBuffer (TestDataName, 0, 13);
			var output = host.Encrypt (buffer);
			ctx.Assert (output, Is.Not.Null, "#1");
			ctx.Assert (output.Size, Is.EqualTo (64), "#2");
			WriteAndCheckOutput (ctx, Data13Result, output);
		}
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:8,代码来源:TestCbcBlockCipher.cs

示例13: TestData11

		public void TestData11 (TestContext ctx, [TestHost] IEncryptionTestHost host)
		{
			// This will use zero padding.
			var buffer = GetBuffer (TestDataName, 0, 11);
			var output = host.Encrypt (buffer);
			ctx.Assert (output, Is.Not.Null, "#1");
			ctx.Assert (output.Size, Is.EqualTo (48), "#2");
			WriteAndCheckOutput (ctx, Data11Result, output);
		}
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:9,代码来源:TestCbcBlockCipher.cs

示例14: OnRun

		protected override void OnRun (TestContext ctx, CancellationToken cancellationToken)
		{
			if (Parameters.ExpectedCipher != null) {
				ctx.Assert (Client.SupportsConnectionInfo, "client supports connection info");
				ctx.Assert (Server.SupportsConnectionInfo, "server supports connection info");

				var clientInfo = Client.GetConnectionInfo ();
				var serverInfo = Server.GetConnectionInfo ();

				if (ctx.Expect (clientInfo, Is.Not.Null, "client connection info"))
					ctx.Expect (clientInfo.CipherCode, Is.EqualTo (Parameters.ExpectedCipher.Value), "client cipher");
				if (ctx.Expect (serverInfo, Is.Not.Null, "server connection info"))
					ctx.Expect (serverInfo.CipherCode, Is.EqualTo (Parameters.ExpectedCipher.Value), "server cipher");
			}

			if (Parameters.ProtocolVersion != null) {
				ctx.Expect (Client.ProtocolVersion, Is.EqualTo (Parameters.ProtocolVersion), "client protocol version");
				ctx.Expect (Server.ProtocolVersion, Is.EqualTo (Parameters.ProtocolVersion), "server protocol version");
			}

			if (Server.Provider.SupportsSslStreams && (Parameters.ServerFlags & ServerFlags.RequireClientCertificate) != 0) {
				ctx.Expect (Server.SslStream.HasRemoteCertificate, "has remote certificate");
				ctx.Expect (Server.SslStream.IsMutuallyAuthenticated, "is mutually authenticated");
			}

			base.OnRun (ctx, cancellationToken);
		}
开发者ID:peterdocter,项目名称:mono-tls,代码行数:27,代码来源:MonoClientAndServerTestRunner.cs

示例15: TestDecryptWithInvalidPadding2

		public void TestDecryptWithInvalidPadding2 (TestContext ctx, [TestHost] IEncryptionTestHost host)
		{
			var input = GetBuffer (Data11Result);

			var modified = new TlsBuffer (input.Size);
			modified.Write (input.Buffer);

			// Flip a bit in the last byte, this will affect the padding size.
			modified.Buffer [modified.Size - 1] ^= 0x01;

			input = new BufferOffsetSize (modified.Buffer, 0, modified.Size);

			try {
				host.Decrypt (input);
				ctx.AssertFail ("#1");
			} catch (Exception ex) {
				ctx.Assert (ex, Is.InstanceOf<TlsException> (), "#2");
				var tlsEx = (TlsException)ex;
				ctx.Assert (tlsEx.Alert.Level, Is.EqualTo (AlertLevel.Fatal), "#3");
				ctx.Assert (tlsEx.Alert.Description, Is.EqualTo (AlertDescription.BadRecordMAC), "#4");
			}
		}
开发者ID:VimalKumarS,项目名称:mono-tls,代码行数:22,代码来源:TestCbcBlockCipher.cs


注:本文中的TestContext.Assert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。