public void ProcessParents_Reparent_Applied()
        {
            var tariff     = GetJsonFromFile("simple_reparent_tariff.json");
            var option     = GetJsonFromFile("simple_reparent_option.json");
            var calculator = new TariffOptionCalculator();

            calculator.Calculate(tariff, option);
            calculator.Reorder(tariff, null);

            var root       = tariff.SelectToken("Parameters");
            var direction  = new TariffDirection("OutgoingCalls", null, null, null);
            var result     = calculator.FindByKey(root, direction.GetKey(), true).ToArray();
            var direction2 = new TariffDirection("ParameterGroup", null, null, new[] { "First" });
            var result2    = calculator.FindByKey(root, direction2.GetKey()).ToArray();
            var direction3 = new TariffDirection("ParameterGroup", null, null, new[] { "Second" });
            var result3    = calculator.FindByKey(root, direction3.GetKey()).ToArray();
            var direction4 = new TariffDirection("IncomingCalls", null, null, null);
            var result4    = calculator.FindByKey(root, direction4.GetKey()).ToArray();
            var direction5 = new TariffDirection("MinutesPackage", null, null, null);
            var result5    = calculator.FindByKey(root, direction5.GetKey()).ToArray();


            result4.Length.Should().Be(1);
            result5.Length.Should().Be(1);

            ((int)result[0]["Parent"]["Id"]).Should().Be((int)result3[0]["Id"]);
            ((string)result2[0]["Title"]).Should().Be("Подгруппа 1");
            ((string)result3[0]["Title"]).Should().Be("Подгруппа 2 (новая)");
            ((int)result4[0]["Parent"]["Id"]).Should().Be((int)result2[0]["Id"]);
            ((int)result5[0]["Parent"]["Id"]).Should().Be((int)result2[0]["Id"]);
        }
        public void ProcessAppend_HasAppendModifier_Appended()
        {
            var tariff     = GetJsonFromFile("simple1_tariff.json");
            var option     = GetJsonFromFile("simple1_option.json");
            var calculator = new TariffOptionCalculator();
            var direction  = new TariffDirection("OutgoingCalls", null, "Russia", null);
            var optionRoot = option.SelectToken("Parameters");
            var obj        = new JObject
            {
                ["Id"]    = 1000,
                ["Alias"] = "Append",
                ["Title"] = "Добавить"
            };

            ((JArray)calculator.FindByKey(optionRoot, direction.GetKey()).First().SelectToken("Modifiers")).Add(obj);
            var cntBefore = tariff.SelectTokens("Parameters.[?(@.Id)]").Count();

            calculator.Calculate(tariff, option);
            calculator.Reorder(tariff, null);

            var cntAfter = tariff.SelectTokens("Parameters.[?(@.Id)]").Count();
            var root     = tariff.SelectToken("Parameters");
            var result   = calculator.FindByKey(root, direction.GetKey()).ToArray();

            result.Length.Should().Be(1);
            ((decimal)result[0]["NumValue"]).Should().Be(85);
            result[0].Previous["Changed"].Should().NotBeNull();

            cntAfter.Should().Be(cntBefore + 1);
        }
        public void ProcessPackages_HasGroupPackage_Applied()
        {
            var tariff     = GetJsonFromFile("package_group_tariff.json");
            var option     = GetJsonFromFile("package_group_option.json");
            var calculator = new TariffOptionCalculator();

            calculator.Calculate(tariff, option);
            calculator.Reorder(tariff, null);

            var root       = tariff.SelectToken("Parameters");
            var direction  = new TariffDirection("OutgoingCalls", null, "Russia", null);
            var result     = calculator.FindByKey(root, direction.GetKey(), true).ToArray();
            var direction2 = new TariffDirection("ParameterGroup", null, null, new [] { "WithinPackage" });
            var result2    = calculator.FindByKey(root, direction2.GetKey()).ToArray();
            var direction3 = new TariffDirection("ParameterGroup", null, null, new[] { "OverPackage" });
            var result3    = calculator.FindByKey(root, direction3.GetKey()).ToArray();


            result.Length.Should().Be(2);
            result2.Length.Should().Be(1);
            result3.Length.Should().Be(1);



            ((decimal)result[0]["NumValue"]).Should().Be(0);
            ((decimal)result[1]["NumValue"]).Should().Be(85);
            ((string)result[0]["Title"]).Should().Be("Новый заголовок (в пределах пакета)");
            ((string)result[1]["Title"]).Should().Be("Новый заголовок (сверх пакета)");
            ((bool)result[0]["Changed"]).Should().BeTrue();
            ((bool)result[1]["Changed"]).Should().BeTrue();

            result[0].Previous.Should().BeEquivalentTo(result2[0]);
            result[1].Previous.Should().BeEquivalentTo(result3[0]);

            ((string)result2[0]["Title"]).Should().Be("В пределах пакета 500 минут");
            ((int)result2[0]["Id"]).Should().Be(5000);
            result2[0].Previous.Should().NotBeNull();

            ((string)result3[0]["Title"]).Should().Be("Сверх пакета 500 минут");
            ((int)result3[0]["Id"]).Should().Be(6000);
            result3[0].Previous.Should().NotBeNull();

            tariff.SelectTokens("Parameters.[?(@.Changed)]").Count().Should().Be(6);
        }