public async Task ImplicitlyDeactivated_WhenActiveConfigurationChangesAndNoLongerMatches_Fires()
        {
            var project = ConfiguredProjectFactory.ImplementProjectConfiguration("Debug|AnyCPU");
            var service = CreateInstance(project, out ProjectValueDataSource <IConfigurationGroup <ProjectConfiguration> > source);

            Assert.False(service.IsImplicitlyActive);

            var configurationGroups = IConfigurationGroupFactory.CreateFromConfigurationNames("Debug|AnyCPU");
            await source.SendAsync(configurationGroups);

            await Task.Delay(500);  // Wait for data to be sent

            Assert.True(service.IsImplicitlyActive);

            int callCount = 0;

            service.ImplicitlyDeactivated += (object sender, EventArgs e) =>
            {
                callCount++;
                return(Task.CompletedTask);
            };

            configurationGroups = IConfigurationGroupFactory.CreateFromConfigurationNames("Debug|x86");
            await source.SendAndCompleteAsync(configurationGroups, service.TargetBlock);

            Assert.Equal(1, callCount);
        }
        public async Task WhenActiveConfigurationChangesAndNoLongerMatches_CallsDeactivateAsync()
        {
            var project = ConfiguredProjectFactory.ImplementProjectConfiguration("Debug|AnyCPU");
            var service = CreateInstance(project, out ProjectValueDataSource <IConfigurationGroup <ProjectConfiguration> > source);

            service.Load();

            Assert.False(service.IsImplicitlyActive);

            var configurationGroups = IConfigurationGroupFactory.CreateFromConfigurationNames("Debug|AnyCPU");
            await source.SendAsync(configurationGroups);

            await Task.Delay(500);  // Wait for data to be sent

            Assert.True(service.IsImplicitlyActive);

            int callCount             = 0;
            var implicitActiveService = IImplicitlyActiveServiceFactory.ImplementDeactivateAsync(() =>
            {
                callCount++;
            });

            service.ImplicitlyActiveServices.Add(implicitActiveService);

            configurationGroups = IConfigurationGroupFactory.CreateFromConfigurationNames("Debug|x86");
            await source.SendAndCompleteAsync(configurationGroups, service.TargetBlock);

            Assert.Equal(1, callCount);
        }
        public async Task IsImplicitlyActive_WhenAccessedInImplicitlyDeactivatedHandler_ReturnsFalse()
        {
            var project = ConfiguredProjectFactory.ImplementProjectConfiguration("Debug|AnyCPU");
            var service = CreateInstance(project, out ProjectValueDataSource <IConfigurationGroup <ProjectConfiguration> > source);

            Assert.False(service.IsImplicitlyActive);

            var configurationGroups = IConfigurationGroupFactory.CreateFromConfigurationNames("Debug|AnyCPU");
            await source.SendAsync(configurationGroups);

            await Task.Delay(500);  // Wait for data to be sent

            Assert.True(service.IsImplicitlyActive);

            bool?result = null;

            service.ImplicitlyDeactivated += (object sender, EventArgs e) =>
            {
                result = ((ConfiguredProjectImplicitActivationTracking)sender).IsImplicitlyActive;
                return(Task.CompletedTask);
            };

            configurationGroups = IConfigurationGroupFactory.CreateFromConfigurationNames("Debug|x86");
            await source.SendAndCompleteAsync(configurationGroups, service.TargetBlock);

            Assert.False(result);
        }
        public async Task IsImplicitlyActive_WhenAccessedInDeactivateAsync_ReturnsFalse()
        {
            var project = ConfiguredProjectFactory.ImplementProjectConfiguration("Debug|AnyCPU");
            var service = CreateInstance(project, out ProjectValueDataSource <IConfigurationGroup <ProjectConfiguration> > source);

            service.Load();

            Assert.False(service.IsImplicitlyActive);

            var configurationGroups = IConfigurationGroupFactory.CreateFromConfigurationNames("Debug|AnyCPU");
            await source.SendAsync(configurationGroups);

            await Task.Delay(500);  // Wait for data to be sent

            Assert.True(service.IsImplicitlyActive);

            bool?result = null;
            var  implicitActiveService = IImplicitlyActiveServiceFactory.ImplementDeactivateAsync(() =>
            {
                result = service.IsImplicitlyActive;
            });

            service.ImplicitlyActiveServices.Add(implicitActiveService);

            configurationGroups = IConfigurationGroupFactory.CreateFromConfigurationNames("Debug|x86");
            await source.SendAndCompleteAsync(configurationGroups, service.TargetBlock);

            Assert.False(result);
        }
        public async Task IsImplicitlyActiveTask_WhenActiveConfigurationChangesAndMatches_ReturnsCompletedTask(string[] configurations, string currentConfiguration)
        {
            var project = ConfiguredProjectFactory.ImplementProjectConfiguration(currentConfiguration);
            var service = CreateInstance(project, out ProjectValueDataSource <IConfigurationGroup <ProjectConfiguration> > source);

            var result = service.IsImplicitlyActiveTask;

            var configurationGroups = IConfigurationGroupFactory.CreateFromConfigurationNames(configurations);
            await source.SendAndCompleteAsync(configurationGroups, service.TargetBlock);

            Assert.True(result.Status == TaskStatus.RanToCompletion);
        }
        public async Task IsImplicitlyActive_WhenActiveConfigurationChangesAndMatches_ReturnsTrue(string[] configurations, string currentConfiguration)
        {
            var project = ConfiguredProjectFactory.ImplementProjectConfiguration(currentConfiguration);
            var service = CreateInstance(project, out ProjectValueDataSource <IConfigurationGroup <ProjectConfiguration> > source);

            Assert.False(service.IsImplicitlyActive); // Just to init

            var configurationGroups = IConfigurationGroupFactory.CreateFromConfigurationNames(configurations);
            await source.SendAndCompleteAsync(configurationGroups, service.TargetBlock);

            Assert.True(service.IsImplicitlyActive);
        }
        public async Task ImplicitlyActivated_WhenActiveConfigurationChangesAndMatches_Fires(string[] configurations, string currentConfiguration)
        {
            var project = ConfiguredProjectFactory.ImplementProjectConfiguration(currentConfiguration);
            var service = CreateInstance(project, out ProjectValueDataSource <IConfigurationGroup <ProjectConfiguration> > source);

            int callCount = 0;

            service.ImplicitlyActivated += (object sender, EventArgs e) =>
            {
                callCount++;
                return(Task.CompletedTask);
            };

            var configurationGroups = IConfigurationGroupFactory.CreateFromConfigurationNames(configurations);
            await source.SendAndCompleteAsync(configurationGroups, service.TargetBlock);

            Assert.Equal(1, callCount);
        }
예제 #8
0
        public async Task WhenActiveConfigurationChanges_LoadsConfiguredProject(string[] configurationNames)
        {
            var configurationGroups = IConfigurationGroupFactory.CreateFromConfigurationNames(configurationNames);

            var results = new List <string>();
            var project = UnconfiguredProjectFactory.ImplementLoadConfiguredProjectAsync(configuration =>
            {
                results.Add(configuration.Name);
                return(Task.FromResult <ConfiguredProject>(null));
            });

            var loader = CreateInstance(project, out ProjectValueDataSource <IConfigurationGroup <ProjectConfiguration> > source);
            await loader.InitializeAsync();

            // Change the active configurations
            await source.SendAndCompleteAsync(configurationGroups, loader.TargetBlock);

            Assert.Equal(configurationNames, results);
        }
        public async Task IsImplicitlyActiveTask_CompletedStateChangesOverLifetime()
        {
            var project = ConfiguredProjectFactory.ImplementProjectConfiguration("Debug|AnyCPU");
            var service = CreateInstance(project, out ProjectValueDataSource <IConfigurationGroup <ProjectConfiguration> > source);

            Assert.False(service.IsImplicitlyActive);

            // Should now be considered active
            var configurationGroups = IConfigurationGroupFactory.CreateFromConfigurationNames("Debug|AnyCPU");
            await source.SendAsync(configurationGroups);

            Assert.True(service.IsImplicitlyActiveTask.Wait(500));

            configurationGroups = IConfigurationGroupFactory.CreateFromConfigurationNames("Debug|x86");
            await source.SendAndCompleteAsync(configurationGroups, service.TargetBlock);

            // Should now be considered in-active
            Assert.False(service.IsImplicitlyActiveTask.IsCompleted);
        }
        public async Task WhenActiveConfigurationChangesAndMatches_CallsActivateAsync(string[] configurations, string currentConfiguration)
        {
            var project = ConfiguredProjectFactory.ImplementProjectConfiguration(currentConfiguration);
            var service = CreateInstance(project, out ProjectValueDataSource <IConfigurationGroup <ProjectConfiguration> > source);

            service.Load();

            int callCount             = 0;
            var implicitActiveService = IImplicitlyActiveServiceFactory.ImplementActivateAsync(() =>
            {
                callCount++;
            });

            service.ImplicitlyActiveServices.Add(implicitActiveService);

            var configurationGroups = IConfigurationGroupFactory.CreateFromConfigurationNames(configurations);
            await source.SendAndCompleteAsync(configurationGroups, service.TargetBlock);

            Assert.Equal(1, callCount);
        }
예제 #11
0
        public async Task Dispose_WhenInitialized_DisposesSubscription()
        {
            int callCount = 0;
            UnconfiguredProject project = UnconfiguredProjectFactory.ImplementLoadConfiguredProjectAsync(configuration => {
                callCount++;
                return(Task.FromResult <ConfiguredProject>(null));
            });

            var loader = CreateInstance(project, out ProjectValueDataSource <IConfigurationGroup <ProjectConfiguration> > source);
            await loader.InitializeAsync();

            loader.Dispose();

            var configurationGroups = IConfigurationGroupFactory.CreateFromConfigurationNames("Debug|AnyCPU");

            // Change the active configurations
            await source.SendAndCompleteAsync(configurationGroups, loader.TargetBlock);

            // Should not be listening
            Assert.Equal(0, callCount);
        }
예제 #12
0
        public async Task InitializeAsync_CanNotInitializeTwice()
        {
            var results = new List <string>();
            var project = UnconfiguredProjectFactory.ImplementLoadConfiguredProjectAsync(configuration => {
                results.Add(configuration.Name);
                return(Task.FromResult <ConfiguredProject>(null));
            });

            var loader = CreateInstance(project, out var source);

            await loader.InitializeAsync();

            await loader.InitializeAsync();

            var configurationGroups = IConfigurationGroupFactory.CreateFromConfigurationNames("Debug|AnyCPU");

            // Change the active configurations
            await source.SendAndCompleteAsync(configurationGroups, loader.TargetBlock);

            Assert.Equal(new string[] { "Debug|AnyCPU" }, results);
        }
예제 #13
0
        public async Task WhenProjectUnloading_DoesNotLoadConfiguredProject()
        {
            var tasksService = IUnconfiguredProjectTasksServiceFactory.CreateWithUnloadedProject <ConfiguredProject>();

            int callCount = 0;
            UnconfiguredProject project = UnconfiguredProjectFactory.ImplementLoadConfiguredProjectAsync(configuration => {
                callCount++;
                return(Task.FromResult <ConfiguredProject>(null));
            });

            var loader = CreateInstance(project, tasksService, out ProjectValueDataSource <IConfigurationGroup <ProjectConfiguration> > source);
            await loader.InitializeAsync();

            var configurationGroups = IConfigurationGroupFactory.CreateFromConfigurationNames("Debug|AnyCPU");

            // Change the active configurations
            await source.SendAndCompleteAsync(configurationGroups, loader.TargetBlock);

            // Should not be listening
            Assert.Equal(0, callCount);
        }