Exemple #1
0
        public void ShouldCollectWithoutChildPlans()
        {
            var metadata = new Dictionary <string, object>
            {
                {
                    Key, new Dictionary <string, object>
                    {
                        { "operatorType", "opType" },
                        { "dbHits", 5L },
                        { "rows", 10L },
                        { "args", new Dictionary <string, object> {
                              { "a", 1L }
                          } },
                        {
                            "identifiers", new List <object>
                            {
                                "a", "b", "c"
                            }
                        }
                    }
                }
            };
            var collector = new ProfiledPlanCollector();

            collector.Collect(metadata);

            collector.Collected.Should().BeEquivalentTo(new ProfiledPlan("opType",
                                                                         new Dictionary <string, object> {
                { "a", 1L }
            },
                                                                         new List <string> {
                "a", "b", "c"
            }, new List <IProfiledPlan>(), 5, 10, 0, 0, 0, 0));
        }
Exemple #2
0
        public void ShouldNotCollectIfNoValueIsGiven()
        {
            var collector = new ProfiledPlanCollector();

            collector.Collect(new Dictionary <string, object>());

            collector.Collected.Should().BeNull();
        }
Exemple #3
0
        public void ShouldNotCollectIfMetadataIsNull()
        {
            var collector = new ProfiledPlanCollector();

            collector.Collect(null);

            collector.Collected.Should().BeNull();
        }
Exemple #4
0
        public void ShouldNotCollectIfValueIsEmpty()
        {
            var collector = new ProfiledPlanCollector();

            collector.Collect(new Dictionary <string, object> {
                { Key, new Dictionary <string, object>() }
            });

            collector.Collected.Should().BeNull();
        }
Exemple #5
0
        public void ShouldThrowIfValueIsOfWrongType()
        {
            var metadata = new Dictionary <string, object> {
                { Key, true }
            };
            var collector = new ProfiledPlanCollector();

            var ex = Record.Exception(() => collector.Collect(metadata));

            ex.Should().BeOfType <ProtocolException>().Which
            .Message.Should()
            .Contain($"Expected '{Key}' metadata to be of type 'IDictionary<String,Object>', but got 'Boolean'.");
        }
Exemple #6
0
        public void ShouldThrowIfOperatorTypeIsMissing()
        {
            var metadata = new Dictionary <string, object>
            {
                {
                    Key, new Dictionary <string, object>
                    {
                        { "args", new Dictionary <string, object>() }
                    }
                }
            };
            var collector = new ProfiledPlanCollector();

            var ex = Record.Exception(() => collector.Collect(metadata));

            ex.Should().BeOfType <ProtocolException>().Which
            .Message.Should()
            .Be("Expected key 'operatorType' to be present in the dictionary, but could not find.");
        }
Exemple #7
0
        public void ShouldReturnSameCollected()
        {
            var metadata = new Dictionary <string, object>
            {
                {
                    Key, new Dictionary <string, object>
                    {
                        { "operatorType", "opType" },
                        { "dbHits", 5L },
                        { "rows", 10L }
                    }
                }
            };
            var collector = new ProfiledPlanCollector();

            collector.Collect(metadata);

            ((IMetadataCollector)collector).Collected.Should().BeSameAs(collector.Collected);
        }
Exemple #8
0
        public void ShouldCollectWithDefaultValues()
        {
            var metadata = new Dictionary <string, object>
            {
                {
                    Key, new Dictionary <string, object>
                    {
                        { "operatorType", "opType" },
                        { "dbHits", 5L },
                        { "rows", 10L }
                    }
                }
            };
            var collector = new ProfiledPlanCollector();

            collector.Collect(metadata);

            collector.Collected.Should().BeEquivalentTo(new ProfiledPlan("opType", new Dictionary <string, object>(),
                                                                         new List <string>(), new List <IProfiledPlan>(), 5, 10, 0, 0, 0, 0));
        }
Exemple #9
0
        public void ShouldCollectWithSpecifiedValues()
        {
            var metadata = new Dictionary <string, object>
            {
                {
                    Key, new Dictionary <string, object>
                    {
                        { "operatorType", "opType" },
                        { "dbHits", 5L },
                        { "rows", 10L },
                        { "pageCacheHits", 1L },
                        { "pageCacheMisses", 2L },
                        { "pageCacheHitRatio", 3.0 },
                        { "time", 4L }
                    }
                }
            };
            var collector = new ProfiledPlanCollector();

            collector.Collect(metadata);

            collector.Collected.Should().BeEquivalentTo(new ProfiledPlan("opType", new Dictionary <string, object>(),
                                                                         new List <string>(), new List <IProfiledPlan>(), 5, 10, 1, 2, 3, 4));
        }
Exemple #10
0
        public void ShouldCollectWithNestedChildPlans()
        {
            var metadata = new Dictionary <string, object>
            {
                {
                    Key, new Dictionary <string, object>
                    {
                        { "operatorType", "opType" },
                        { "dbHits", 5L },
                        { "rows", 10L },
                        { "args", new Dictionary <string, object> {
                              { "a", 1L }
                          } },
                        {
                            "identifiers", new List <object>
                            {
                                "a", "b", "c"
                            }
                        },
                        {
                            "children", new List <object>
                            {
                                new Dictionary <string, object>
                                {
                                    { "operatorType", "childOpType" },
                                    { "dbHits", 15L },
                                    { "rows", 20L },
                                    { "args", new Dictionary <string, object> {
                                          { "b", 2L }
                                      } },
                                    {
                                        "identifiers", new List <object>
                                        {
                                            "d", "e"
                                        }
                                    },
                                    {
                                        "children", new List <object>
                                        {
                                            new Dictionary <string, object>
                                            {
                                                { "operatorType", "childChildOpType" },
                                                { "dbHits", 25L },
                                                { "rows", 30L },
                                                { "args", new Dictionary <string, object> {
                                                      { "c", 3L }
                                                  } },
                                                {
                                                    "identifiers", new List <object>
                                                    {
                                                        "f"
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };
            var collector = new ProfiledPlanCollector();

            collector.Collect(metadata);

            collector.Collected.Should().BeEquivalentTo(new ProfiledPlan("opType",
                                                                         new Dictionary <string, object> {
                { "a", 1L }
            },
                                                                         new List <string> {
                "a", "b", "c"
            },
                                                                         new List <IProfiledPlan>
            {
                new ProfiledPlan("childOpType", new Dictionary <string, object> {
                    { "b", 2L }
                },
                                 new List <string> {
                    "d", "e"
                },
                                 new List <IProfiledPlan>
                {
                    new ProfiledPlan("childChildOpType", new Dictionary <string, object> {
                        { "c", 3L }
                    },
                                     new List <string> {
                        "f"
                    },
                                     new List <IProfiledPlan>(), 25, 30)
                }, 15, 20)
            }, 5, 10));
        }