Ejemplo n.º 1
0
        public static void TestSamplePointer(LfxPointer pointer, LfxPointerType type)
        {
            var pointerText = type == LfxPointerType.Simple ? SimplePointerText :
                              type == LfxPointerType.Curl ? CurlPointerText :
                              ArchivePointerText;

            Assert.AreEqual(type, pointer.Type);
            Assert.AreEqual(Version, pointer.Version);
            Assert.AreEqual(Method, pointer.HashMethod);
            Assert.AreEqual(HashValue, pointer.HashValue);
            Assert.AreEqual(LfxHash.Parse(HashValue), pointer.Hash);
            Assert.AreEqual(Size, pointer.Size);

            if (type == LfxPointerType.Simple)
            {
                Assert.AreEqual(null, pointer.Url);
                Assert.AreEqual(null, pointer.ArchiveHint);
            }

            if (type == LfxPointerType.Curl)
            {
                Assert.AreEqual(Url, pointer.Url);
                Assert.AreEqual(null, pointer.ArchiveHint);
            }

            if (type == LfxPointerType.Archive)
            {
                Assert.AreEqual(Url, pointer.Url);
                Assert.AreEqual(ArchiveHint, pointer.ArchiveHint);
            }

            Assert.AreEqual(
                pointerText,
                pointer.ToString()
                );

            // round-trip
            using (var tempFile = new TempFile()) {
                File.WriteAllText(tempFile, pointer.ToString());

                using (var pointerFile = new StreamReader(tempFile)) {
                    var pointerRoundTrip = LfxPointer.Parse(pointerFile);
                    Assert.IsTrue(pointer.Equals(pointerRoundTrip));
                    Assert.IsTrue(pointer.Equals((object)pointerRoundTrip));
                    Assert.AreEqual(pointer.ToString(), pointerRoundTrip.ToString());
                    Assert.AreEqual(pointer, pointerRoundTrip);
                    Assert.AreEqual(pointer.GetHashCode(), pointer.GetHashCode());
                }
            }


            var otherPointer = LfxPointer.Parse(OtherPointerText);

            Assert.AreNotEqual(pointer, otherPointer);
            Assert.AreNotEqual(pointer.GetHashCode(), otherPointer.GetHashCode());
        }
Ejemplo n.º 2
0
        public static void ParseTest()
        {
            var hash = LfxHash.Parse(UpperHashValue);

            Assert.AreEqual(HashValue, hash.ToString());
            Assert.AreEqual(HashValue, (string)hash);
            Assert.AreEqual(HashValue, hash.ToString());
            Assert.IsTrue(LfxHash.Parse(UpperHashValue).Equals((object)hash));

            var otherHash = LfxHash.Parse(OtherHashValue);

            Assert.IsFalse(HashValue.Equals((object)otherHash));
            Assert.AreNotEqual(hash, otherHash);
            Assert.AreNotEqual(hash.GetHashCode(), otherHash.GetHashCode());
        }
Ejemplo n.º 3
0
        public void Init()
        {
            var nugetUrl   = "https://dist.nuget.org/win-x86-commandline/v3.4.4/NuGet.exe";
            var nugetHash  = "c12d583dd1b5447ac905a334262e02718f641fca3877d0b6117fe44674072a27";
            var nugetCount = 3957976L;

            var nugetPkgUrl     = "http://nuget.org/api/v2/package/${id}/${ver}";
            var nugetPkgPattern = "^((?<id>.*?)[.])(?=\\d)(?<ver>[^/]*)/(?<path>.*)$";
            var nugetPkgHint    = "${path}";

            var args = Parse(
                maxArgs: 0,
                switchInfo: GitCmdSwitchInfo.Create(
                    LfxCmdSwitches.Sample
                    )
                );

            Git("init");
            Lfx("config --set");

            if (!args.IsSet(LfxCmdSwitches.Sample))
            {
                return;
            }

            File.WriteAllText(".gitattributes", $"* text=auto");

            using (var dls = new TempCurDir("dls")) {
                File.WriteAllLines(".gitattributes", new[] {
                    $"* filter=lfx diff=lfx merge=lfx -text",
                    $".gitattributes filter= diff= merge= text=auto",
                    $".gitignore filter= diff= merge= text=auto",
                    $"packages.config filter= diff= merge= text=auto",
                    $"*.lfxconfig filter= diff= merge= text eol=lf"
                });

                using (var packages = new TempCurDir("tools")) {
                    Git($"config -f nuget.exe.lfxconfig --add lfx.type curl");
                    Git($"config -f nuget.exe.lfxconfig --add lfx.url {nugetUrl}");

                    File.WriteAllText("NuGet.exe", LfxPointer.Create(
                                          hash: LfxHash.Parse(nugetHash),
                                          count: nugetCount
                                          ).AddUrl(nugetUrl.ToUrl()).ToString());
                }

                using (var packages = new TempCurDir("packages")) {
                    File.WriteAllText(".gitignore", $"*.nupkg");

                    Git($"config -f .lfxconfig --add lfx.type archive");
                    Git($"config -f .lfxconfig --add lfx.url {nugetPkgUrl}");
                    Git($"config -f .lfxconfig --add lfx.pattern {nugetPkgPattern}");
                    Git($"config -f .lfxconfig --add lfx.hint {nugetPkgHint}");

                    new XElement("packages",
                                 new XElement("package",
                                              new XAttribute("id", "NUnit"),
                                              new XAttribute("version", "2.6.4")
                                              )
                                 ).Save("packages.config");
                }
            }
        }