Пример #1
0
        public void OnePosition_TotalValue()
        {
            double expectedAmount = 12345.67;
            Position pos = new Position { SecurityIdentifier = "foo", Amount = expectedAmount };
            Portfolio target = new Portfolio();

            target.Positions.Add(pos);

            Assert.AreEqual(expectedAmount, target.TotalValue);
        }
Пример #2
0
        public void TwoPositions_TotalValue()
        {
            Position posOne = new Position { SecurityIdentifier = "foo", Amount = 12345.67 };
            Position posTwo = new Position { SecurityIdentifier = "bar", Amount = 23456.78 };
            double expectedAmount = posOne.Amount + posTwo.Amount;
            Portfolio target = new Portfolio();

            target.Positions.Add(posOne);
            target.Positions.Add(posTwo);

            Assert.AreEqual(expectedAmount, target.TotalValue);
        }
Пример #3
0
        public void AddingPositionFiresPropertyChangedEvent()
        {
            Position posOne = new Position { SecurityIdentifier = "foo", Amount = 12345.67 };
            Position posTwo = new Position { SecurityIdentifier = "bar", Amount = 23456.78 };
            Portfolio target = new Portfolio();
            target.Positions.Add(posOne);

            List<string> propertyNames = new List<string>();
            target.PropertyChanged += (s, e) =>
            {
                propertyNames.Add(e.PropertyName);
            };

            target.Positions.Add(posTwo);

            Assert.AreEqual(1, propertyNames.Count(), "checking propertyNames Count");
            Assert.IsTrue(propertyNames.Contains(String.Empty), "checking that propertyNames contains empty string");
        }
Пример #4
0
        public void ChangingPositionAmountInOldCollectionDoesNotFirePropertyChangedEvent()
        {
            Position posOne = new Position { SecurityIdentifier = "foo", Amount = 12345.67 };
            Position posTwo = new Position { SecurityIdentifier = "bar", Amount = 23456.78 };
            Position posThree = new Position { SecurityIdentifier = "bletch", Amount = 34567.89 };
            ObservableCollection<Position> origPositions = new ObservableCollection<Position>{
                posOne,
                posTwo
            };
            ObservableCollection<Position> newPositions = new ObservableCollection<Position> { posThree };
            Portfolio target = new Portfolio { Positions = origPositions };
            target.Positions = newPositions;

            List<string> propertyNames = new List<string>();
            target.PropertyChanged += (s, e) =>
            {
                propertyNames.Add(e.PropertyName);
            };

            posOne.Amount = 45678.90;

            Assert.AreEqual(0, propertyNames.Count(), "checking propertyNames Count");
        }
Пример #5
0
        public void ChangingRemovedPositionDoesNotFirePropertyChangedEvent()
        {
            Position posOne = new Position { SecurityIdentifier = "foo", Amount = 12345.67 };
            Position posTwo = new Position { SecurityIdentifier = "bar", Amount = 23456.78 };
            Portfolio target = new Portfolio();
            target.Positions.Add(posOne);
            target.Positions.Add(posTwo);

            target.Positions.Remove(posTwo);

            List<string> propertyNames = new List<string>();
            target.PropertyChanged += (s, e) =>
            {
                propertyNames.Add(e.PropertyName);
            };

            posTwo.Amount = 34567.89;

            Assert.AreEqual(0, propertyNames.Count(), "checking propertyNames Count");
        }
Пример #6
0
        public void ReplacingPositionsCollectionFiresPropertyChangedEvent()
        {
            Position posOne = new Position { SecurityIdentifier = "foo", Amount = 12345.67 };
            Position posTwo = new Position { SecurityIdentifier = "bar", Amount = 23456.78 };
            Position posThree = new Position { SecurityIdentifier = "bletch", Amount = 34567.89 };
            ObservableCollection<Position> origPositions = new ObservableCollection<Position>{
                posOne,
                posTwo
            };
            ObservableCollection<Position> newPositions = new ObservableCollection<Position> { posThree };
            Portfolio target = new Portfolio { Positions = origPositions };

            List<string> propertyNames = new List<string>();
            target.PropertyChanged += (s, e) =>
            {
                propertyNames.Add(e.PropertyName);
            };

            target.Positions = newPositions;

            Assert.AreEqual(1, propertyNames.Count(), "checking propertyNames Count");
            Assert.IsTrue(propertyNames.Contains(String.Empty), "checking that propertyNames contains String.Empty");
        }