Esempio n. 1
0
 public void NewGridShouldHaveProperCellCounts()
 {
     for (var r = 0; r < grid.RowCount; r++)
     {
         for (var c = 0; c < grid.ColumnCount; c++)
         {
             Assert.IsNotNull(grid.GetCellText(r, c), $"grid.GetCellText({r},{c}) should not be null");
         }
     }
 }
Esempio n. 2
0
        public async Task OrderStreamConvertsToGrid()
        {
            //Need to create delay for the first set of orders to come in
            var statusEvent = new ManualResetEvent(false);
            var isFired     = false;

            //Listen for orders flowing in as json
            connection.ServerJsonReceived += (sender, jsonArgs) =>
            {
                var args = ServerDataReceivedEventArgs <BlotterOrder> .DeserializeMessage(jsonArgs.RawJson);

                var grid = new FastWindowGridModel <BlotterOrder>(10);
                grid.LoadRowJson(jsonArgs.RowsJson);

                //Make sure data matches
                var props = typeof(BlotterOrder).GetProperties();
                Assert.AreEqual(props.Length, grid.ColumnCount, "Grid column count should match the number of public properties in BlotterOrders");

                for (var r = 0; r < grid.RowCount; r++)
                {
                    for (var c = 0; c < grid.ColumnCount; c++)
                    {
                        var cellstr = grid.GetCellText(r, c).ToLower();
                        var propval = props[c].GetValue(args.Data.ElementAt(r));

                        if (propval is DateTime)
                        {
                            var cellval = DateTimeOffset.Parse(cellstr, CultureInfo.InvariantCulture).DateTime;
                            Console.WriteLine($"({r},{c}): {propval} = {cellval}: {(DateTime)propval == cellval}");
                            Assert.AreEqual(propval, cellval);
                        }
                        else
                        {
                            var propstr = propval?.ToString().ToLower() ?? string.Empty;
                            Console.WriteLine($"({r},{c}): {propstr} = {cellstr}: {propstr == cellstr}");
                            Assert.AreEqual(propstr, cellstr);
                        }
                    }
                }

                Console.WriteLine("Property match completed successfully.");
                isFired = true;
                statusEvent.Set();
            };

            //Listen for orders flowing in as byte arrays
            connection.ServerBytesReceived += (sender, bytesArgs) =>
            {
                var args = ServerDataReceivedEventArgs <BlotterOrder> .DeserializeMessage(bytesArgs.RawData);

                var grid = new FastWindowGridModel <BlotterOrder>(10);
                grid.LoadRowObjects(bytesArgs.RowData);

                //Make sure data matches
                var props = typeof(BlotterOrder).GetProperties();
                Assert.AreEqual(props.Length, grid.ColumnCount, "Grid column count should match the number of public properties in BlotterOrders");

                for (var r = 0; r < grid.RowCount; r++)
                {
                    for (var c = 0; c < grid.ColumnCount; c++)
                    {
                        var cellstr = (grid.GetCellText(r, c) ?? "").ToLower();
                        var propval = props[c].GetValue(args.Data.ElementAt(r));

                        if (propval is DateTime)
                        {
                            var cellval = DateTimeOffset.Parse(cellstr, CultureInfo.InvariantCulture).DateTime;
                            Console.WriteLine($"({r},{c}): {propval} = {cellval}: {(DateTime)propval == cellval}");
                            Assert.AreEqual(propval, cellval);
                        }
                        else
                        {
                            var propstr = propval?.ToString().ToLower() ?? string.Empty;
                            Console.WriteLine($"({r},{c}): {propstr} = {cellstr}: {propstr == cellstr}");
                            Assert.AreEqual(propstr, cellstr);
                        }
                    }
                }

                Console.WriteLine("Property match completed successfully.");
                isFired = true;
                statusEvent.Set();
            };

            //Make the call to open the orders stream and wait for the ServerDataReceived event to fire TWICE
            var callname = AppSettings["ordersStreamCall"];

            Assert.IsNotNull(callname, "AppSettings should contain an entry for 'ordersStreamCall'");

            //Call with sorting by price DESC
            var call = new ServerCall(1, callname, new List <object> {
                0, 10, "DESC", "price"
            });
            await connection.Send(call);

            statusEvent.WaitOne(5000);

            Assert.IsTrue(isFired, "ServerDataReceived event should fired.");
        }