コード例 #1
0
        public void VerifyInvestorNotNotifiedFirstTimeThresholdCrossedFromOppositeDirectionOfTrigger()
        {
            // Arrange
            var utstock = new StockUnitTestCaseExtension("TestStock", "TEST", 10.00);

            var uttriggers = new List <Trigger>()
            {
                new Trigger()
                {
                    Type           = Models.Enums.TriggerType.Sell,
                    Threshold      = 15.00,
                    Direction      = Models.Enums.TriggerDirection.FromAbove,
                    Sensitivity    = 0.5,
                    ClientNotified = false
                }
            };

            var utinvestor = new UnitTestInvestor()
            {
                InvestorId    = 1,
                Name          = "TestInvestor",
                StockTriggers = new Dictionary <string, List <Trigger> >()
            };

            utinvestor.StockTriggers.Add("TEST", uttriggers);

            utstock.Attach(utinvestor);

            //Act
            utstock.SetPrice(15.50);

            //Assert
            Assert.AreEqual(0, utinvestor.NotificationCount);
        }
コード例 #2
0
        public void VerifyInvestorsAddedToSubscriberList()
        {
            // Arrange
            var utstock    = new StockUnitTestCaseExtension("TestStock", "TEST", 10.00);
            var utinvestor = new UnitTestInvestor()
            {
                InvestorId = 1,
                Name       = "TestInvestor"
            };

            //Act
            utstock.Attach(utinvestor);

            //Assert
            Assert.AreEqual(1, utstock.Investors.Count);
        }
コード例 #3
0
        public void VerifyInvestorNotifiedWhenThresholdReachedOutsideFromDelta()
        {
            // Arrange
            var utstock = new StockUnitTestCaseExtension("TestStock", "TEST", 20.00);

            var uttriggers = new List <Trigger>()
            {
                new Trigger()
                {
                    Type           = Models.Enums.TriggerType.Sell,
                    Threshold      = 15.00,
                    Direction      = Models.Enums.TriggerDirection.FromAbove,
                    Sensitivity    = 1.00,
                    ClientNotified = false
                }
            };

            var utinvestor = new UnitTestInvestor()
            {
                InvestorId    = 1,
                Name          = "TestInvestor",
                StockTriggers = new Dictionary <string, List <Trigger> >()
            };

            utinvestor.StockTriggers.Add("TEST", uttriggers);

            utstock.Attach(utinvestor);

            //Act
            utstock.SetPrice(15.00);
            utstock.SetPrice(16.01);
            utstock.SetPrice(15.00);
            utstock.SetPrice(13.50);
            utstock.SetPrice(15.00);

            //Assert
            Assert.AreEqual(2, utinvestor.NotificationCount);
        }
コード例 #4
0
        public void VerifyInvestorNotNotifiedWhenOldPriceIsAlreadyBelowThreshold()
        {
            // Arrange
            var utstock = new StockUnitTestCaseExtension("TestStock", "TEST", 10.00);

            var uttriggers = new List <Trigger>()
            {
                new Trigger()
                {
                    Type           = Models.Enums.TriggerType.Buy,
                    Threshold      = 8.00,
                    Direction      = Models.Enums.TriggerDirection.FromAbove,
                    Sensitivity    = 1.00,
                    ClientNotified = false
                }
            };

            var utinvestor = new UnitTestInvestor()
            {
                InvestorId    = 1,
                Name          = "TestInvestor",
                StockTriggers = new Dictionary <string, List <Trigger> >()
            };

            utinvestor.StockTriggers.Add("TEST", uttriggers);

            utstock.Attach(utinvestor);

            //Act
            utstock.SetPrice(8.00);
            utstock.SetPrice(8.50);
            utstock.SetPrice(7.75);
            utstock.SetPrice(7.25);
            utstock.SetPrice(5.25);

            //Assert
            Assert.AreEqual(1, utinvestor.NotificationCount);
        }