Esempio n. 1
0
        public void ValidRegistration_CreatesCorrectKeys(string extension, string generator, string contextGuid)
        {
            var    numTimesCreateKeyCalled  = 0;
            var    numTimesSetupValueCalled = 0;
            var    createdKey    = "";
            var    createdSubkey = "";
            object subkeyValue   = "";

            var registration = RegistrationContextFactory.CreateInstance(key =>
            {
                numTimesCreateKeyCalled++;
                createdKey = key;
            }, (subkey, value) =>
            {
                numTimesSetupValueCalled++;
                createdSubkey = subkey;
                subkeyValue   = value;
            });

            var attr = new GeneratorExtensionRegistrationAttribute(extension, generator, contextGuid);

            attr.Register(registration);

            Assert.Equal(1, numTimesCreateKeyCalled);
            Assert.Equal($"Generators\\{contextGuid}\\{extension}", createdKey);
            Assert.Equal(1, numTimesSetupValueCalled);
            Assert.Equal(string.Empty, createdSubkey);
            Assert.Equal(generator, subkeyValue);
        }
Esempio n. 2
0
        public void RemoteCodeGeneratorRegistrationAttribute_ValidRegistration_CreatesCorrectKeys(string generatorGuid, string generatorName, string contextGuid, bool generatesDesignTimeSource, bool generatesSharedDesignTimeSource)
        {
            var  numTimesCreateKeyCalled = 0;
            var  createdKey = "";
            Guid parsedGeneratorGuid;

            Guid.TryParse(generatorGuid, out parsedGeneratorGuid);

            var setValueCallCounts = new Dictionary <string, int>();
            var setValueValues     = new Dictionary <string, object>();
            var expectedSubkeys    = 2 + (generatesDesignTimeSource ? 1 : 0) + (generatesSharedDesignTimeSource ? 1 : 0);

            var registration = RegistrationContextFactory.CreateInstance(key =>
            {
                numTimesCreateKeyCalled++;
                createdKey = key;
            }, (subkey, value) =>
            {
                setValueCallCounts[subkey] = setValueCallCounts.ContainsKey(subkey) ? setValueCallCounts[subkey] + 1 : 1;
                setValueValues[subkey]     = value;
            });

            var attr = new RemoteCodeGeneratorRegistrationAttribute(generatorGuid, generatorName, contextGuid)
            {
                GeneratesDesignTimeSource       = generatesDesignTimeSource,
                GeneratesSharedDesignTimeSource = generatesSharedDesignTimeSource
            };

            attr.Register(registration);

            Assert.Equal(1, numTimesCreateKeyCalled);
            Assert.Equal($"Generators\\{contextGuid}\\{generatorName}", createdKey);
            Assert.Equal(expectedSubkeys, setValueCallCounts.Count);

            setValueCallCounts.ToList().ForEach(pair =>
            {
                Assert.Equal(1, pair.Value);
            });

            Assert.Equal(generatorName, setValueValues[string.Empty]);
            Assert.Equal(parsedGeneratorGuid.ToString("B"), setValueValues["CLSID"]);
            if (generatesDesignTimeSource)
            {
                Assert.Equal(1, setValueValues["GeneratesDesignTimeSource"]);
            }
            if (generatesSharedDesignTimeSource)
            {
                Assert.Equal(1, setValueValues["GeneratesSharedDesignTimeSource"]);
            }
        }