Пример #1
0
        public void StoreElement_WithInvalidFriendlyName_CreatesNewGuidAsName(string friendlyName)
        {
            WithUniqueTempDirectory(dirInfo =>
            {
                // Arrange
                var element    = XElement.Parse("<element1 />");
                var repository = new FileSystemXmlRepository(dirInfo);

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

                // Assert
                var fileInfos = dirInfo.GetFiles();
                var fileInfo  = fileInfos.Single(); // only one file should've been created

                // filename should be "{GUID}.xml"
                var filename = fileInfo.Name;
                Assert.EndsWith(".xml", filename, StringComparison.OrdinalIgnoreCase);
                var filenameNoSuffix = filename.Substring(0, filename.Length - ".xml".Length);
                Guid parsedGuid      = Guid.Parse(filenameNoSuffix);
                Assert.NotEqual(Guid.Empty, parsedGuid);

                // file contents should be "<element1 />"
                var parsedElement = XElement.Parse(File.ReadAllText(fileInfo.FullName));
                XmlAssert.Equal("<element1 />", parsedElement);
            });
        }
Пример #2
0
        public void StoreElements_ThenRetrieve_SeesAllElements()
        {
            WithUniqueTempDirectory(dirInfo =>
            {
                // Arrange
                var repository = new FileSystemXmlRepository(dirInfo);

                // 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()
        {
            WithUniqueTempDirectory(dirInfo =>
            {
                // Arrange
                var element = XElement.Parse("<element1 />");
                var repository = new FileSystemXmlRepository(dirInfo);

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

                // Assert
                var fileInfos = dirInfo.GetFiles();
                var fileInfo = fileInfos.Single(); // only one file should've been created

                // filename should be "valid-friendly-name.xml"
                Assert.Equal("valid-friendly-name.xml", fileInfo.Name, StringComparer.OrdinalIgnoreCase);

                // file contents should be "<element1 />"
                var parsedElement = XElement.Parse(File.ReadAllText(fileInfo.FullName));
                XmlAssert.Equal("<element1 />", parsedElement);
            });
        }
Пример #4
0
        public void StoreElement_WithValidFriendlyName_UsesFriendlyName()
        {
            WithUniqueTempDirectory(dirInfo =>
            {
                // Arrange
                var element    = XElement.Parse("<element1 />");
                var repository = new FileSystemXmlRepository(dirInfo);

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

                // Assert
                var fileInfos = dirInfo.GetFiles();
                var fileInfo  = fileInfos.Single(); // only one file should've been created

                // filename should be "valid-friendly-name.xml"
                Assert.Equal("valid-friendly-name.xml", fileInfo.Name, StringComparer.OrdinalIgnoreCase);

                // file contents should be "<element1 />"
                var parsedElement = XElement.Parse(File.ReadAllText(fileInfo.FullName));
                XmlAssert.Equal("<element1 />", parsedElement);
            });
        }
        public void StoreElement_WithInvalidFriendlyName_CreatesNewGuidAsName(string friendlyName)
        {
            WithUniqueTempDirectory(dirInfo =>
            {
                // Arrange
                var element = XElement.Parse("<element1 />");
                var repository = new FileSystemXmlRepository(dirInfo);

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

                // Assert
                var fileInfos = dirInfo.GetFiles();
                var fileInfo = fileInfos.Single(); // only one file should've been created

                // filename should be "{GUID}.xml"
                var filename = fileInfo.Name;
                Assert.EndsWith(".xml", filename, StringComparison.OrdinalIgnoreCase);
                var filenameNoSuffix = filename.Substring(0, filename.Length - ".xml".Length);
                Guid parsedGuid = Guid.Parse(filenameNoSuffix);
                Assert.NotEqual(Guid.Empty, parsedGuid);

                // file contents should be "<element1 />"
                var parsedElement = XElement.Parse(File.ReadAllText(fileInfo.FullName));
                XmlAssert.Equal("<element1 />", parsedElement);
            });
        }
        public void StoreElements_ThenRetrieve_SeesAllElements()
        {
            WithUniqueTempDirectory(dirInfo =>
            {
                // Arrange
                var repository = new FileSystemXmlRepository(dirInfo);

                // 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);
            });
        }