public void InstanceIsNotAssignableToTypeReference()
    {
        ModelBase act = new ModelDerived();
        Type      t   = typeof(IModel);

        // MSTest
        MSTestAssert.IsNotInstanceOfType(act, t, "Some context");
        // Assert.IsNotInstanceOfType failed. Wrong Type:<IModel>. Actual type:<ModelDerived>. Some context

        // NUnit
        Assert.That(act, Is.Not.InstanceOf(t), () => "Some context");
        // Some context
        //  Expected: not instance of <IModel>
        //  But was: <ModelDerived>

        // XUnit does not support this case.

        // Fluent
        act.Should().NotBeAssignableTo(t, "SOME REASONS");
        // Expected act to not be assignable to IModel because SOME REASONS, but ModelDerived is.

        // Shouldly
        act.ShouldNotBeAssignableTo(t, "Some context");
        // act
        //   should not be assignable to
        // IModel
        //   but was
        // ModelDerived (63566392)
        //
        // Additional Info:
        //  Some context
    }
Exemplo n.º 2
0
 /// <summary>Assert.IsNotInstanceOfType</summary>
 public static void IsNotInstanceOf <TWrong>(this object value, string message = "")
 {
     Assert.IsNotInstanceOfType(value, typeof(TWrong), message);
 }
Exemplo n.º 3
0
        public void PydInPackage()
        {
            PythonPaths.Python27.AssertInstalled();

            var outputPath = TestData.GetTempPath();

            Console.WriteLine("Writing to: " + outputPath);

            // run the analyzer
            using (var output = ProcessOutput.RunHiddenAndCapture("Microsoft.PythonTools.Analyzer.exe",
                                                                  "/python", PythonPaths.Python27.InterpreterPath,
                                                                  "/lib", TestData.GetPath(@"TestData\PydStdLib"),
                                                                  "/version", "2.7",
                                                                  "/outdir", outputPath,
                                                                  "/indir", CompletionDB,
                                                                  "/log", "AnalysisLog.txt")) {
                output.Wait();
                Console.WriteLine("* Stdout *");
                foreach (var line in output.StandardOutputLines)
                {
                    Console.WriteLine(line);
                }
                Console.WriteLine("* Stderr *");
                foreach (var line in output.StandardErrorLines)
                {
                    Console.WriteLine(line);
                }
                Assert.AreEqual(0, output.ExitCode);
            }

            var fact  = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(new Version(2, 7));
            var paths = new List <string> {
                outputPath
            };

            paths.AddRange(Directory.EnumerateDirectories(outputPath));
            var typeDb = new PythonTypeDatabase(fact, paths);
            var module = typeDb.GetModule("Package.winsound");

            Assert.IsNotNull(module, "Package.winsound was not analyzed");
            var package = typeDb.GetModule("Package");

            Assert.IsNotNull(package, "Could not import Package");
            var member = package.GetMember(null, "winsound");

            Assert.IsNotNull(member, "Could not get member Package.winsound");
            Assert.AreSame(module, member);

            module = typeDb.GetModule("Package._testcapi");
            Assert.IsNotNull(module, "Package._testcapi was not analyzed");
            package = typeDb.GetModule("Package");
            Assert.IsNotNull(package, "Could not import Package");
            member = package.GetMember(null, "_testcapi");
            Assert.IsNotNull(member, "Could not get member Package._testcapi");
            Assert.IsNotInstanceOfType(member, typeof(CPythonMultipleMembers));
            Assert.AreSame(module, member);

            module = typeDb.GetModule("Package.select");
            Assert.IsNotNull(module, "Package.select was not analyzed");
            package = typeDb.GetModule("Package");
            Assert.IsNotNull(package, "Could not import Package");
            member = package.GetMember(null, "select");
            Assert.IsNotNull(member, "Could not get member Package.select");
            Assert.IsInstanceOfType(member, typeof(CPythonMultipleMembers));
            var mm = (CPythonMultipleMembers)member;

            AssertUtil.ContainsExactly(mm.Members.Select(m => m.MemberType),
                                       PythonMemberType.Module,
                                       PythonMemberType.Constant,
                                       PythonMemberType.Class
                                       );
            Assert.IsNotNull(mm.Members.Contains(module));

            try {
                // Only clean up if the test passed
                Directory.Delete(outputPath, true);
            } catch { }
        }
Exemplo n.º 4
0
 public static void IsNotInstanceOfType(object value, Type wrongType, string message)
 {
     Assert.IsNotInstanceOfType(value, wrongType, message, (object[])null);
 }