示例#1
0
        public void TestOverwrite()
        {
            var mockCore      = MockRepository.GenerateMock <ICentipedeCore>();
            var mockVariables = MockRepository.GenerateMock <IDictionary <string, object> >();

            const string fromName = "fromow";
            const string toName   = "toow";

            Cp action = new Cp(mockVariables, mockCore)
            {
                From           = fromName,
                To             = toName,
                AllowOverWrite = false
            };

            using (new FileForTesting(fromName))
                using (new FileForTesting(toName))
                {
                    try
                    {
                        action.Run();
                        Assert.Fail("Did not fail when not overwriting");
                    }
                    catch
                    { }
                    action.AllowOverWrite = true;
                    try
                    {
                        action.Run();
                    }
                    catch
                    {
                        Assert.Fail("Failed to overwrite");
                    }
                }
        }
示例#2
0
        public void TestInterpolation()
        {
            const string fromName = "from1";
            const string fromText = "<from>";
            const string toName   = "to2";
            const string toText   = "<to>";

            var mockCore         = MockRepository.GenerateMock <ICentipedeCore>();
            var mockVariables    = MockRepository.GenerateMock <IDictionary <string, object> >();
            var mockPythonEngine = MockRepository.GenerateStub <IPythonEngine>();

            mockCore.Expect(c => c.PythonEngine).Return(mockPythonEngine);

            var bcFrom = MockRepository.GenerateMock <IPythonByteCode>();
            var bcTo   = MockRepository.GenerateMock <IPythonByteCode>();


            mockPythonEngine.Expect(e => e.Compile(Arg <String> .Is.Equal(fromText),
                                                   Arg <SourceCodeType> .Is.Anything))
            .Return(bcFrom);

            mockPythonEngine.Expect(e => e.Evaluate(bcFrom))
            .Return(fromName);

            mockPythonEngine.Expect(e => e.Compile(Arg <String> .Is.Equal(toText),
                                                   Arg <SourceCodeType> .Is.Anything))
            .Return(bcTo);

            mockPythonEngine.Expect(e => e.Evaluate(bcTo)).Return(toName);

            var action = new Cp(mockVariables, mockCore)
            {
                From = string.Format("{{{0}}}", fromText),
                To   = string.Format("{{{0}}}", toText)
            };

            using (new FileForTesting(fromName))
                using (new FileForTesting(toName, create: false))
                {
                    action.Run();
                }

            mockPythonEngine.VerifyAllExpectations();
        }
示例#3
0
        public void TestMissingFile()
        {
            var mockCore      = MockRepository.GenerateMock <ICentipedeCore>();
            var mockVariables = MockRepository.GenerateMock <IDictionary <string, object> >();

            const string fromName = "fromow";
            const string toName   = "toow";

            Cp action = new Cp(mockVariables, mockCore)
            {
                From           = fromName,
                To             = toName,
                AllowOverWrite = false
            };

            try
            {
                action.Run();
                Assert.Fail("Did not fail with missing file");
            }
            catch
            { }
        }
示例#4
0
        public void TestRun()
        {
            var mockCore      = MockRepository.GenerateMock <ICentipedeCore>();
            var mockVariables = MockRepository.GenerateMock <IDictionary <string, object> >();

            const string fromName = "from";
            const string toName   = "to";

            Cp action = new Cp(mockVariables, mockCore)
            {
                From = fromName,
                To   = toName
            };
            const int length = 1024;

            using (new FileForTesting(fromName, length))
                using (new FileForTesting(toName, create: false))
                {
                    action.Run();

                    Assert.IsTrue(File.Exists(toName));
                    Assert.AreEqual(File.ReadAllText(toName).Length, length);
                }
        }