Example #1
0
        public void UsageRequestMatchesExample()
        {
            var example = @"{
  ""type"": ""Usage"",
  ""timeframe"": ""MonthToDate"",
  ""dataset"": {
    ""granularity"": ""Daily"",
    ""aggregation"": {},
    ""grouping"": [],
    ""filter"": {
      ""and"": [
        {
          ""or"": [
            {
              ""dimension"": {
                ""name"": ""ResourceLocation"",
                ""operator"": ""In"",
                ""values"": [
                  ""East US"",
                  ""West Europe""
                ]
              }
            },
            {
              ""tags"": {
                ""name"": ""Environment"",
                ""operator"": ""In"",
                ""values"": [
                  ""UAT"",
                  ""Prod""
                ]
              }
            }
          ]
        },
        {
          ""dimension"": {
            ""name"": ""ResourceGroup"",
            ""operator"": ""In"",
            ""values"": [
              ""API""
            ]
          }
        }
      ]
    }
  }
}";

            var request =
                new UsageRequest(
                    Timeframe.MonthToDate,
                    new Dataset(
                        Granularity.Daily,
                        new Dictionary <string, Aggregation>(),
                        new List <Grouping>(),
                        FilterExpression.And(
                            FilterExpression.Or(
                                FilterExpression.Dimension(
                                    "ResourceLocation",
                                    Operator.In,
                                    new[] { "East US", "West Europe" }),
                                FilterExpression.Tag(
                                    "Environment",
                                    Operator.In,
                                    new[] { "UAT", "Prod" })),
                            FilterExpression.Dimension(
                                "ResourceGroup",
                                Operator.In,
                                new[] { "API" }))));

            Assert.Equal(example, Serialize(request));
        }