Exemple #1
0
        private static bool RunSingleTest(MethodInfo method)
        {
            Console.WriteLine($"Running {method.Name}...");
            try
            {
                BinderTestAttribute attribute = method.GetCustomAttribute <BinderTestAttribute>();
                if (!string.IsNullOrEmpty(attribute.TestSetup))
                {
                    MethodInfo setupMethod = method.DeclaringType
                                             .GetMethod(attribute.TestSetup, BindingFlags.Public | BindingFlags.Static);
                    Assert.IsTrue(setupMethod != null);
                    setupMethod.Invoke(null, new object[0]);
                }

                Func <BindOperation> func = (Func <BindOperation>)method.CreateDelegate(typeof(Func <BindOperation>));
                using (var listener = new BinderEventListener())
                {
                    BindOperation expected = func();
                    ValidateSingleBind(listener, expected.AssemblyName.Name, expected);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Test {method.Name} failed: {e}");
                return(false);
            }

            return(true);
        }
Exemple #2
0
        private static void ValidateSingleBind(BinderEventListener listener, AssemblyName assemblyName, BindOperation expected)
        {
            BindOperation[] binds = listener.WaitAndGetEventsForAssembly(assemblyName);
            Assert.True(binds.Length == 1, $"Bind event count for {assemblyName} - expected: 1, actual: {binds.Length}");
            BindOperation actual = binds[0];

            Helpers.ValidateBindOperation(expected, actual);
        }
        public static void PlatformAssembly_DefaultALC()
        {
            Console.WriteLine($"Running {nameof(PlatformAssembly_DefaultALC)}...");
            using (var listener = new BinderEventListener())
            {
                string   assemblyName = "System.Xml";
                Assembly asm          = Assembly.Load(assemblyName);

                BindOperation[] binds = listener.WaitAndGetEventsForAssembly(assemblyName);
                Assert.True(binds.Length == 1, $"Bind count for {assemblyName} - expected: 1, actual: {binds.Length}");
                BindOperation bind = binds[0];
                Assert.True(bind.Success, $"Expected bind for {assemblyName} to succeed");
            }
        }
Exemple #4
0
        private static void ValidateSingleBind(BinderEventListener listener, string assemblyName, BindOperation expected)
        {
            BindOperation[] binds = listener.WaitAndGetEventsForAssembly(assemblyName);
            Assert.IsTrue(binds.Length == 1, $"Bind event count for {assemblyName} - expected: 1, actual: {binds.Length}");
            BindOperation actual = binds[0];

            ValidateAssemblyName(expected.AssemblyName, actual.AssemblyName, nameof(BindOperation.AssemblyName));
            Assert.AreEqual(expected.AssemblyPath ?? string.Empty, actual.AssemblyPath, $"Unexpected value for {nameof(BindOperation.AssemblyPath)} on event");
            Assert.AreEqual(expected.AssemblyLoadContext, actual.AssemblyLoadContext, $"Unexpected value for {nameof(BindOperation.AssemblyLoadContext)} on event");
            ValidateAssemblyName(expected.RequestingAssembly, actual.RequestingAssembly, nameof(BindOperation.RequestingAssembly));
            Assert.AreEqual(expected.RequestingAssemblyLoadContext ?? string.Empty, actual.RequestingAssemblyLoadContext, $"Unexpected value for {nameof(BindOperation.RequestingAssemblyLoadContext)} on event");

            Assert.AreEqual(expected.Success, actual.Success, $"Unexpected value for {nameof(BindOperation.Success)} on event");
            Assert.AreEqual(expected.ResultAssemblyPath ?? string.Empty, actual.ResultAssemblyPath, $"Unexpected value for {nameof(BindOperation.ResultAssemblyPath)} on event");
            Assert.AreEqual(expected.Cached, actual.Cached, $"Unexpected value for {nameof(BindOperation.Cached)} on event");
            ValidateAssemblyName(expected.ResultAssemblyName, actual.ResultAssemblyName, nameof(BindOperation.ResultAssemblyName));
        }
        public static void NonExistentAssembly_DefaultALC()
        {
            Console.WriteLine($"Running {nameof(NonExistentAssembly_DefaultALC)}...");
            using (var listener = new BinderEventListener())
            {
                string assemblyName = "DoesNotExist";
                try
                {
                    Assembly.Load(assemblyName);
                }
                catch { }

                BindOperation[] binds = listener.WaitAndGetEventsForAssembly(assemblyName);
                Assert.True(binds.Length == 1, $"Bind event count for {assemblyName} - expected: 1, actual: {binds.Length}");
                BindOperation bind = binds[0];
                Assert.False(bind.Success, $"Expected bind for {assemblyName} to fail");
            }
        }
Exemple #6
0
        private static bool RunSingleTest(MethodInfo method)
        {
            Console.WriteLine($"[{DateTime.Now:T}] Running {method.Name}...");
            try
            {
                BinderTestAttribute attribute = method.GetCustomAttribute <BinderTestAttribute>();
                if (!string.IsNullOrEmpty(attribute.TestSetup))
                {
                    MethodInfo setupMethod = method.DeclaringType
                                             .GetMethod(attribute.TestSetup, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
                    Assert.True(setupMethod != null);
                    setupMethod.Invoke(null, new object[0]);
                }

                var loadsToTrack = new string[]
                {
                    Assembly.GetExecutingAssembly().GetName().Name,
                    DependentAssemblyName,
                    $"{DependentAssemblyName}.resources",
                    SubdirectoryAssemblyName,
                    $"{SubdirectoryAssemblyName}.resources",
                };
                if (attribute.AdditionalLoadsToTrack != null)
                {
                    loadsToTrack = loadsToTrack.Union(attribute.AdditionalLoadsToTrack).ToArray();
                }

                Func <BindOperation> func = (Func <BindOperation>)method.CreateDelegate(typeof(Func <BindOperation>));
                using (var listener = new BinderEventListener(loadsToTrack))
                {
                    BindOperation expected = func();
                    ValidateSingleBind(listener, expected.AssemblyName, expected);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Test {method.Name} failed: {e}");
                return(false);
            }

            return(true);
        }