Click here to Skip to main content
15,881,092 members
Articles / Programming Languages / C#

EnvMan 1.3 - Windows Environment Variables Manager

Rate me:
Please Sign up or sign in to vote.
4.34/5 (21 votes)
1 Feb 2008GPL36 min read 148K   360   83  
Environment Variables Manager (EnvMan) is a tool written in C# .Net intended to handle the administration of Windows Shell Environment Variables. It is designed to replace Control Panel System Environment Manager and easily manage long variable values.
/*
   EnvMan - The Open-Source Windows Environment Variables Manager
   Copyright (C) 2006-2007 Vlad Setchin <v_setchin@yahoo.com.au>

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.Text;

using EnvManager.Handlers;
using NUnit.Framework;

namespace EnvManager.Tests.Handlers
{
    [TestFixture]
    public class UndoRedoCommandListTest
    {
        #region Variables
        const string REDO_STRING = "Redo ";
        const string UNDO_STRING = "Undo ";
        const string COMMAND_NAME1 = "Command1";
        const string COMMAND_NAME2 = "Command2";
        const string COMMAND_NAME3 = "Command3";
        UndoRedoCommandList commandsList = null;
        MockCommand command1 = null;
        MockCommand command2 = null;
        MockCommand command3 = null;
        #endregion Variables

        #region Setup Teardown
        [SetUp]
        public void SetUp()
        {
            commandsList = new UndoRedoCommandList();

            command1 = new MockCommand();
            command1.CommandName = COMMAND_NAME1;

            command2 = new MockCommand();
            command2.CommandName = COMMAND_NAME2;

            command3 = new MockCommand();
            command3.CommandName = COMMAND_NAME3;
        }
        #endregion Setup Teardown

        #region Tests
        [Test]
        public void TestAdd()
        {
            commandsList.Add(command1);

            Assert.IsTrue(commandsList.CanUndo);
            Assert.IsFalse(commandsList.CanRedo);
            Assert.AreEqual(commandsList.UndoMsg, UNDO_STRING + COMMAND_NAME1);
        }
        [Test]
        public void TestAddUndo()
        {
            commandsList.Add(command1);
            UndoCommand(1);
            Assert.IsFalse(commandsList.CanUndo);
            Assert.IsTrue(commandsList.CanRedo);
            Assert.AreEqual(commandsList.RedoMsg, REDO_STRING + COMMAND_NAME1);
        }
        [Test]
        public void TestAddUndoAdd()
        {
            commandsList.Add(command1);
            UndoCommand(1);
            commandsList.Add(command2);
            Assert.IsTrue(commandsList.CanUndo);
            Assert.IsFalse(commandsList.CanRedo);
            Assert.AreEqual(commandsList.UndoMsg, UNDO_STRING + COMMAND_NAME2);
        }
        [Test]
        public void TestAddx2Undo()
        {
            commandsList.Add(command1);
            commandsList.Add(command2);
            UndoCommand(1);
            Assert.IsTrue(commandsList.CanUndo);
            Assert.IsTrue(commandsList.CanRedo);
            Assert.AreEqual(commandsList.UndoMsg, UNDO_STRING + COMMAND_NAME1);
            Assert.AreEqual(commandsList.RedoMsg, REDO_STRING + COMMAND_NAME2);
        }
        [Test]
        public void TestAddx2UndoAdd()
        {
            commandsList.Add(command1);
            commandsList.Add(command2);
            UndoCommand(1);
            commandsList.Add(command3);
            Assert.IsTrue(commandsList.CanUndo);
            Assert.IsFalse(commandsList.CanRedo);
            Assert.AreEqual(commandsList.UndoMsg, UNDO_STRING + COMMAND_NAME3);
        }
        [Test]
        public void TestAddx3Undox3()
        {
            commandsList.Add(command1);
            commandsList.Add(command2);
            commandsList.Add(command3);
            UndoCommand(3);
            Assert.IsFalse(commandsList.CanUndo);
            Assert.IsTrue(commandsList.CanRedo);
            Assert.AreEqual(commandsList.RedoMsg, REDO_STRING + COMMAND_NAME1);
        }
        [Test]
        public void TestAddx3Undox3Redox3()
        {
            commandsList.Add(command1);
            commandsList.Add(command2);
            commandsList.Add(command3);
            UndoCommand(3);
            RedoCommand(3);
            Assert.IsTrue(commandsList.CanUndo);
            Assert.IsFalse(commandsList.CanRedo);
            Assert.AreEqual(commandsList.UndoMsg, UNDO_STRING + COMMAND_NAME3);
        } 
        #endregion Tests

        #region Tool functions
        private void UndoCommand(int numActions)
        {
            for(int i = 0; i < numActions; i++)
            {
                commandsList.Undo();
            }
        }
        private void RedoCommand(int numActions)
        {
            for (int i = 0; i < numActions; i++)
            {
                commandsList.Redo();
            }
        }
        #endregion Tool functions
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior)
Australia Australia
I have never shared my work online before. Now time has come. I recently started a Software Development Toolbox project. Anyone is welcome to view and add your share to it.

Comments and Discussions