Beispiel #1
0
        protected override void Initialize()
        {
            var debugProfilesBlock = new TransformBlock <ILaunchSettings, IProjectVersionedValue <IReadOnlyList <IEnumValue> > >(
                update =>
            {
                // Compute the new enum values from the profile provider
                var generatedResult = DebugProfileEnumValuesGenerator.GetEnumeratorEnumValues(update).ToImmutableList();
                _dataSourceVersion++;
                var dataSources = ImmutableDictionary <NamedIdentity, IComparable> .Empty.Add(DataSourceKey, DataSourceVersion);
                return(new ProjectVersionedValue <IReadOnlyList <IEnumValue> >(generatedResult, dataSources));
            });

            var broadcastBlock = new BroadcastBlock <IProjectVersionedValue <IReadOnlyList <IEnumValue> > >(b => b);

            _launchProfileProviderLink = LaunchSettingProvider.SourceBlock.LinkTo(
                debugProfilesBlock,
                linkOptions: new DataflowLinkOptions {
                PropagateCompletion = true
            });

            _debugProviderLink = debugProfilesBlock.LinkTo(broadcastBlock, new DataflowLinkOptions {
                PropagateCompletion = true
            });

            _publicBlock = broadcastBlock.SafePublicize();
        }
        public async Task DebugProfileEnumValuesGenerator_GetListsValuesAsyncTests()
        {
            var testProfiles = new Mock <ILaunchSettings>();

            testProfiles.Setup(m => m.ActiveProfile).Returns(() => { return(_profiles[1]); });
            testProfiles.Setup(m => m.Profiles).Returns(() =>
            {
                return(_profiles.ToImmutableList());
            });

            var moqProfileProvider = new Mock <ILaunchSettingsProvider>();

            moqProfileProvider.Setup(p => p.CurrentSnapshot).Returns(testProfiles.Object);
            var threadingService = new IProjectThreadingServiceMock();

            var generator =
                new DebugProfileEnumValuesGenerator(moqProfileProvider.Object, threadingService);
            ICollection <IEnumValue> results = await generator.GetListedValuesAsync();

            Assert.True(results.Count == 4);
            Assert.True(results.ElementAt(0).Name == "Profile1" && results.ElementAt(0).DisplayName == "Profile1");
            Assert.True(results.ElementAt(1).Name == "MyCommand" && results.ElementAt(1).DisplayName == "MyCommand");
            Assert.True(results.ElementAt(2).Name == "Foo" && results.ElementAt(2).DisplayName == "Foo");
            Assert.True(results.ElementAt(3).Name == "Bar" && results.ElementAt(3).DisplayName == "Bar");
        }
        protected override void Initialize()
        {
            IPropagatorBlock <IProjectVersionedValue <ILaunchSettings>, IProjectVersionedValue <IReadOnlyList <IEnumValue> > > debugProfilesBlock = DataflowBlockSlim.CreateTransformBlock <IProjectVersionedValue <ILaunchSettings>, IProjectVersionedValue <IReadOnlyList <IEnumValue> > >(
                update =>
            {
                // Compute the new enum values from the profile provider
                var generatedResult = DebugProfileEnumValuesGenerator.GetEnumeratorEnumValues(update.Value).ToImmutableList();
                _dataSourceVersion++;
                ImmutableDictionary <NamedIdentity, IComparable> dataSources = ImmutableDictionary <NamedIdentity, IComparable> .Empty.Add(DataSourceKey, DataSourceVersion);
                return(new ProjectVersionedValue <IReadOnlyList <IEnumValue> >(generatedResult, dataSources));
            });

            IBroadcastBlock <IProjectVersionedValue <IReadOnlyList <IEnumValue> > > broadcastBlock = DataflowBlockSlim.CreateBroadcastBlock <IProjectVersionedValue <IReadOnlyList <IEnumValue> > >();

            // The interface has two definitions of SourceBlock: one from
            // ILaunchSettingsProvider, and one from IProjectValueDataSource<T> (via
            // IVersionedLaunchSettingsProvider). We need the cast to pick the proper one.
            _launchProfileProviderLink = ((IProjectValueDataSource <ILaunchSettings>)LaunchSettingProvider).SourceBlock.LinkTo(
                debugProfilesBlock,
                linkOptions: DataflowOption.PropagateCompletion);

            JoinUpstreamDataSources(LaunchSettingProvider);

            _debugProviderLink = debugProfilesBlock.LinkTo(broadcastBlock, DataflowOption.PropagateCompletion);

            _publicBlock = broadcastBlock.SafePublicize();
        }
        public async Task DebugProfileEnumValuesGenerator_TryCreateEnumValueAsyncTests()
        {
            var testProfiles = new Mock <ILaunchSettings>();

            testProfiles.Setup(m => m.ActiveProfile).Returns(() => { return(_profiles[1]); });
            testProfiles.Setup(m => m.Profiles).Returns(() =>
            {
                return(_profiles.ToImmutableList());
            });

            var moqProfileProvider = new Mock <ILaunchSettingsProvider>();

            moqProfileProvider.Setup(p => p.CurrentSnapshot).Returns(testProfiles.Object);
            var threadingService = new IProjectThreadingServiceMock();

            var generator =
                new DebugProfileEnumValuesGenerator(moqProfileProvider.Object, threadingService);

            Assert.False(generator.AllowCustomValues);
            IEnumValue result = await generator.TryCreateEnumValueAsync("Profile1");

            Assert.True(result.Name == "Profile1" && result.DisplayName == "Profile1");
            result = await generator.TryCreateEnumValueAsync("MyCommand");

            Assert.True(result.Name == "MyCommand" && result.DisplayName == "MyCommand");

            // case sensitive check
            result = await generator.TryCreateEnumValueAsync("mycommand");

            Assert.Null(result);

            result = await generator.TryCreateEnumValueAsync("Foo");

            Assert.True(result.Name == "Foo" && result.DisplayName == "Foo");
            result = await generator.TryCreateEnumValueAsync("Bar");

            Assert.True(result.Name == "Bar" && result.DisplayName == "Bar");
        }