コード例 #1
0
        public void StoreElement_WithInvalidFriendlyName_CreatesNewGuidAsName(string friendlyName)
        {
            WithUniqueTempDirectory(dirInfo =>
            {
                // Arrange
                var element    = XElement.Parse("<element1 />");
                var repository = new FileSystemXmlRepository(dirInfo, NullLoggerFactory.Instance);

                // 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 Directory_Property()
        {
            WithUniqueTempDirectory(dirInfo =>
            {
                // Arrange
                var repository = new FileSystemXmlRepository(dirInfo, NullLoggerFactory.Instance);

                // Act
                var retVal = repository.Directory;

                // Assert
                Assert.Equal(dirInfo, retVal);
            });
        }
コード例 #3
0
        public void GetAllElements_EmptyOrNonexistentDirectory_ReturnsEmptyCollection()
        {
            WithUniqueTempDirectory(dirInfo =>
            {
                // Arrange
                var repository = new FileSystemXmlRepository(dirInfo, NullLoggerFactory.Instance);

                // Act
                var allElements = repository.GetAllElements();

                // Assert
                Assert.Equal(0, allElements.Count);
            });
        }
コード例 #4
0
        public void GetAllElements_EmptyOrNonexistentDirectory_ReturnsEmptyCollection()
        {
            WithUniqueTempDirectory(dirInfo =>
            {
                // Arrange
                var repository = new FileSystemXmlRepository(dirInfo);

                // Act
                var allElements = repository.GetAllElements();

                // Assert
                Assert.Equal(0, allElements.Count);
            });
        }
コード例 #5
0
        public void Logs_DockerEphemeralFolders()
        {
            // Arrange
            var loggerFactory = new StringLoggerFactory(LogLevel.Warning);

            WithUniqueTempDirectory(dirInfo =>
            {
                // Act
                var repo = new FileSystemXmlRepository(dirInfo, loggerFactory);

                // Assert
                Assert.Contains(Resources.FormatFileSystem_EphemeralKeysLocationInContainer(dirInfo.FullName), loggerFactory.ToString());
            });
        }
コード例 #6
0
        public void Directory_Property()
        {
            WithUniqueTempDirectory(dirInfo =>
            {
                // Arrange
                var repository = new FileSystemXmlRepository(dirInfo);

                // Act
                var retVal = repository.Directory;

                // Assert
                Assert.Equal(dirInfo, retVal);
            });
        }
コード例 #7
0
        public void StoreElements_ThenRetrieve_SeesAllElements()
        {
            WithUniqueTempDirectory(dirInfo =>
            {
                // Arrange
                var repository = new FileSystemXmlRepository(dirInfo, NullLoggerFactory.Instance);

                // 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);
            });
        }
コード例 #8
0
        public void StoreElement_WithValidFriendlyName_UsesFriendlyName()
        {
            WithUniqueTempDirectory(dirInfo =>
            {
                // Arrange
                var element    = XElement.Parse("<element1 />");
                var repository = new FileSystemXmlRepository(dirInfo, NullLoggerFactory.Instance);

                // 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);
            });
        }
コード例 #9
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);
            });
        }
コード例 #10
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);
            });
        }
コード例 #11
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);
            });
        }