Esempio n. 1
0
        public void AddStrategy_Compute_HandlesDoubleMaxValuesWithZero()
        {
            AddStrategy   strategy = new AddStrategy();
            List <double> inputs   = new List <double> {
                0, double.MaxValue
            };

            Assert.DoesNotThrowAsync(() => strategy.Compute(inputs), Resources.ListOutOfRange);
        }
Esempio n. 2
0
        public void AddStrategy_Compute_HandlesDoubleMaxValues()
        {
            AddStrategy   strategy = new AddStrategy();
            List <double> inputs   = new List <double> {
                double.MaxValue, double.MaxValue
            };

            Assert.ThrowsAsync <CalculatorException>(() => strategy.Compute(inputs));
        }
        /// <summary>
        /// Sets up the strategy to be executed
        /// </summary>
        /// <param name="initializeStrategy">Holds info to initialize the given strategy</param>
        private void InitializeUserStrategy(InitializeStrategy initializeStrategy)
        {
            try
            {
                if (_asyncClassLogger.IsInfoEnabled)
                {
                    _asyncClassLogger.Info("Setting up user strategy to run: " + initializeStrategy.StrategyType.FullName,
                                           _type.FullName, "InitializeUserStrategy");
                }

                // Get new Key.
                string key = ApplicationIdGenerator.NextId();

                // Save Strategy details in new Strategy Executor object
                StrategyExecutor strategyExecutor = new StrategyExecutor(key, initializeStrategy.StrategyType, initializeStrategy.CtorArguments);

                // Add to local map
                _strategiesCollection.AddOrUpdate(key, strategyExecutor, (ky, value) => strategyExecutor);

                //Register Event
                strategyExecutor.StatusChanged     += OnStatusChanged;
                strategyExecutor.ExecutionReceived += OnExecutionArrived;

                // Save Brief info of constructor parameters
                StringBuilder briefInfo = new StringBuilder();

                // Add Strategy Description
                briefInfo.Append(LoadCustomStrategy.GetCustomClassSummary(initializeStrategy.StrategyType));
                briefInfo.Append(" :: ");

                // Add Parameters Description
                foreach (object ctorArgument in initializeStrategy.CtorArguments)
                {
                    briefInfo.Append(ctorArgument.ToString());
                    briefInfo.Append("|");
                }

                // Create object to add to AddStrattegy.cs object
                SelectedStrategy selectedStrategy = new SelectedStrategy
                {
                    Key       = key,
                    Symbol    = initializeStrategy.CtorArguments[3].ToString(),
                    BriefInfo = briefInfo.ToString()
                };

                // Create object to pass to event aggregator.
                AddStrategy addStrategy = new AddStrategy(selectedStrategy);

                // Publish event to notify listeners.
                EventSystem.Publish <AddStrategy>(addStrategy);
            }
            catch (Exception exception)
            {
                _asyncClassLogger.Error(exception, _type.FullName, "InitializeUserStrategy");
            }
        }
Esempio n. 4
0
        public async Task AddStrategy_Compute_HandlesNegativeValues()
        {
            AddStrategy   strategy = new AddStrategy();
            List <double> inputs   = new List <double> {
                -1, 2, -4, 1, 7, 0, 8, 0, 12, 5730203
            };
            var result = await strategy.Compute(inputs);

            Assert.AreEqual(5730228, result, 0.00000001); // The tolerance delta used here is due to the fact that double is used instead of decimal for speed
        }
Esempio n. 5
0
        public async Task AddStrategy_Compute_ReturnsCorrectResult()
        {
            AddStrategy   strategy = new AddStrategy();
            List <double> inputs   = new List <double> {
                3, 4.2, 6
            };
            var result = await strategy.Compute(inputs);

            Assert.AreEqual(13.2, result, 0.00000001); // The tolerance delta used here is due to the fact that double is used instead of decimal for speed
        }
        /// <summary>
        /// Adds selected strategy to strategy view
        /// </summary>
        /// <param name="addStrategy"></param>
        private void AddSelectedStrategy(AddStrategy addStrategy)
        {
            try
            {
                if (Logger.IsDebugEnabled)
                {
                    Logger.Debug("Adding strategy to view: " + addStrategy.SelectedStrategy, _type.FullName,
                                 "AddSelectedStrategy");
                }

                // Add to observable collection
                _strategiesCollection.Add(addStrategy.SelectedStrategy);
            }
            catch (Exception exception)
            {
                Logger.Error(exception, _type.FullName, "AddSelectedStrategy");
            }
        }
Esempio n. 7
0
        public void AddStrategy_Compute_HandlesNullInput()
        {
            AddStrategy strategy = new AddStrategy();

            Assert.ThrowsAsync <CalculatorException>(() => strategy.Compute(MockInputs.NullList));
        }