AreEqual() public static method

public static AreEqual ( object objA, object objB ) : bool
objA object
objB object
return bool
Ejemplo n.º 1
0
        public void CheckObsoleteGenerateFunction()
        {
            var path = PythonPaths.Versions.LastOrDefault(p => p != null && p.IsCPython);

            path.AssertInstalled();

            var factory = InterpreterFactoryCreator.CreateInterpreterFactory(
                new InterpreterConfiguration(
                    path.Id,
                    "Test Interpreter",
                    path.PrefixPath,
                    path.InterpreterPath,
                    path.InterpreterPath,
                    path.LibPath,
                    "PYTHONPATH",
                    path.Isx64 ? ProcessorArchitecture.Amd64 : ProcessorArchitecture.X86,
                    path.Version.ToVersion()
                    ),
                new InterpreterFactoryCreationOptions {
                WatchLibraryForNewModules = false
            }
                );

            var tcs        = new TaskCompletionSource <int>();
            var beforeProc = Process.GetProcessesByName("Microsoft.PythonTools.Analyzer");

            var request = new PythonTypeDatabaseCreationRequest {
                Factory       = factory,
                OutputPath    = TestData.GetTempPath(randomSubPath: true),
                SkipUnchanged = true,
                OnExit        = tcs.SetResult
            };

            Console.WriteLine("OutputPath: {0}", request.OutputPath);

#pragma warning disable 618
            PythonTypeDatabase.Generate(request);
#pragma warning restore 618

            int expected = 0;

            if (!tcs.Task.Wait(TimeSpan.FromMinutes(1.0)))
            {
                var proc = Process.GetProcessesByName("Microsoft.PythonTools.Analyzer")
                           .Except(beforeProc)
                           .ToArray();

                // Ensure we actually started running
                Assert.AreNotEqual(0, proc.Length, "Process is not running");

                expected = -1;

                // Kill the process
                foreach (var p in proc)
                {
                    Console.WriteLine("Killing process {0}", p.Id);
                    p.Kill();
                }

                Assert.IsTrue(tcs.Task.Wait(TimeSpan.FromMinutes(1.0)), "Process did not die");
            }

            Assert.AreEqual(expected, tcs.Task.Result, "Incorrect exit code");
        }
Ejemplo n.º 2
0
        public void ToHtmlUnorderedListTest()
        {
            dynamic expando = new ExpandoObject();

            expando.Key1      = "Value1";
            expando.Key2      = new ExpandoObject();
            expando.Key2.Key1 = "Value1";
            expando.Key2.Key2 = "Value2";
            expando.Key2.Key3 = "Value3";

            var expected = @"
<div>System.Dynamic.ExpandoObject</div>
<ul>
    <li><strong>Key1</strong> = Value1</li>
    <li><strong>Key2</strong> = System.Dynamic.ExpandoObject
        <div>System.Dynamic.ExpandoObject</div>
        <ul>
            <li><strong>Key1</strong> = Value1</li>
            <li><strong>Key2</strong> = Value2</li>
            <li><strong>Key3</strong> = Value3</li>
        </ul>
    </li>
</ul>

";

            expected = Regex.Replace(expected, "\r?\n", Environment.NewLine);

            Assert.AreEqual(expected, ((ExpandoObject)expando).ToHtmlUnorderedList(true, true));

            var     list     = new List <ExpandoObject>();
            dynamic expando1 = new ExpandoObject();

            expando1.Key1 = "Value1";

            dynamic expando2 = new ExpandoObject();

            expando2.Key2 = "Value2";

            list.Add(expando1);
            list.Add(expando2);

            expando.Key4 = list;

            expected = @"
<div>System.Dynamic.ExpandoObject</div>
<ul>
    <li><strong>Key1</strong> = Value1</li>
    <li><strong>Key2</strong> = System.Dynamic.ExpandoObject
        <div>System.Dynamic.ExpandoObject</div>
        <ul>
            <li><strong>Key1</strong> = Value1</li>
            <li><strong>Key2</strong> = Value2</li>
            <li><strong>Key3</strong> = Value3</li>
        </ul>
    </li>
    <li><strong>Key4</strong> = System.Collections.Generic.List`1[System.Dynamic.ExpandoObject]
        <div>System.Collections.Generic.List`1[System.Dynamic.ExpandoObject]</div>
        <ol>
            <li>
                <div>System.Dynamic.ExpandoObject</div>
                <ul>
                    <li><strong>Key1</strong> = Value1</li>
                </ul>
            </li>
            <li>
                <div>System.Dynamic.ExpandoObject</div>
                <ul>
                    <li><strong>Key2</strong> = Value2</li>
                </ul>
            </li>
        </ol>
    </li>
</ul>

";

            expected = Regex.Replace(expected, "\r?\n", Environment.NewLine);
            Assert.AreEqual(expected, ((ExpandoObject)expando).ToHtmlUnorderedList(true, true));
        }
Ejemplo n.º 3
0
        public async Task TestMultiClusterConf_3_3()
        {
            // use a random global service id for testing purposes
            var globalserviceid = Guid.NewGuid();

            // use two clusters
            var clusterA = "A";
            var clusterB = "B";

            Action <ClusterConfiguration> configcustomizer = (ClusterConfiguration c) =>
            {
                c.Globals.DefaultMultiCluster = new List <string>(2)
                {
                    clusterA, clusterB
                };

                // logging
                foreach (var o in c.Overrides)
                {
                    o.Value.TraceLevelOverrides.Add(new Tuple <string, Severity>("Runtime.MultiClusterOracle", Severity.Verbose));
                }
            };

            // create cluster A and clientA
            NewGeoCluster(globalserviceid, clusterA, 3, configcustomizer);
            var clientA = NewClient <ClientWrapper>(clusterA, 0);
            var portA0  = Clusters[clusterA].Silos[0].Endpoint.Port;
            var portA1  = Clusters[clusterA].Silos[1].Endpoint.Port;
            var portA2  = Clusters[clusterA].Silos[2].Endpoint.Port;

            // create cluster B and clientB
            NewGeoCluster(globalserviceid, clusterB, 3, configcustomizer);
            var clientB = NewClient <ClientWrapper>(clusterB, 0);
            var portB0  = Clusters[clusterB].Silos[0].Endpoint.Port;
            var portB1  = Clusters[clusterB].Silos[1].Endpoint.Port;
            var portB2  = Clusters[clusterB].Silos[2].Endpoint.Port;

            // wait for membership to stabilize
            await WaitForLivenessToStabilizeAsync();

            // wait for gossip network to stabilize
            await WaitForMultiClusterGossipToStabilizeAsync(false);

            // check that default configuration took effect
            var cur = clientA.GetMultiClusterConfiguration();

            Assert.IsTrue(cur != null && string.Join(",", cur.Clusters) == string.Join(",", clusterA, clusterB));
            AssertSameList(clientA.GetMultiClusterGateways(), clientB.GetMultiClusterGateways());

            // expect 4 active gateways, two per cluster
            var activegateways = clientA.GetMultiClusterGateways().Where(g => g.Status == GatewayStatus.Active).ToList();

            Assert.AreEqual(string.Join(",", portA0, portA1),
                            string.Join(",", activegateways.Where(g => g.ClusterId == clusterA).Select(g => g.SiloAddress.Endpoint.Port).OrderBy(x => x)));
            Assert.AreEqual(string.Join(",", portB0, portB1),
                            string.Join(",", activegateways.Where(g => g.ClusterId == clusterB).Select(g => g.SiloAddress.Endpoint.Port).OrderBy(x => x)));
            var activegatewaysB = clientB.GetMultiClusterGateways().Where(g => g.Status == GatewayStatus.Active).ToList();

            // shut down one of the gateways in cluster B gracefully
            var target = Clusters[clusterB].Silos.Where(h => h.Endpoint.Port == portB1).FirstOrDefault();

            Assert.IsNotNull(target);
            StopSilo(target);
            await WaitForLivenessToStabilizeAsync();

            // expect disappearance and replacement of gateway from multicluster network
            await WaitForMultiClusterGossipToStabilizeAsync(false);

            AssertSameList(clientA.GetMultiClusterGateways(), clientB.GetMultiClusterGateways());
            activegateways = clientA.GetMultiClusterGateways().Where(g => g.Status == GatewayStatus.Active).ToList();
            Assert.AreEqual(string.Join(",", portA0, portA1),
                            string.Join(",", activegateways.Where(g => g.ClusterId == clusterA).Select(g => g.SiloAddress.Endpoint.Port).OrderBy(x => x)));
            Assert.AreEqual(string.Join(",", portB0, portB2),
                            string.Join(",", activegateways.Where(g => g.ClusterId == clusterB).Select(g => g.SiloAddress.Endpoint.Port).OrderBy(x => x)));


            // kill one of the gateways in cluster A
            target = Clusters[clusterA].Silos.Where(h => h.Endpoint.Port == portA1).FirstOrDefault();
            Assert.IsNotNull(target);
            KillSilo(target);
            await WaitForLivenessToStabilizeAsync();

            // wait for time necessary before peer removal can kick in
            await Task.Delay(MultiClusterOracle.CleanupSilentGoneGatewaysAfter);

            // wait for membership protocol to determine death of A
            while (true)
            {
                var hosts     = clientA.GetHosts();
                var killedone = hosts.Where(kvp => kvp.Key.Endpoint.Port == portA1).FirstOrDefault();
                Assert.IsTrue(killedone.Value != SiloStatus.None);
                if (killedone.Value == SiloStatus.Dead)
                {
                    break;
                }
                await Task.Delay(100);
            }

            // wait for gossip propagation
            await WaitForMultiClusterGossipToStabilizeAsync(false);

            AssertSameList(clientA.GetMultiClusterGateways(), clientB.GetMultiClusterGateways());
            activegateways = clientA.GetMultiClusterGateways().Where(g => g.Status == GatewayStatus.Active).ToList();
            Assert.AreEqual(string.Join(",", portA0, portA2),
                            string.Join(",", activegateways.Where(g => g.ClusterId == clusterA).Select(g => g.SiloAddress.Endpoint.Port).OrderBy(x => x)));
            Assert.AreEqual(string.Join(",", portB0, portB2),
                            string.Join(",", activegateways.Where(g => g.ClusterId == clusterB).Select(g => g.SiloAddress.Endpoint.Port).OrderBy(x => x)));
        }
Ejemplo n.º 4
0
 public void TestConvertStringUInt()
 {
     Assert.AreEqual(4294967295, StringConverter.Convert <uint>("4294967295"));
 }
        public void TestAbout()
        {
            var result = _home.About() as ViewResult;

            Assert.AreEqual("About", result.ViewName);
        }
Ejemplo n.º 6
0
 public void TestConvertStringLong()
 {
     Assert.AreEqual(1099511627776L, StringConverter.Convert <long>("1099511627776"));
 }
Ejemplo n.º 7
0
 public void TestConvertStringFloat()
 {
     Assert.AreEqual(5.3f, StringConverter.Convert <float>("5.3"));
 }
Ejemplo n.º 8
0
        public void PydInPackage()
        {
            PythonPaths.Python27.AssertInstalled();

            var outputPath = TestData.GetTempPath(randomSubPath: true);

            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", TestData.GetPath("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 { }
        }
Ejemplo n.º 9
0
        public void VersionedSharedDatabase()
        {
            var twoFive  = PythonTypeDatabase.CreateDefaultTypeDatabase(new Version(2, 5));
            var twoSix   = PythonTypeDatabase.CreateDefaultTypeDatabase(new Version(2, 6));
            var twoSeven = PythonTypeDatabase.CreateDefaultTypeDatabase(new Version(2, 7));
            var threeOh  = PythonTypeDatabase.CreateDefaultTypeDatabase(new Version(3, 0));
            var threeOne = PythonTypeDatabase.CreateDefaultTypeDatabase(new Version(3, 1));
            var threeTwo = PythonTypeDatabase.CreateDefaultTypeDatabase(new Version(3, 2));

            // new in 2.6
            Assert.AreEqual(null, twoFive.BuiltinModule.GetAnyMember("bytearray"));
            foreach (var version in new[] { twoSix, twoSeven, threeOh, threeOne, threeTwo })
            {
                Assert.AreNotEqual(version, version.BuiltinModule.GetAnyMember("bytearray"));
            }

            // new in 2.7
            Assert.AreEqual(null, twoSix.BuiltinModule.GetAnyMember("memoryview"));
            foreach (var version in new[] { twoSeven, threeOh, threeOne, threeTwo })
            {
                Assert.AreNotEqual(version, version.BuiltinModule.GetAnyMember("memoryview"));
            }

            // not in 3.0
            foreach (var version in new[] { twoFive, twoSix, twoSeven })
            {
                Assert.AreNotEqual(null, version.BuiltinModule.GetAnyMember("StandardError"));
            }

            foreach (var version in new[] { threeOh, threeOne, threeTwo })
            {
                Assert.AreEqual(null, version.BuiltinModule.GetAnyMember("StandardError"));
            }

            // new in 3.0
            foreach (var version in new[] { twoFive, twoSix, twoSeven })
            {
                Assert.AreEqual(null, version.BuiltinModule.GetAnyMember("exec"));
                Assert.AreEqual(null, version.BuiltinModule.GetAnyMember("print"));
            }

            foreach (var version in new[] { threeOh, threeOne, threeTwo })
            {
                Assert.AreNotEqual(null, version.BuiltinModule.GetAnyMember("exec"));
                Assert.AreNotEqual(null, version.BuiltinModule.GetAnyMember("print"));
            }


            // new in 3.1
            foreach (var version in new[] { twoFive, twoSix, twoSeven, threeOh })
            {
                Assert.AreEqual(null, version.GetModule("sys").GetMember(null, "int_info"));
            }

            foreach (var version in new[] { threeOne, threeTwo })
            {
                Assert.AreNotEqual(null, version.GetModule("sys").GetMember(null, "int_info"));
            }

            // new in 3.2
            foreach (var version in new[] { twoFive, twoSix, twoSeven, threeOh, threeOne })
            {
                Assert.AreEqual(null, version.GetModule("sys").GetMember(null, "setswitchinterval"));
            }

            foreach (var version in new[] { threeTwo })
            {
                Assert.AreNotEqual(null, version.GetModule("sys").GetMember(null, "setswitchinterval"));
            }
        }
Ejemplo n.º 10
0
        public void PostAnswer_Correct_Answer_Three_Times_Moves_To_Next_Rank_And_Reset_Level_200()
        {
            // Arrange
            ExerciseController ec = new ExerciseController(_exerciseLogic.Object, _sessionLogic.Object);
            var exercise1         = new Exercise()
            {
                Id = Guid.NewGuid(), Expression1 = 2, Expression2 = 3, TimeLimit = 30, AssignedSession = session.Id, CreatedDateTime = DateTime.Now
            };

            State.Exercises.Add(exercise1);


            // Act
            var correctAnswer1 = new Answer()
            {
                ExerciseId = exercise1.Id, SessionId = session.Id, SubmittedAnswer = "5"
            };
            var result = (ObjectResult)ec.PostAnswer(exercise1.Id.Value, correctAnswer1);

            // Assert
            Assert.AreEqual(result.StatusCode, 200);
            var expectedResult = new Result()
            {
                AllLevelCompleted = false, AnswerCorrect = true, Rank = RankEnum.Beginner, Level = 2
            };

            Assert.AreEqual(expectedResult, result.Value);

            // Arrange
            var exercise2 = new Exercise()
            {
                Id = Guid.NewGuid(), Expression1 = 23, Expression2 = 3, TimeLimit = 30, AssignedSession = session.Id, CreatedDateTime = DateTime.Now
            };

            State.Exercises.Add(exercise2);

            // Act
            var correctAnswer2 = new Answer()
            {
                ExerciseId = exercise2.Id, SessionId = session.Id, SubmittedAnswer = "26"
            };
            var result2 = (ObjectResult)ec.PostAnswer(exercise2.Id.Value, correctAnswer2);

            // Assert
            Assert.AreEqual(result2.StatusCode, 200);
            var expectedResult2 = new Result()
            {
                AllLevelCompleted = false, AnswerCorrect = true, Rank = RankEnum.Beginner, Level = 3
            };

            Assert.AreEqual(expectedResult2, result2.Value);

            // Arrange
            var exercise3 = new Exercise()
            {
                Id = Guid.NewGuid(), Expression1 = 2, Expression2 = 1, TimeLimit = 30, AssignedSession = session.Id, CreatedDateTime = DateTime.Now
            };

            State.Exercises.Add(exercise3);

            // Act
            var correctAnswer3 = new Answer()
            {
                ExerciseId = exercise3.Id, SessionId = session.Id, SubmittedAnswer = "3"
            };
            var result3 = (ObjectResult)ec.PostAnswer(exercise3.Id.Value, correctAnswer3);

            // Assert
            Assert.AreEqual(result3.StatusCode, 200);
            var expectedResult3 = new Result()
            {
                AllLevelCompleted = false, AnswerCorrect = true, Rank = RankEnum.Talented, Level = 1
            };

            Assert.AreEqual(expectedResult3, result3.Value);
        }
Ejemplo n.º 11
0
        public void OphalenTrajectenTest()
        {
            // Arrange - We're mocking our dbSet & dbContext
            // in-memory data

            List <Cursus> cursussen = new List <Cursus>()
            {
                new Cursus()
                {
                    Titel             = "dotNET cursus",
                    Type              = ".NET",
                    Prijs             = 15.45,
                    Categorie         = "Cursus",
                    IsBuyable         = true,
                    Beschrijving      = "Some example text some ...",
                    LangeBeschrijving = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
                    FotoURLCard       = "https://52bec9fb483231ac1c712343-jebebgcvzf.stackpathdns.com/wp-content/uploads/2016/05/dotnet.jpg",
                    OrderNumber       = 1
                },
                new Cursus()
                {
                    Titel             = "dotNET cursus 2",
                    Type              = ".NET",
                    Prijs             = 18.45,
                    IsBuyable         = true,
                    Beschrijving      = "Some example text some ...",
                    Categorie         = "Cursus",
                    LangeBeschrijving = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
                    FotoURLCard       = "https://52bec9fb483231ac1c712343-jebebgcvzf.stackpathdns.com/wp-content/uploads/2016/05/dotnet.jpg",
                    OrderNumber       = 2
                }
            };
            IQueryable <Traject> trajecten = new List <Traject>()
            {
                new Traject()
                {
                    Titel             = "dotNET cursus",
                    Type              = ".NET",
                    Prijs             = 45.45,
                    Categorie         = "Traject",
                    IsBuyable         = true,
                    Cursussen         = cursussen,
                    Beschrijving      = "Some example text some ...",
                    LangeBeschrijving = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
                    FotoURLCard       = "https://52bec9fb483231ac1c712343-jebebgcvzf.stackpathdns.com/wp-content/uploads/2016/05/dotnet.jpg",
                    OrderNumber       = 1
                },
                new Traject()
                {
                    Titel             = "dotNET cursus 2",
                    Type              = ".NET",
                    Prijs             = 48.45,
                    IsBuyable         = true,
                    Cursussen         = cursussen,
                    Beschrijving      = "Some example text some ...",
                    Categorie         = "Cursus",
                    LangeBeschrijving = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
                    FotoURLCard       = "https://52bec9fb483231ac1c712343-jebebgcvzf.stackpathdns.com/wp-content/uploads/2016/05/dotnet.jpg",
                    OrderNumber       = 2
                }
            }.AsQueryable();

            var mockSet = new Mock <DbSet <Traject> >();

            mockSet.As <IQueryable <Traject> >().Setup(m => m.Provider).Returns(trajecten.Provider);
            mockSet.As <IQueryable <Traject> >().Setup(m => m.Expression).Returns(trajecten.Expression);
            mockSet.As <IQueryable <Traject> >().Setup(m => m.ElementType).Returns(trajecten.ElementType);
            mockSet.As <IQueryable <Traject> >().Setup(m => m.GetEnumerator()).Returns(trajecten.GetEnumerator());

            var mockContext = new Mock <DatabaseContext>();

            mockContext.Setup(c => c.Trajecten).Returns(mockSet.Object);

            var mockRepo = new Mock <ITrajectRepository>();

            mockRepo.Setup(a => a.GetTrajecten(trajectFilter)).Returns(mockContext.Object.Trajecten.ToList());
            // Act
            //ICursusRepository repo = new CursusRepository(mockContext.Object, contextFilter);
            var actual = mockRepo.Object.GetTrajecten(trajectFilter);

            // Assert
            Assert.AreEqual(2, actual.Count());
            Assert.AreEqual("Traject", actual.First().Categorie);
            Assert.AreEqual(".NET", actual.First().Type);
            Assert.AreEqual(45.45, actual.First().Prijs);
        }
Ejemplo n.º 12
0
        public void ShouldExport()
        {
            var str = rep.Export();

            Assert.AreEqual(true, str.Length > 0);
        }
 public void then_running_this_test_should_pass()
 {
     Assert.AreEqual(true, true);
 }
        public void GivenNormalCondition_WhenEnter_ThenReturnStandardRate()
        {
            List <CalculatorCase> cases = new List <CalculatorCase>()
            {
                new CalculatorCase()
                {
                    TimerData = new TimerDto()
                    {
                        Entry = new DateTime(2017, 1, 2, 9, 0, 0),
                        Exit  = new DateTime(2017, 1, 2, 10, 0, 0)
                    },
                    Expected = new ParkingRateDto()
                    {
                        Name  = CONSTANTS.RATE.STANDARD,
                        Price = 5
                    }
                },
                new CalculatorCase()
                {
                    TimerData = new TimerDto()
                    {
                        Entry = new DateTime(2017, 1, 2, 10, 0, 0),
                        Exit  = new DateTime(2017, 1, 2, 12, 0, 0)
                    },
                    Expected = new ParkingRateDto()
                    {
                        Name  = CONSTANTS.RATE.STANDARD,
                        Price = 10
                    }
                },
                new CalculatorCase()
                {
                    TimerData = new TimerDto()
                    {
                        Entry = new DateTime(2017, 1, 2, 12, 0, 0),
                        Exit  = new DateTime(2017, 1, 2, 15, 0, 0)
                    },
                    Expected = new ParkingRateDto()
                    {
                        Name  = CONSTANTS.RATE.STANDARD,
                        Price = 15
                    }
                },
                new CalculatorCase()
                {
                    TimerData = new TimerDto()
                    {
                        Entry = new DateTime(2017, 1, 2, 15, 0, 0),
                        Exit  = new DateTime(2017, 1, 2, 19, 0, 0)
                    },
                    Expected = new ParkingRateDto()
                    {
                        Name  = CONSTANTS.RATE.STANDARD,
                        Price = 20
                    }
                },
                new CalculatorCase()
                {
                    TimerData = new TimerDto()
                    {
                        Entry = new DateTime(2017, 1, 2, 12, 0, 0),
                        Exit  = new DateTime(2017, 1, 4, 12, 0, 0)
                    },
                    Expected = new ParkingRateDto()
                    {
                        Name  = CONSTANTS.RATE.STANDARD,
                        Price = 40
                    }
                },
                new CalculatorCase()
                {
                    TimerData = new TimerDto()
                    {
                        Entry = new DateTime(2017, 1, 2, 12, 0, 0),
                        Exit  = new DateTime(2017, 1, 4, 15, 0, 0)
                    },
                    Expected = new ParkingRateDto()
                    {
                        Name  = CONSTANTS.RATE.STANDARD,
                        Price = 55
                    }
                },
                new CalculatorCase()
                {
                    TimerData = new TimerDto()
                    {
                        Entry = new DateTime(2017, 1, 2, 12, 0, 0),
                        Exit  = new DateTime(2017, 1, 4, 19, 0, 0)
                    },
                    Expected = new ParkingRateDto()
                    {
                        Name  = CONSTANTS.RATE.STANDARD,
                        Price = 60
                    }
                },
                new CalculatorCase()
                {
                    TimerData = new TimerDto()
                    {
                        Entry = new DateTime(2017, 1, 2, 12, 0, 0),
                        Exit  = new DateTime(2017, 1, 2, 12, 15, 0)
                    },
                    Expected = new ParkingRateDto()
                    {
                        Name  = CONSTANTS.RATE.STANDARD,
                        Price = 5
                    }
                }
            };

            foreach (var c in cases)
            {
                var result = _calculatorService.Calculate(c.TimerData).Result;
                Assert.AreEqual(c.Expected.Name, result.Name);
                Assert.AreEqual(c.Expected.Price, result.Price);
            }
        }
Ejemplo n.º 15
0
 public void TestConvertStringShort()
 {
     Assert.AreEqual((short)1024, StringConverter.Convert <short>("1024"));
 }
Ejemplo n.º 16
0
        private void TestOpen(PythonVersion path)
        {
            path.AssertInstalled();
            Console.WriteLine(path.InterpreterPath);

            Guid testId  = Guid.NewGuid();
            var  testDir = TestData.GetTempPath(testId.ToString());

            // run the scraper
            using (var proc = ProcessOutput.RunHiddenAndCapture(
                       path.InterpreterPath,
                       TestData.GetPath("PythonScraper.py"),
                       testDir,
                       TestData.GetPath("CompletionDB")
                       )) {
                Console.WriteLine("Command: " + proc.Arguments);

                proc.Wait();

                // it should succeed
                Console.WriteLine("**Stdout**");
                foreach (var line in proc.StandardOutputLines)
                {
                    Console.WriteLine(line);
                }
                Console.WriteLine("");
                Console.WriteLine("**Stdout**");
                foreach (var line in proc.StandardErrorLines)
                {
                    Console.WriteLine(line);
                }

                Assert.AreEqual(0, proc.ExitCode, "Bad exit code: " + proc.ExitCode);
            }

            // perform some basic validation
            dynamic builtinDb = Unpickle.Load(new FileStream(Path.Combine(testDir, path.Version.Is3x() ? "builtins.idb" : "__builtin__.idb"), FileMode.Open, FileAccess.Read));

            if (path.Version.Is2x())   // no open in 3.x
            {
                foreach (var overload in builtinDb["members"]["open"]["value"]["overloads"])
                {
                    Assert.AreEqual("__builtin__", overload["ret_type"][0][0]);
                    Assert.AreEqual("file", overload["ret_type"][0][1]);
                }

                if (!path.InterpreterPath.Contains("Iron"))
                {
                    // http://pytools.codeplex.com/workitem/799
                    var arr = (IList <object>)builtinDb["members"]["list"]["value"]["members"]["__init__"]["value"]["overloads"];
                    Assert.AreEqual(
                        "args",
                        ((dynamic)(arr[0]))["args"][1]["name"]
                        );
                }
            }

            if (!path.InterpreterPath.Contains("Iron"))
            {
                dynamic itertoolsDb = Unpickle.Load(new FileStream(Path.Combine(testDir, "itertools.idb"), FileMode.Open, FileAccess.Read));
                var     tee         = itertoolsDb["members"]["tee"]["value"];
                var     overloads   = tee["overloads"];
                var     nArg        = overloads[0]["args"][1];
                Assert.AreEqual("n", nArg["name"]);
                Assert.AreEqual("2", nArg["default_value"]);

                dynamic sreDb   = Unpickle.Load(new FileStream(Path.Combine(testDir, "_sre.idb"), FileMode.Open, FileAccess.Read));
                var     members = sreDb["members"];
                Assert.IsTrue(members.ContainsKey("SRE_Pattern"));
                Assert.IsTrue(members.ContainsKey("SRE_Match"));
            }

            Console.WriteLine("Passed: {0}", path.InterpreterPath);
        }
Ejemplo n.º 17
0
 public void TestConvertStringInt()
 {
     Assert.AreEqual(262144, StringConverter.Convert <int>("262144"));
 }
Ejemplo n.º 18
0
 public void TestConvertStringULong()
 {
     Assert.AreEqual(18446744073709551615, StringConverter.Convert <ulong>("18446744073709551615"));
 }
Ejemplo n.º 19
0
 public void TestConvertStringSByte()
 {
     Assert.AreEqual((sbyte)-128, StringConverter.Convert <sbyte>("-128"));
 }
Ejemplo n.º 20
0
 public void TestConvertStringByte()
 {
     Assert.AreEqual((byte)123, StringConverter.Convert <byte>("123"));
 }
Ejemplo n.º 21
0
 public void TestConvertStringUShort()
 {
     Assert.AreEqual((ushort)65535, StringConverter.Convert <ushort>("65535"));
 }
Ejemplo n.º 22
0
 public void TestConvertStringChar()
 {
     Assert.AreEqual('c', StringConverter.Convert <char>("c"));
 }
        public void TestIndex()
        {
            var result = _home.Index() as ViewResult;

            Assert.AreEqual("Index", result.ViewName);
        }
Ejemplo n.º 24
0
 public void TestConvertStringDateTime()
 {
     Assert.AreEqual(new DateTime(2015, 9, 17), StringConverter.Convert <DateTime>("2015-09-17"));
 }
        public void TestContact()
        {
            var result = _home.Contact() as ViewResult;

            Assert.AreEqual("Contact", result.ViewName);
        }
Ejemplo n.º 26
0
 public void TestConvertStringDecimal()
 {
     Assert.AreEqual(decimal.MaxValue, StringConverter.Convert <decimal>("79228162514264337593543950335"));
 }
Ejemplo n.º 27
0
        public void General()
        {
            string code = @"def f(a, *b, **c): pass

def f1(x = 42): pass
def f2(x = []): pass

class C(object): 
    @property
    def f(self):
        return 42
    def g(self):
        return 100

class D(C): 
    x = C().g

abc = 42
fob = int

class X(object): pass
class Y(object): pass

union = X()
union = Y()

list_of_int = [1, 2, 3]
tuple_of_str = 'a', 'b', 'c'

m = max

class Aliased(object):
    def f(self):
        pass

def Aliased(fob):
    pass
";

            using (var newPs = SaveLoad(PythonLanguageVersion.V27, new AnalysisModule("test", "test.py", code))) {
                AssertUtil.Contains(newPs.Analyzer.Analyzer.GetModules().Select(x => x.Name), "test");

                string codeText = @"
import test
abc = test.abc
fob = test.fob
a = test.C()
cf = a.f
cg = a.g()
dx = test.D().x
scg = test.C.g
f1 = test.f1
union = test.union
list_of_int = test.list_of_int
tuple_of_str = test.tuple_of_str
f1 = test.f1
f2 = test.f2
m = test.m
Aliased = test.Aliased
";
                var    newMod   = newPs.NewModule("baz", codeText);
                int    pos      = codeText.LastIndexOf('\n');

                AssertUtil.ContainsExactly(newMod.Analysis.GetTypeIdsByIndex("abc", pos), BuiltinTypeId.Int);
                AssertUtil.ContainsExactly(newMod.Analysis.GetTypeIdsByIndex("cf", pos), BuiltinTypeId.Int);
                AssertUtil.ContainsExactly(newMod.Analysis.GetTypeIdsByIndex("cg", pos), BuiltinTypeId.Int);
                Assert.AreEqual("function f1(x = 42)", newMod.Analysis.GetValuesByIndex("f1", pos).First().Description);
                Assert.AreEqual("bound method x", newMod.Analysis.GetValuesByIndex("dx", pos).First().Description);
                Assert.AreEqual("function test.C.g(self)", newMod.Analysis.GetValuesByIndex("scg", pos).First().Description);
                var unionMembers = new List <AnalysisValue>(newMod.Analysis.GetValuesByIndex("union", pos));
                Assert.AreEqual(unionMembers.Count, 2);
                AssertUtil.ContainsExactly(unionMembers.Select(x => x.PythonType.Name), "X", "Y");

                var list = newMod.Analysis.GetValuesByIndex("list_of_int", pos).First();
                AssertUtil.ContainsExactly(newMod.Analysis.GetShortDescriptionsByIndex("list_of_int", pos), "list of int");
                AssertUtil.ContainsExactly(newMod.Analysis.GetShortDescriptionsByIndex("tuple_of_str", pos), "tuple of str");

                AssertUtil.ContainsExactly(newMod.Analysis.GetShortDescriptionsByIndex("fob", pos), "type int");

                var result = newMod.Analysis.GetSignaturesByIndex("f1", pos).ToArray();
                Assert.AreEqual(1, result.Length);
                Assert.AreEqual(1, result[0].Parameters.Length);
                Assert.AreEqual("int", result[0].Parameters[0].Type);

                result = newMod.Analysis.GetSignaturesByIndex("m", pos).ToArray();
                Assert.AreEqual(6, result.Length);

                var members = newMod.Analysis.GetMembersByIndex("Aliased", pos, GetMemberOptions.None);
                AssertUtil.Contains(members.Select(x => x.Name), "f");
                AssertUtil.Contains(members.Select(x => x.Name), "__self__");
            }
        }
Ejemplo n.º 28
0
 public void TestConvertStringDouble()
 {
     Assert.AreEqual(3.6, StringConverter.Convert <double>("3.6"));
 }
Ejemplo n.º 29
0
        public async Task TestMultiClusterConf_1_1()
        {
            // use a random global service id for testing purposes
            var globalserviceid = Guid.NewGuid();

            // create cluster A and clientA
            var clusterA = "A";

            NewGeoCluster(globalserviceid, clusterA, 1);
            var siloA   = Clusters[clusterA].Silos[0].Silo.SiloAddress.Endpoint;
            var clientA = NewClient <ClientWrapper>(clusterA, 0);

            var cur = clientA.GetMultiClusterConfiguration();

            Assert.IsNull(cur, "no configuration should be there yet");

            await WaitForMultiClusterGossipToStabilizeAsync(false);

            cur = clientA.GetMultiClusterConfiguration();
            Assert.IsNull(cur, "no configuration should be there yet");

            var gateways = clientA.GetMultiClusterGateways();

            Assert.AreEqual(1, gateways.Count, "Expect 1 gateway");
            Assert.AreEqual("A", gateways[0].ClusterId);
            Assert.AreEqual(siloA, gateways[0].SiloAddress.Endpoint);
            Assert.AreEqual(GatewayStatus.Active, gateways[0].Status);

            // create cluster B and clientB
            var clusterB = "B";

            NewGeoCluster(globalserviceid, clusterB, 1);
            var siloB   = Clusters[clusterB].Silos[0].Silo.SiloAddress.Endpoint;
            var clientB = NewClient <ClientWrapper>(clusterB, 0);

            cur = clientB.GetMultiClusterConfiguration();
            Assert.IsNull(cur, "no configuration should be there yet");

            await WaitForMultiClusterGossipToStabilizeAsync(false);

            cur = clientB.GetMultiClusterConfiguration();
            Assert.IsNull(cur, "no configuration should be there yet");

            gateways = clientA.GetMultiClusterGateways();
            Assert.AreEqual(2, gateways.Count, "Expect 2 gateways");
            gateways.Sort((a, b) => a.ClusterId.CompareTo(b.ClusterId));
            Assert.AreEqual(clusterA, gateways[0].ClusterId);
            Assert.AreEqual(siloA, gateways[0].SiloAddress.Endpoint);
            Assert.AreEqual(GatewayStatus.Active, gateways[0].Status);
            Assert.AreEqual(clusterB, gateways[1].ClusterId);
            Assert.AreEqual(siloB, gateways[1].SiloAddress.Endpoint);
            Assert.AreEqual(GatewayStatus.Active, gateways[1].Status);

            for (int i = 0; i < 2; i++)
            {
                // test injection
                var conf = clientA.InjectMultiClusterConf(clusterA, clusterB);

                // immediately visible on A, visible after stabilization on B
                cur = clientA.GetMultiClusterConfiguration();
                Assert.IsTrue(conf.Equals(cur));
                await WaitForMultiClusterGossipToStabilizeAsync(false);

                cur = clientA.GetMultiClusterConfiguration();
                Assert.IsTrue(conf.Equals(cur));
                cur = clientB.GetMultiClusterConfiguration();
                Assert.IsTrue(conf.Equals(cur));
            }

            // shut down cluster B
            StopSilo(Clusters[clusterB].Silos[0]);
            await WaitForLivenessToStabilizeAsync();

            // expect disappearance of gateway from multicluster network
            await WaitForMultiClusterGossipToStabilizeAsync(false);

            gateways = clientA.GetMultiClusterGateways();
            Assert.AreEqual(2, gateways.Count, "Expect 2 gateways");
            var activegateways = gateways.Where(g => g.Status == GatewayStatus.Active).ToList();

            Assert.AreEqual(1, activegateways.Count, "Expect 1 active gateway");
            Assert.AreEqual("A", activegateways[0].ClusterId);
        }
Ejemplo n.º 30
0
        public void MatchIdentifyCard_False()
        {
            bool expect = "513901199509120610".MatchIdentifyCard();

            Assert.AreEqual(false, expect);
        }