Ejemplo n.º 1
0
        public void Composition_Encodes()
        {
            var actual = ImaginationConfigCodec
                         .EncodeString(ImaginationConfig.Create(
                                           "http://www.google.com",
                                           Natural.Create(1).Match(x => x, _ => null),
                                           new[] { "url1" },
                                           Option <string> .Some("*****@*****.**"),
                                           AdvancedOptions.Create(
                                               false,
                                               SuperAdvancedOptions.Create(
                                                   ChildFieldType.Case1(1)
                                                   )
                                               )
                                           ));

            var expected =
                @"{
  ""url"": ""http://www.google.com"",
  ""connectionLimit"": 1,
  ""trustedUrls"": [
    ""url1""
  ],
  ""email"": ""*****@*****.**"",
  ""advanced"": {
    ""allowNonsecure"": false,
    ""superAdvanced"": {
      ""childField"": 1
    }
  }
}".Replace("\r\n", "\n");

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 2
0
        public void Composition_AppropriateData_Decodes()
        {
            var actual = ImaginationConfigCodec
                         .DecodeString(@"{
                'url': 'http://www.google.com',
                'connectionLimit': 1,
                'trustedUrls': ['url1'],
                'email': '*****@*****.**',
                'advanced': {
                    'allowNonsecure': false,
                    'superAdvanced': { 'childField': 1 }
                }
            }")
                         .Match(
                v => v,
                e => null
                );

            var expected = ImaginationConfig.Create(
                "http://www.google.com",
                Natural.Create(1).Match(x => x, _ => null),
                new[] { "url1" },
                Option <string> .Some("*****@*****.**"),
                AdvancedOptions.Create(
                    false,
                    SuperAdvancedOptions.Create(
                        ChildFieldType.Case1(1)
                        )
                    )
                );

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 3
0
 private ImaginationConfig(
     string url,
     Natural connectionLimit,
     IEnumerable <string> trustedUrls,
     Option <string> email,
     AdvancedOptions advanced)
 {
     this.Url             = url;
     this.ConnectionLimit = connectionLimit;
     this.TrustedUrls     = trustedUrls;
     this.Email           = email;
     this.Advanced        = advanced;
 }
Ejemplo n.º 4
0
 public static ImaginationConfig Create(
     string url,
     Natural connectionLimit,
     IEnumerable <string> trustedUrls,
     Option <string> email,
     AdvancedOptions advanced)
 {
     return(new ImaginationConfig(
                url,
                connectionLimit,
                trustedUrls,
                email,
                advanced
                ));
 }