Exemplo n.º 1
0
            public static void CorrectlySetsPropertyValuesForPrimitiveTypeConstants()
            {
                Expression <Func <PrimitiveTypes, PrimitiveTypes, PrimitiveTypes> > createAggregateFunc
                    = (aggregate, current) => new PrimitiveTypes
                    {
                    Boolean = true,
                    Byte    = 2,
                    Char    = 'x',
                    Double  = 3.14159,
                    Int16   = -3,
                    Int32   = 58,
                    Int64   = 249,
                    SByte   = -3,
                    Single  = 2.158f,
                    UInt16  = 4,
                    UInt32  = 7,
                    UInt64  = 12,
                    };

                string actual = CreateAggregateVisitor.Visit(createAggregateFunc);

                Assert.Equal("{ \"Boolean\": true, \"Byte\": 2, \"Char\": \"x\", \"Double\": 3.14159,"
                             + " \"Int16\": -3, \"Int32\": 58, \"Int64\": 249, \"SByte\": -3, \"Single\": 2.158,"
                             + " \"UInt16\": 4, \"UInt32\": 7, \"UInt64\": 12 }",
                             actual);
            }
Exemplo n.º 2
0
            public static void ReturnsObjectLiteralForNewObjectExpressionWithArguments()
            {
                Expression <Func <SaleAggregate, Sale, SaleAggregate> > createAggregateFunc = (aggregate, current)
                                                                                              => new SaleAggregate(1);

                string actual = CreateAggregateVisitor.Visit(createAggregateFunc);

                Assert.Equal("{ \"count\": 1, \"averageAmount\": 0.0, \"totalAmount\": 0.0 }", actual);
            }
Exemplo n.º 3
0
            public static void ReturnsObjectLiteralForMemberInitializationExpressionWithoutArguments()
            {
                Expression <Func <SaleAggregate, Sale, SaleAggregate> > createAggregateFunc = (aggregate, current)
                                                                                              => new SaleAggregate {
                    TotalAmount = 2.5m
                };

                string actual = CreateAggregateVisitor.Visit(createAggregateFunc);

                Assert.Equal("{ \"count\": 0, \"averageAmount\": 0.0, \"totalAmount\": 2.5 }", actual);
            }
Exemplo n.º 4
0
            public static void CorrectlySetsPropertyValuesForDateTimeConstant()
            {
                var dateTime = DateTime.Now;

                Expression <Func <Container <DateTime>, Container <DateTime>, Container <DateTime> > > createAggregateFunc
                    = (aggregate, current) => new Container <DateTime> {
                    Value = dateTime
                    };

                string actual = CreateAggregateVisitor.Visit(createAggregateFunc);

                Assert.Equal("{ \"value\": \"" + dateTime.ToString("O", CultureInfo.InvariantCulture) + "\" }",
                             actual);
            }
Exemplo n.º 5
0
 private static string GetCreateAggregateFunction(QueryExpressions expressions)
 {
     return("return " + CreateAggregateVisitor.Visit(expressions.CreateAggregateExpression) + ";");
 }