コード例 #1
0
        public void CheckPropertyChangedTriggered()
        {
            // Scan all RIs for each prop marked with [IsSerializedForLocalRepositoryAttribute] try to change and verify prop changed triggered

            //Arrange

            // Get all Repository items
            IEnumerable <Type> list = GetRepoItems();

            ErrCounter = 0;

            //Act
            foreach (Type type in list)
            {
                Console.WriteLine("CheckPropertyChangedTriggered for type: " + type.FullName);
                if (type.IsAbstract)
                {
                    continue;
                }
                RepositoryItemBase RI = (RepositoryItemBase)Activator.CreateInstance(type);
                RI.PropertyChanged += RIPropertyChanged;
                RI.StartDirtyTracking();

                // Properties
                foreach (PropertyInfo PI in RI.GetType().GetProperties())
                {
                    var token = PI.GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                    if (token == null)
                    {
                        continue;
                    }
                    Console.WriteLine("CheckPropertyChangedTriggered for property: " + PI.Name);
                    object newValue = GetNewValue(PI.PropertyType, PI.GetValue(RI));
                    if (newValue != null)
                    {
                        RI.DirtyStatus = eDirtyStatus.NoChange;
                        prop           = null;
                        PI.SetValue(RI, newValue);
                        CheckChanges(RI, PI.Name, newValue);
                    }
                }


                // Fields
                foreach (FieldInfo FI in RI.GetType().GetFields())
                {
                    var token = FI.GetCustomAttribute(typeof(IsSerializedForLocalRepositoryAttribute));
                    if (token == null)
                    {
                        continue;
                    }
                    Console.WriteLine("CheckPropertyChangedTriggered for property: " + FI.Name);
                    object newValue = GetNewValue(FI.FieldType, FI.GetValue(RI));
                    if (newValue != null)
                    {
                        RI.DirtyStatus = eDirtyStatus.NoChange;
                        prop           = null;
                        FI.SetValue(RI, newValue);
                        CheckChanges(RI, FI.Name, newValue);
                    }
                }
            }
            //Assert
            Assert.AreEqual(0, ErrCounter);
        }