Exemplo n.º 1
0
        public void DsfDateTimeActivity_Execute_Blank_ShouldHaveNoErrorWithDebugOutput()
        {
            //------------Setup for test--------------------------
            const string varName = "[[dt]]";
            var          act     = new DsfDotNetDateTimeActivity
            {
                DateTime                  = "",
                InputFormat               = "",
                OutputFormat              = "",
                TimeModifierType          = "",
                TimeModifierAmount        = 0,
                Result                    = varName,
                TimeModifierAmountDisplay = 0.ToString(CultureInfo.InvariantCulture)
            };
            var dataMock = new Mock <IDSFDataObject>();

            dataMock.Setup(o => o.IsDebugMode()).Returns(() => true);
            var executionEnvironment = new ExecutionEnvironment();

            dataMock.Setup(o => o.Environment).Returns(executionEnvironment);
            var data = dataMock.Object;

            //------------Execute Test---------------------------
            act.Execute(data, 0);
            //------------Assert Results-------------------------
            var debugout = act.GetDebugOutputs(executionEnvironment, 0);
            var value    = executionEnvironment.EvalAsListOfStrings(varName, 0);

            Assert.AreEqual(1, value.Count);
            Assert.IsTrue(DateTime.TryParse(value[0], out DateTime datetimeResult), $"Failed to parse value: {value[0]} as a DateTime");
            Assert.AreEqual(false, debugout[0].ResultsList[0].HasError);
            Assert.AreEqual(varName, debugout[0].ResultsList[0].Variable);
            Assert.AreEqual(DebugItemResultType.Variable, debugout[0].ResultsList[0].Type);
        }
Exemplo n.º 2
0
        public void DsfDateTimeActivity_Execute_InvalidDateTime_ShouldHaveErrorWithDebugOutput()
        {
            //------------Setup for test--------------------------
            const string varName = "[[dt]]";
            var          act     = new DsfDotNetDateTimeActivity
            {
                DateTime                  = "a/p/R",
                InputFormat               = "",
                OutputFormat              = "",
                TimeModifierType          = "",
                TimeModifierAmount        = 1,
                Result                    = varName,
                TimeModifierAmountDisplay = 1.ToString(CultureInfo.InvariantCulture)
            };
            var dataMock = new Mock <IDSFDataObject>();

            dataMock.Setup(o => o.IsDebugMode()).Returns(() => true);
            var executionEnvironment = new ExecutionEnvironment();

            dataMock.Setup(o => o.Environment).Returns(executionEnvironment);
            var data = dataMock.Object;

            var timeBefore = DateTime.Now;

            //------------Execute Test---------------------------
            var activity = act.Execute(data, 0);
            //------------Assert Results-------------------------
            var timeAfter = DateTime.Now;

            var debugout = act.GetDebugOutputs(executionEnvironment, 0);
            var value    = executionEnvironment.EvalAsListOfStrings(varName, 0);

            Assert.AreEqual(value.Count, 1);
            Assert.AreEqual("", value[0]);
            Assert.AreEqual(false, debugout[0].ResultsList[0].HasError);
            Assert.AreEqual(varName, debugout[0].ResultsList[0].Variable);
            Assert.AreEqual(DebugItemResultType.Variable, debugout[0].ResultsList[0].Type);

            Assert.AreEqual("The string was not recognized as a valid DateTime. There is an unknown word starting at index 0.", executionEnvironment.FetchErrors());
        }