Exemplo n.º 1
0
        /// <summary>
        /// Check that error handling works as expected when a serialization
        /// error occurs.
        /// </summary>
        public void JsonBuilder_VerifyErrorHandling()
        {
            _jsonBuilderElement = new TestJsonBuilderElement(_loggerFactory, true);

            // Create a moderately complex set of values so that we can
            // validate the complex value handling.
            _elementDataMock.Setup(ed => ed.AsDictionary()).
            Returns(new Dictionary <string, object>()
            {
                { "property", new List <NestedData>()
                  {
                      new NestedData(_loggerFactory.CreateLogger <NestedData>(), _pipeline.Object)
                      {
                          Value1 = "abc", Value2 = 123
                      },
                      new NestedData(_loggerFactory.CreateLogger <NestedData>(), _pipeline.Object)
                      {
                          Value1 = "xyz", Value2 = 789
                      }
                  } },
            });

            // Configure the property meta-data as needed for
            // this test.
            var testElementMetaData = new Dictionary <string, IElementPropertyMetaData>();
            var nestedMetaData      = new List <IElementPropertyMetaData>()
            {
                new ElementPropertyMetaData(_testEngine.Object, "value1", typeof(string), true),
                new ElementPropertyMetaData(_testEngine.Object, "value2", typeof(int), true),
            };
            var p1 = new ElementPropertyMetaData(_testEngine.Object, "property", typeof(List <NestedData>), true, "", nestedMetaData);

            testElementMetaData.Add("property", p1);
            _propertyMetaData.Add("test", testElementMetaData);

            // Configure the flow data to record error that are added.
            Mock <IFlowData> flowData      = new Mock <IFlowData>();
            Exception        lastException = null;

            flowData.Setup(d => d.AddError(It.IsAny <Exception>(), _jsonBuilderElement)).Callback(
                (Exception ex, IFlowElement element) =>
            {
                lastException = ex;
            });
            var json = TestIteration(1, null, flowData);

            // Check that the error message was logged and contains
            // some of the expected content.
            // Checking for an exact match would be too brittle
            Assert.IsNotNull(lastException, "Expected an error to be logged but it was not");
            Assert.IsTrue(lastException.Message.Contains("abc"),
                          $"Logged message did not contain expected text 'abc'. {lastException.Message}");
            Assert.IsTrue(lastException.Message.Contains("xyz"),
                          $"Logged message did not contain expected text 'xyz'. {lastException.Message}");
            Assert.IsTrue(lastException.Message.Contains("123"),
                          $"Logged message did not contain expected text '123'. {lastException.Message}");
            Assert.IsTrue(lastException.Message.Contains("789"),
                          $"Logged message did not contain expected text '789'. {lastException.Message}");
        }
Exemplo n.º 2
0
        public void Init()
        {
            _testEngine = new Mock <IAspectEngine>();
            _testEngine.Setup(e => e.Properties).Returns(new List <IAspectPropertyMetaData>()
            {
                new AspectPropertyMetaData(_testEngine.Object, "property", typeof(string), "", new List <string>(), true),
                new AspectPropertyMetaData(_testEngine.Object, "jsproperty", typeof(JavaScript), "", new List <string>(), true)
            });
            _testEngine.Setup(e => e.ElementDataKey).Returns("test");

            _loggerFactory = new LoggerFactory();

            _jsonBuilderElement = new JsonBuilderElementBuilder(_loggerFactory)
                                  .Build();

            _elementDataMock = new Mock <IElementData>();
            _elementDataMock.Setup(ed => ed.AsDictionary()).
            Returns(new Dictionary <string, object>()
            {
                { "property", "thisIsAValue" },
                { "jsproperty", "var = 'some js code';" }
            });
        }
Exemplo n.º 3
0
        public void Init()
        {
            _testEngine = new Mock <IAspectEngine>();
            _testEngine.Setup(e => e.ElementDataKey).Returns("test");

            _loggerFactory = new LoggerFactory();

            _jsonBuilderElement = new JsonBuilderElementBuilder(_loggerFactory)
                                  .Build();

            _elementDataMock = new Mock <IElementData>();
            _elementDataMock.Setup(ed => ed.AsDictionary()).
            Returns(new Dictionary <string, object>()
            {
                { "property", "thisIsAValue" },
                { "jsproperty", "var = 'some js code';" }
            });

            _pipeline = new Mock <IPipeline>();
            _pipeline.Setup(p => p.GetHashCode()).Returns(1);
            _propertyMetaData = new Dictionary <string, IReadOnlyDictionary <string, IElementPropertyMetaData> >();
            _pipeline.Setup(p => p.ElementAvailableProperties).Returns(_propertyMetaData);
        }