示例#1
0
        public void Can_handle_speacial_data_types()
        {
            // Arrange
            var schema = new Schema();

            schema.AddRange(new IField[]
            {
                new AvatarField("avatar"),
                new TemplateField("tempate")
                {
                    Value = "{avatar}"
                },
                new DummyImageURLField("dummy image"),
                new DigitSequenceField("digit sequence")
                {
                    Format = "###-@@@"
                },
                new StateField("state"),
                new ParagraphsField("paragraph"),
                new NatoPhoneticField("nato"),
                new FormulaField("formula", "2+2")
            });

            var sut = new MockarooClient();

            // Act
            var data    = sut.FetchDataAsync(schema, 1).Result;
            var results = JArray.Parse(Encoding.UTF8.GetString(data)).ToString(Formatting.Indented);

            // Assert
            results.ShouldNotBeNullOrEmpty();
            Diff.Approve(schema, ".json");
            //Diff.Approve(results, ".json", "result");
        }
示例#2
0
    public override string Resolve(string name, IEnumerable <Parameter> parameters, string[] args)
    {
        var rowsets = parameters.OfType <RowSetParameter>().ToDictionary(p => p.Name);
        var scalars = parameters.OfType <ScalarParameter>().ToDictionary(p => p.Name);

        var input_rowset  = rowsets["input"];
        var input_schema  = input_rowset.Schema;
        var output_cols   = input_schema.Columns.Reverse().ToList();
        var output_schema = new Schema();

        output_schema.AddRange(output_cols);

        string input_schema_str  = input_rowset.Schema.ToString();
        string output_schema_str = output_schema.ToString();

        string select_clause = string.Join(",", output_cols.Select(c => c.Name));

        //Generate
        var sb_def = new StringBuilder();

        sb_def.AppendFormat("FUNC {0}\n", name);
        sb_def.AppendFormat(" RETURN ROWSET({0})\n", output_schema_str);
        sb_def.AppendFormat(" PARAMS({0} ROWSET( {1}) )\n", input_rowset.Name, input_schema_str);
        sb_def.AppendFormat("BEGIN\n");
        sb_def.AppendFormat(" rs1=SELECT {0} FROM {1};\n", select_clause, input_rowset.Name);
        sb_def.AppendFormat("END FUNC\n");
        string def = sb_def.ToString();

        return(def);
    }
示例#3
0
        public void Can_fetch_raw_data_from_server()
        {
            // Arrange
            var limit  = 2;
            var sut    = new MockarooClient();
            var fields = GetAllFieldTypes().ToArray();

            var schema = new Schema();

            schema.AddRange(fields);

            // Act
            var data   = sut.FetchDataAsync(schema, limit, Format.JSON).Result;
            var result = JArray.Parse(Encoding.UTF8.GetString(data));

            // Assert
            result.Count.ShouldBe(limit);
            Console.WriteLine(result.ToString());
        }