Example #1
0
        public void TestCopyView()
        {
            WeightedAverageView copied = (WeightedAverageView)_myView.CloneView();

            Assert.IsTrue(_myView.FieldNameWeight.Equals(copied.FieldNameWeight));
            Assert.IsTrue(_myView.FieldNameX.Equals(copied.FieldNameX));
        }
Example #2
0
        private void TryParameter(Object[] @params, String fieldNameX, String fieldNameW)
        {
            _factory.SetViewParameters(_viewFactoryContext, TestViewSupport.ToExprListMD(@params));
            _factory.Attach(SupportEventTypeFactory.CreateBeanType(typeof(SupportMarketDataBean)), SupportStatementContextFactory.MakeContext(), null, null);
            WeightedAverageView view = (WeightedAverageView)_factory.MakeView(SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext());

            Assert.AreEqual(fieldNameX, view.FieldNameX.ToExpressionStringMinPrecedenceSafe());
            Assert.AreEqual(fieldNameW, view.FieldNameWeight.ToExpressionStringMinPrecedenceSafe());
        }
Example #3
0
        public void SetUp()
        {
            // Set up sum view and a test child view
            EventType type = WeightedAverageView.CreateEventType(SupportStatementContextFactory.MakeContext(), null, 1);

            WeightedAverageViewFactory factory = new WeightedAverageViewFactory();

            factory.FieldNameX      = SupportExprNodeFactory.MakeIdentNodeMD("Price");
            factory.EventType       = type;
            factory.FieldNameWeight = SupportExprNodeFactory.MakeIdentNodeMD("Volume");
            _myView = new WeightedAverageView(factory, SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext());

            _childView = new SupportBeanClassView(typeof(SupportMarketDataBean));
            _myView.AddView(_childView);
        }
        public void TestCanReuse()
        {
            _factory.SetViewParameters(_viewFactoryContext, TestViewSupport.ToExprListMD(new Object[] { "Price", "Volume" }));
            _factory.Attach(SupportEventTypeFactory.CreateBeanType(typeof(SupportMarketDataBean)), SupportStatementContextFactory.MakeContext(), null, null);
            Assert.IsFalse(_factory.CanReuse(new FirstElementView(null)));
            EventType type = WeightedAverageView.CreateEventType(SupportStatementContextFactory.MakeContext(), null, 1);
            WeightedAverageViewFactory factoryTwo = new WeightedAverageViewFactory();

            factoryTwo.FieldNameX      = SupportExprNodeFactory.MakeIdentNodeMD("Price");
            factoryTwo.EventType       = type;
            factoryTwo.FieldNameWeight = SupportExprNodeFactory.MakeIdentNodeMD("Price");
            Assert.IsFalse(_factory.CanReuse(new WeightedAverageView(factoryTwo, SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext())));
            factoryTwo.FieldNameWeight = SupportExprNodeFactory.MakeIdentNodeMD("Volume");
            Assert.IsTrue(_factory.CanReuse(new WeightedAverageView(factoryTwo, SupportStatementContextFactory.MakeAgentInstanceViewFactoryContext())));
        }
        public void Attach(EventType parentEventType, StatementContext statementContext, ViewFactory optionalParentFactory, IList <ViewFactory> parentViewFactories)
        {
            ExprNode[] validated = ViewFactorySupport.Validate(ViewName, parentEventType, statementContext, _viewParameters, true);

            if (validated.Length < 2)
            {
                throw new ViewParameterException(ViewParamMessage);
            }
            if ((!validated[0].ExprEvaluator.ReturnType.IsNumeric()) || (!validated[1].ExprEvaluator.ReturnType.IsNumeric()))
            {
                throw new ViewParameterException(ViewParamMessage);
            }

            _fieldNameX      = validated[0];
            _fieldNameWeight = validated[1];
            _additionalProps = StatViewAdditionalProps.Make(validated, 2, parentEventType);
            _eventType       = WeightedAverageView.CreateEventType(statementContext, _additionalProps, _streamNumber);
        }