Пример #1
0
 public void EnumTestWithDefault(TestEnumType value = TestEnumType.Value3)
 {
     Assert.AreNotEqual(TestEnumType.NeverSetValue, value, "Test is not setup correctly or something is really messed up");
     Actual = value;
 }
 public IQueryable <TestEnumType> EnumFunctionImportComposable(TestEnumType p1, string p2)
 {
     throw new NotImplementedException();
 }
Пример #3
0
 public EnumTestClass()
 {
     Actual = TestEnumType.NeverSetValue;
 }
			public void DoTest( string testAssemblyFile, int packerCompatiblityOptions, int enumSerializationMethod, TestEnumType enumValue, byte[] expectedPackedValue, int expectedSerializerTypeCounts )
			{
				var assembly = Assembly.LoadFrom( testAssemblyFile );
				var types = assembly.GetTypes().Where( t => typeof( IMessagePackSerializer ).IsAssignableFrom( t ) ).ToList();
				Assert.That( types.Count, Is.EqualTo( expectedSerializerTypeCounts ), String.Join( ", ", types.Select( t => t.ToString() ).ToArray() ) );

				var context = new SerializationContext( ( PackerCompatibilityOptions )packerCompatiblityOptions );

				byte[] binary;
				var serializer = Activator.CreateInstance( types.Single( t => typeof( MessagePackSerializer<TestEnumType> ).IsAssignableFrom( t ) ), context ) as MessagePackSerializer<TestEnumType>;
				binary = serializer.PackSingleObject( enumValue );
				Assert.That(
					binary,
					Is.EqualTo( expectedPackedValue ),
					"{0} != {1}",
					Binary.ToHexString( binary ),
					Binary.ToHexString( expectedPackedValue ) 
				);
			}
 public static int UdfWithNonPrimitiveParam(TestEnumType param)
 {
     throw new NotImplementedException();
 }
		private static void TestOnWorkerAppDomain( string geneartedAssemblyFilePath, PackerCompatibilityOptions packerCompatibilityOptions, EnumSerializationMethod enumSerializationMethod, TestEnumType enumValue, byte[] expectedPackedValue )
		{
			var appDomainSetUp = new AppDomainSetup() { ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase };
			var workerDomain = AppDomain.CreateDomain( "Worker", null, appDomainSetUp );
			try
			{
				var testerProxy =
					workerDomain.CreateInstanceAndUnwrap( typeof( Tester ).Assembly.FullName, typeof( Tester ).FullName ) as Tester;
				testerProxy.DoTest( geneartedAssemblyFilePath, ( int )packerCompatibilityOptions, ( int )enumSerializationMethod, enumValue, expectedPackedValue, 1 );
			}
			finally
			{
				AppDomain.Unload( workerDomain );
			}
		}
		private static void TestOnWorkerAppDomainWithCompile( string geneartedSourceFilePath, PackerCompatibilityOptions packerCompatibilityOptions, EnumSerializationMethod enumSerializationMethod, TestEnumType enumValue, byte[] expectedPackedValue )
		{
			var parameters = new CompilerParameters();
			parameters.ReferencedAssemblies.Add( typeof( GeneratedCodeAttribute ).Assembly.Location );
			parameters.ReferencedAssemblies.Add( typeof( MessagePackObject ).Assembly.Location );
			parameters.ReferencedAssemblies.Add( Assembly.GetExecutingAssembly().Location );
			var result =
				CodeDomProvider.CreateProvider( "C#" ).CompileAssemblyFromFile( parameters, geneartedSourceFilePath );

			Assert.That( result.Errors.Count, Is.EqualTo( 0 ), String.Join( Environment.NewLine, result.Output.OfType<string>().ToArray() ) );

			try
			{
				var appDomainSetUp =
					new AppDomainSetup
					{
						ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase
					};
				var workerDomain = AppDomain.CreateDomain( "Worker", null, appDomainSetUp );
				try
				{
					var testerProxy =
						workerDomain.CreateInstanceAndUnwrap( typeof( Tester ).Assembly.FullName, typeof( Tester ).FullName ) as Tester;
					testerProxy.DoTest(
						result.PathToAssembly,
						( int ) packerCompatibilityOptions,
						( int ) enumSerializationMethod,
						enumValue,
						expectedPackedValue,
						1 
					);
				}
				finally
				{
					AppDomain.Unload( workerDomain );
				}
			}
			finally
			{
				File.Delete( result.PathToAssembly );
			}
		}
Пример #8
0
 int ReturnEnumIntCast(TestEnumType testEnumType)
 {
     return((int)testEnumType);
 }
Пример #9
0
 public void GetEnumValueFromDescription_ReturnsValue(string description, TestEnumType expected, TestEnumType defaultValue)
 {
     Assert.AreEqual(expected, description.GetEnumValueFromDescription(defaultValue));
 }
Пример #10
0
 public void GetDescription_ReturnsEmptyIfNoDescription(TestEnumType value)
 {
     Assert.AreEqual(string.Empty, value.GetDescription());
 }
Пример #11
0
 public void GetDescription_ReturnsDescription(TestEnumType value, string expected)
 {
     Assert.AreEqual(expected, value.GetDescription());
 }
Пример #12
0
		int ReturnEnumIntCast(TestEnumType testEnumType) {
			return (int)testEnumType;
		}