Ejemplo n.º 1
0
        public void testBuildOneFile_FinishWriteCommit()
        {
            string        path         = "a-File-path";
            var           mode         = FileMode.RegularFile;
            long          lastModified = 1218123387057L;
            int           Length       = 1342;
            DirCacheEntry entOrig;

            DirCache        dc = DirCache.Lock(db);
            DirCacheBuilder b  = dc.builder();

            Assert.IsNotNull(b);

            entOrig = new DirCacheEntry(path);
            entOrig.setFileMode(mode);
            entOrig.setLastModified(lastModified);
            entOrig.setLength(Length);

            Assert.AreNotSame(path, entOrig.getPathString());
            Assert.AreEqual(path, entOrig.getPathString());
            Assert.AreEqual(ObjectId.ZeroId, entOrig.getObjectId());
            Assert.AreEqual(mode.Bits, entOrig.getRawMode());
            Assert.AreEqual(0, entOrig.getStage());
            Assert.AreEqual(lastModified, entOrig.getLastModified());
            Assert.AreEqual(Length, entOrig.getLength());
            Assert.IsFalse(entOrig.isAssumeValid());
            b.add(entOrig);

            b.finish();
            Assert.AreEqual(1, dc.getEntryCount());
            Assert.AreSame(entOrig, dc.getEntry(0));

            dc.write();
            Assert.IsTrue(dc.commit());

            dc = DirCache.read(db);
            Assert.AreEqual(1, dc.getEntryCount());

            DirCacheEntry entRead = dc.getEntry(0);

            Assert.AreNotSame(entOrig, entRead);
            Assert.AreEqual(path, entRead.getPathString());
            Assert.AreEqual(ObjectId.ZeroId, entOrig.getObjectId());
            Assert.AreEqual(mode.Bits, entOrig.getRawMode());
            Assert.AreEqual(0, entOrig.getStage());
            Assert.AreEqual(lastModified, entOrig.getLastModified());
            Assert.AreEqual(Length, entOrig.getLength());
            Assert.IsFalse(entOrig.isAssumeValid());
        }
        private static void AssertAreEqual(CGitIndexRecord c, DirCacheEntry j)
        {
            Assert.IsNotNull(c);
            Assert.IsNotNull(j);

            Assert.AreEqual(c.Path, j.getPathString());
            Assert.AreEqual(c.Id, j.getObjectId());
            Assert.AreEqual(c.Mode, j.getRawMode());
            Assert.AreEqual(c.Stage, j.getStage());
        }
Ejemplo n.º 3
0
        public void testCreate_ByStringPathAndStage()
        {
            DirCacheEntry e;

            e = new DirCacheEntry("a", 0);
            Assert.AreEqual("a", e.getPathString());
            Assert.AreEqual(0, e.getStage());

            e = new DirCacheEntry("a/b", 1);
            Assert.AreEqual("a/b", e.getPathString());
            Assert.AreEqual(1, e.getStage());

            e = new DirCacheEntry("a/c", 2);
            Assert.AreEqual("a/c", e.getPathString());
            Assert.AreEqual(2, e.getStage());

            e = new DirCacheEntry("a/d", 3);
            Assert.AreEqual("a/d", e.getPathString());
            Assert.AreEqual(3, e.getStage());

            try
            {
                new DirCacheEntry("/a", 1);
                Assert.Fail("Incorrectly created DirCacheEntry");
            }
            catch (ArgumentException err)
            {
                Assert.AreEqual("Invalid path: /a", err.Message);
            }

            try
            {
                new DirCacheEntry("a", -11);
                Assert.Fail("Incorrectly created DirCacheEntry");
            }
            catch (ArgumentException err)
            {
                Assert.AreEqual("Invalid stage -11 for path a", err.Message);
            }

            try
            {
                new DirCacheEntry("a", 4);
                Assert.Fail("Incorrectly created DirCacheEntry");
            }
            catch (ArgumentException err)
            {
                Assert.AreEqual("Invalid stage 4 for path a", err.Message);
            }
        }