Esempio n. 1
0
        internal static FtpNodeInformation ToFtpNode(this string operand)
        {
            var match      = regDirectory.Match(operand);
            var dictionary = new System.Collections.Generic.Dictionary <string, string>();

            if (match.Success)
            {
                return(new FtpNodeInformation
                {
                    NodeType = match.Groups["type"].Value.Trim().ToNodeType(),
                    Name = match.Groups["name"].Value.Trim(),
                    Size = match.Groups["size"].Value.ParseOrDefault(),
                    DateModified = match.Groups["modify"].Value.ParseExactOrDefault("yyyyMMddHHmmss")
                });
            }
            else
            {
                dictionary = operand.Split(';')
                             .Select(s => s.Split('='))
                             .ToDictionary(strings => strings.Length == 2
                                                          ? strings[0]
                                                          : "name",
                                           strings => strings.Length == 2
                                                           ? strings[1]
                                                           : strings[0]);
                return(new FtpNodeInformation
                {
                    NodeType = dictionary.GetValueOrDefault("type").Trim().ToNodeType(),
                    Name = dictionary.GetValueOrDefault("name").Trim(),
                    Size = dictionary.GetValueOrDefault("size").ParseOrDefault(),
                    DateModified = dictionary.GetValueOrDefault("modify").ParseExactOrDefault("yyyyMMddHHmmss")
                });
            }
        }
        public void GetValueOrDefault_Test()
        {
            var dict = new System.Collections.Generic.Dictionary <string, string>()
            {
                { "123", "xxx" },
                { "456", "yyy" },
                { "789", "" }
            };

            var v1 = dict.GetValueOrDefault("123", "33");

            Assert.Equal("xxx", v1);

            var v2 = dict.GetValueOrDefault("111", "xx");

            Assert.Equal("xx", v2);

            var v3 = dict.GetValueOrDefault("789", "x");

            Assert.Equal("", v3);
        }
Esempio n. 3
0
            public void Should_Return_DefaultValue_If_Value_Does_Not_Exist()
            {
                // Given
                var defaultValue = "defaultValue";
                var dictionary   = new System.Collections.Generic.Dictionary <string, string> {
                    { "foo", "bar" }
                };

                // When
                var result = dictionary.GetValueOrDefault("bar", defaultValue);

                // Then
                result.ShouldBe(defaultValue);
            }
Esempio n. 4
0
            public void Should_Return_Value_If_Exists()
            {
                // Given
                var key        = "foo";
                var value      = "bar";
                var dictionary = new System.Collections.Generic.Dictionary <string, string> {
                    { key, value }
                };

                // When
                var result = dictionary.GetValueOrDefault(key, null);

                // Then
                result.ShouldBe(value);
            }