public async Task Test_StartupException()
        {
            bool isDisposed = false;

            AssemblyUtils.SetEntryAssembly(GetType().Assembly);

            var applicationConfig = ApplicationConfigBuilder
                                    .Create()
                                    .WithApplicationName(ApplicationName)
                                    .WithScanDirectories(
                TestAssemblyDirectories
                )
                                    // Add all file starting with Dapplo and ending on .dll
                                    .WithAssemblyPatterns("Dapplo*")
                                    .BuildApplicationConfig();

            using (var bootstrapper = new ApplicationBootstrapper(applicationConfig))
            {
                bootstrapper.Configure();

                // Makes the startup break
                bootstrapper.Builder.Register(context => true);

                bootstrapper.RegisterForDisposal(SimpleDisposable.Create(() => isDisposed = true));

                // Initialize, so we can export
                Assert.True(await bootstrapper.InitializeAsync().ConfigureAwait(false), "Not initialized");

                // Start the composition, and IStartupActions
                await Assert.ThrowsAsync <NotSupportedException>(async() => await bootstrapper.StartupAsync().ConfigureAwait(false));
            }
            // Dispose automatically calls IShutdownActions
            Assert.True(isDisposed);
        }
예제 #2
0
        /// <summary>
        /// Create an observable for the INotifyPropertyChanged
        /// </summary>
        /// <param name="source">INotifyPropertyChanged</param>
        /// <param name="propertyNamePattern">Optional property name / pattern</param>
        /// <typeparam name="T">INotifyPropertyChanged</typeparam>
        /// <returns>IObservable with PropertyChangedEventArgs</returns>
        public static IObservable <PropertyChangedEventArgs> OnPropertyChanged <T>(this T source, string propertyNamePattern = null)
            where T : INotifyPropertyChanged
        {
            var observable = Observable.Create <PropertyChangedEventArgs>(observer =>
            {
                PropertyChangedEventHandler handler = (s, e) => observer.OnNext(e);
                source.PropertyChanged += handler;
                return(SimpleDisposable.Create(() => source.PropertyChanged -= handler));
            });

            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            // Create predicate
            Func <PropertyChangedEventArgs, bool> predicate;

            if (!string.IsNullOrEmpty(propertyNamePattern) && propertyNamePattern != "*")
            {
                predicate = propertyChangedEventArgs =>
                {
                    try
                    {
                        var propertyName = propertyChangedEventArgs.PropertyName;
                        return(string.IsNullOrEmpty(propertyName) || propertyName == "*" || propertyNamePattern == propertyName || Regex.IsMatch(propertyName, propertyNamePattern));
                    }
                    catch (Exception ex)
                    {
                        Log.Error().WriteLine(ex, "Error in predicate for OnPropertyChangedPattern");
                    }
                    return(false);
                };
            }
            else
            {
                predicate = args => true;
            }

            return(observable.Where(predicate));
        }