public void AddFirstTest()
        {
            var list = new ReAttachTargetList(5);
            for (var i = 1; i <= 3; i++)
                list.AddFirst(new ReAttachTarget(i, "path" + i, "user" + i));
            Assert.AreEqual(3, list[0].ProcessId);
            Assert.AreEqual(2, list[1].ProcessId);

            for (var i = 4; i <= 5; i++)
                list.AddFirst(new ReAttachTarget(i, "path" + i, "user" + i));
            Assert.AreEqual(5, list[0].ProcessId);
            Assert.AreEqual(4, list[1].ProcessId);
        }
        public void SaveErrorTest()
        {
            var key    = new Mock <IRegistryKey>(MockBehavior.Strict);
            var subkey = new Mock <IRegistryKey>(MockBehavior.Strict);

            key.Setup(k => k.CreateSubKey(It.IsAny <string>())).Returns(subkey.Object);

            subkey.Setup(k => k.SetValue(It.IsAny <string>(), It.IsAny <string>())).Throws
                (new SecurityException("Simulating no access when setting value. :)"));
            subkey.Setup(k => k.DeleteValue(It.IsAny <string>(), It.IsAny <bool>())).Throws
                (new SecurityException("Simulating no access when deleting value. :)"));

            var package = new Mock <IReAttachPackage>();

            package.Setup(p => p.OpenUserRegistryRoot()).Returns(key.Object);
            package.Setup(p => p.Reporter).Returns(new ReAttachTraceReporter());
            var repository = new ReAttachRegistryRepository(package.Object);

            var targets = new ReAttachTargetList(ReAttachConstants.ReAttachHistorySize);

            Assert.IsFalse(repository.SaveTargets(targets));

            for (var i = 1; i <= 3; i++)
            {
                targets.AddFirst(new ReAttachTarget(i, "path" + i, "user" + i));
            }

            Assert.IsFalse(repository.SaveTargets(targets));
        }
        public void SaveTest()
        {
            var key    = new Mock <IRegistryKey>();
            var subkey = new Mock <IRegistryKey>();

            key.Setup(k => k.CreateSubKey(It.IsAny <string>())).Returns(subkey.Object);

            var package = new Mock <IReAttachPackage>();

            package.Setup(p => p.OpenUserRegistryRoot()).Returns(key.Object);
            var repository = new ReAttachRegistryRepository(package.Object);

            var targets = new ReAttachTargetList(ReAttachConstants.ReAttachHistorySize);

            for (var i = 1; i <= 3; i++)
            {
                targets.AddFirst(new ReAttachTarget(i, "path" + i, "user" + i));
            }

            Assert.IsTrue(repository.SaveTargets(targets));
            key.Verify(k => k.CreateSubKey(It.IsAny <string>()), Times.Once());

            for (var i = 1; i <= 3; i++)
            {
                subkey.Verify(k => k.SetValue(
                                  ReAttachConstants.ReAttachRegistryHistoryKeyPrefix + i,
                                  It.IsAny <string>()), Times.Once());
            }

            subkey.Verify(k => k.Close(), Times.Once());
        }
        public void AddFirstTest()
        {
            var list = new ReAttachTargetList(5);

            for (var i = 1; i <= 3; i++)
            {
                list.AddFirst(new ReAttachTarget(i, "path" + i, "user" + i));
            }
            Assert.AreEqual(3, list[0].ProcessId);
            Assert.AreEqual(2, list[1].ProcessId);

            for (var i = 4; i <= 5; i++)
            {
                list.AddFirst(new ReAttachTarget(i, "path" + i, "user" + i));
            }
            Assert.AreEqual(5, list[0].ProcessId);
            Assert.AreEqual(4, list[1].ProcessId);
        }
        public void MaxItemsTest()
        {
            var list = new ReAttachTargetList(5);

            for (var i = 1; i <= 10; i++)
            {
                list.AddFirst(new ReAttachTarget(i, "path" + i, "user" + i));
            }
            Assert.AreEqual(5, list.Count);
            Assert.AreEqual(10, list[0].ProcessId);
            Assert.AreEqual(6, list[4].ProcessId);
        }
        public void AddExistingElementFirstTest()
        {
            var list = new ReAttachTargetList(5);
            for (var i = 1; i <= 4; i++)
                list.AddLast(new ReAttachTarget(i, "path" + i, "user" + i));
            Assert.AreEqual(3, list[2].ProcessId);
            Assert.AreEqual(4, list.Count);

            list.AddFirst(new ReAttachTarget(3, "path3", "user3"));
            Assert.AreNotEqual(3, list[2].ProcessId);
            Assert.AreEqual(3, list[0].ProcessId);
            Assert.AreEqual(4, list.Count);
        }
        public void AddExistingElementFirstTest()
        {
            var list = new ReAttachTargetList(5);

            for (var i = 1; i <= 4; i++)
            {
                list.AddLast(new ReAttachTarget(i, "path" + i, "user" + i));
            }
            Assert.AreEqual(3, list[2].ProcessId);
            Assert.AreEqual(4, list.Count);

            list.AddFirst(new ReAttachTarget(3, "path3", "user3"));
            Assert.AreNotEqual(3, list[2].ProcessId);
            Assert.AreEqual(3, list[0].ProcessId);
            Assert.AreEqual(4, list.Count);
        }
        public void SaveTest()
        {
            var key = new Mock<IRegistryKey>();
            var subkey = new Mock<IRegistryKey>();
            key.Setup(k => k.CreateSubKey(It.IsAny<string>())).Returns(subkey.Object);

            var package = new Mock<IReAttachPackage>();
            package.Setup(p => p.OpenUserRegistryRoot()).Returns(key.Object);
            var repository = new ReAttachRegistryRepository(package.Object);

            var targets = new ReAttachTargetList(ReAttachConstants.ReAttachHistorySize);
            for (var i = 1; i <= 3; i++)
                targets.AddFirst(new ReAttachTarget(i, "path" + i, "user" + i));

            Assert.IsTrue(repository.SaveTargets(targets));
            key.Verify(k => k.CreateSubKey(It.IsAny<string>()), Times.Once());

            for (var i = 1; i <= 3; i++)
            {
                subkey.Verify(k => k.SetValue(
                    ReAttachConstants.ReAttachRegistryHistoryKeyPrefix + i,
                    It.IsAny<string>()), Times.Once());
            }

            subkey.Verify(k => k.Close(), Times.Once());
        }
        public void SaveErrorTest()
        {
            var key = new Mock<IRegistryKey>(MockBehavior.Strict);
            var subkey = new Mock<IRegistryKey>(MockBehavior.Strict);
            key.Setup(k => k.CreateSubKey(It.IsAny<string>())).Returns(subkey.Object);

            subkey.Setup(k => k.SetValue(It.IsAny<string>(), It.IsAny<string>())).Throws
                (new SecurityException("Simulating no access when setting value. :)"));
            subkey.Setup(k => k.DeleteValue(It.IsAny<string>(), It.IsAny<bool>())).Throws
                (new SecurityException("Simulating no access when deleting value. :)"));

            var package = new Mock<IReAttachPackage>();
            package.Setup(p => p.OpenUserRegistryRoot()).Returns(key.Object);
            package.Setup(p => p.Reporter).Returns(new ReAttachTraceReporter());
            var repository = new ReAttachRegistryRepository(package.Object);

            var targets = new ReAttachTargetList(ReAttachConstants.ReAttachHistorySize);
            Assert.IsFalse(repository.SaveTargets(targets));

            for (var i = 1; i <= 3; i++)
                targets.AddFirst(new ReAttachTarget(i, "path" + i, "user" + i));

            Assert.IsFalse(repository.SaveTargets(targets));
        }
Exemple #10
0
 public void AddFirst(ReAttachTarget target) => _targets.AddFirst(target);
 public void MaxItemsTest()
 {
     var list = new ReAttachTargetList(5);
     for (var i = 1; i <= 10; i++)
         list.AddFirst(new ReAttachTarget(i, "path" + i, "user" + i));
     Assert.AreEqual(5, list.Count);
     Assert.AreEqual(10, list[0].ProcessId);
     Assert.AreEqual(6, list[4].ProcessId);
 }
        public void SaveTest()
        {
            var key = new Mock<IRegistryKey>();
            var subkey = new Mock<IRegistryKey>();
            key.Setup(k => k.CreateSubKey(It.IsAny<string>())).Returns(subkey.Object);

            var package = new Mock<IReAttachPackage>();
            package.Setup(p => p.OpenUserRegistryRoot()).Returns(key.Object);
            var repository = new ReAttachRegistryRepository(package.Object);

            var targets = new ReAttachTargetList(ReAttachConstants.ReAttachHistorySize);
            for (var i = 1; i <= 3; i++)
                targets.AddFirst(new ReAttachTarget(i, "path" + i, "user" + i));

            Assert.IsTrue(repository.SaveTargets(targets));

            key.Verify(k => k.CreateSubKey(It.IsAny<string>()), Times.Once());

            for (var i = 1; i <= 3; i++)
            {
                var expected = string.Format("{0}{1}{2}{3}{4}{5}{6}",
                        targets[i - 1].ProcessPath, ReAttachConstants.ReAttachRegistrySplitChar,
                        targets[i - 1].ProcessUser, ReAttachConstants.ReAttachRegistrySplitChar,
                        targets[i - 1].ProcessId, ReAttachConstants.ReAttachRegistrySplitChar,
                        targets[i - 1].ServerName);

                subkey.Verify(k => k.SetValue(ReAttachConstants.ReAttachRegistryHistoryKeyPrefix + i,
                    expected), Times.Once());
            }

            subkey.Verify(k => k.Close(), Times.Once());
        }