public void StoreElements_ThenRetrieve_SeesAllElements()
        {
            WithUniqueTempRegKey(regKey =>
            {
                // Arrange
                var repository = new RegistryXmlRepository(regKey);

                // Act
                repository.StoreElement(new XElement("element1"), friendlyName: null);
                repository.StoreElement(new XElement("element2"), friendlyName: null);
                repository.StoreElement(new XElement("element3"), friendlyName: null);
                var allElements = repository.GetAllElements();

                // Assert
                var orderedNames = allElements.Select(el => el.Name.LocalName).OrderBy(name => name);
                Assert.Equal(new[] { "element1", "element2", "element3" }, orderedNames);
            });
        }
        public void StoreElement_WithValidFriendlyName_UsesFriendlyName()
        {
            WithUniqueTempRegKey(regKey =>
            {
                // Arrange
                var element = XElement.Parse("<element1 />");
                var repository = new RegistryXmlRepository(regKey);

                // Act
                repository.StoreElement(element, "valid-friendly-name");

                // Assert
                var valueNames = regKey.GetValueNames();
                var valueName = valueNames.Single(); // only one value should've been created

                // value name should be "valid-friendly-name"
                Assert.Equal("valid-friendly-name", valueName, StringComparer.OrdinalIgnoreCase);

                // value contents should be "<element1 />"
                var parsedElement = XElement.Parse(regKey.GetValue(valueName) as string);
                XmlAssert.Equal("<element1 />", parsedElement);
            });
        }
        public void StoreElement_WithInvalidFriendlyName_CreatesNewGuidAsName(string friendlyName)
        {
            WithUniqueTempRegKey(regKey =>
            {
                // Arrange
                var element = XElement.Parse("<element1 />");
                var repository = new RegistryXmlRepository(regKey);

                // Act
                repository.StoreElement(element, friendlyName);

                // Assert
                var valueNames = regKey.GetValueNames();
                var valueName = valueNames.Single(); // only one value should've been created

                // value name should be "{GUID}"
                Guid parsedGuid = Guid.Parse(valueName as string);
                Assert.NotEqual(Guid.Empty, parsedGuid);

                // value contents should be "<element1 />"
                var parsedElement = XElement.Parse(regKey.GetValue(valueName) as string);
                XmlAssert.Equal("<element1 />", parsedElement);
            });
        }