Exemplo n.º 1
0
        private void RegisterKnownCommandTypes()
        {
            foreach (AssemblyPart ap in Deployment.Current.Parts)
            {
                StreamResourceInfo sri = Application.GetResourceStream(new Uri(ap.Source, UriKind.Relative));
                Assembly           asm = new AssemblyPart().Load(sri.Stream);

                foreach (var type in asm.GetTypes())
                {
                    if (type.BaseType == typeof(Command))
                    {
                        KnownCommandTypes.Add(type);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void DataTransferObject_PublicPropertySetterCallsOnPropertyChanged_Succeeds()
        {
            List <string> ignoredDtoProperties = new List <string> ()
            {
                "Notifications"
            };

            IDtoFactory dtoFactory = new DtoFactory();

            foreach (AssemblyPart assemblyPart in Deployment.Current.Parts)
            {
                StreamResourceInfo sri =
                    Application.GetResourceStream(
                        new Uri(assemblyPart.Source, UriKind.Relative));

                Assembly dtoAssembly = new AssemblyPart().Load(sri.Stream);

                var allDtos = dtoAssembly.GetTypes()
                              .Where(t => typeof(EditableDataTransferObject).IsAssignableFrom(t) && !t.IsAbstract)
                              .Select
                                  (t => new
                {
                    Dto     = dtoFactory.CreateDto(t),
                    PropSet = t.GetProperties()
                              .Select
                                  (p => new
                    {
                        PropertyName   = p.Name,
                        PropertySetter = p.GetSetMethod()
                    }
                                  )
                              .Where(p => p.PropertySetter != null &&
                                     !ignoredDtoProperties.Contains(p.PropertyName))
                }
                                  );

                foreach (var d in allDtos)
                {
                    INotifyPropertyChanged inpc = d.Dto;

                    foreach (var p in d.PropSet)
                    {
                        // Setup event handler for the property being examined
                        string changedPropertyName = String.Empty;
                        // use named variable (as opposed to anonymous delegate) so we can unsubscribe
                        PropertyChangedEventHandler inpcOnPropertyChanged =
                            (obj, e) => changedPropertyName = e.PropertyName;
                        inpc.PropertyChanged += inpcOnPropertyChanged;

                        // Simulate property change by invoking setter directly
                        p.PropertySetter.Invoke(d.Dto, new object[] { null });

                        Assert.AreEqual(
                            p.PropertyName,
                            changedPropertyName,
                            String.Format(
                                "Offending DTO type::property {0}::{1}",
                                d.Dto.GetType(),
                                p.PropertyName));

                        // Reset event handler
                        inpc.PropertyChanged -= inpcOnPropertyChanged;
                    }
                }
            }
        }