示例#1
0
        public async Task When_removing_a_condition_from_a_toggle()
        {
            _toggle.AddCondition(EditorID.Parse("me"), Condition("disabled"));
            await _fixture.SaveToggle(_toggle);

            await _fixture.Scenario(_ =>
            {
                _.Delete
                .Url($"/api/toggles/id/{_toggle.ID}/conditions/0");

                _.StatusCodeShouldBeOk();
                _.ContentShouldBe($"{{\"toggleID\":\"{_toggle.ID}\",\"conditions\":[]}}");
            });
        }
示例#2
0
 protected override void InitialiseToggle(Toggle toggle)
 {
     toggle.AddCondition(Editor, new Dictionary <string, object>
     {
         { ConditionBuilder.TypeKey, "enabled" }
     });
 }
示例#3
0
        public void When_adding_a_child_to_a_condition_which_doesnt_support_children()
        {
            CreateToggle(t => { t.AddCondition(Editor, ConditionProperties("enabled")); });

            Should.Throw <ConditionException>(
                () => Toggle.AddCondition(Editor, ConditionProperties("enabled"), parentConditionID: ConditionID.Parse(0))
                );
        }
示例#4
0
        public void When_the_parent_condition_doesnt_exist()
        {
            CreateToggle(t => { t.AddCondition(Editor, ConditionProperties("any")); });

            Should.Throw <ConditionNotFoundException>(
                () => Toggle.AddCondition(Editor, ConditionProperties("enabled"), parentConditionID: ConditionID.Parse(13))
                );
        }
示例#5
0
        public void Conditions_can_have_a_parent_specified()
        {
            CreateToggle(t => { t.AddCondition(Editor, ConditionProperties("any")); });

            var added = Toggle.AddCondition(Editor, ConditionProperties("enabled"), parentConditionID: ConditionID.Parse(0));

            SingleEvent <ConditionAdded>(e => e.ShouldSatisfyAllConditions(
                                             () => e.ConditionID.ShouldBe(added),
                                             () => e.Editor.ShouldBe(Editor),
                                             () => e.ParentConditionID.ShouldBe(ConditionID.Parse(0))
                                             ));
        }
示例#6
0
        public async Task InitializeAsync()
        {
            _toggle = Toggle.CreateNew(_fixture.Editor, _fixture.Generate("toggle-routes"));
            _toggle.AddTag(_fixture.Editor, "readonly");
            _toggle.AddTag(_fixture.Editor, "test");
            _toggle.AddCondition(_fixture.Editor, new Dictionary <string, object>
            {
                { ConditionBuilder.TypeKey, "enabled" }
            });

            await _fixture.SaveToggle(_toggle);
        }
示例#7
0
        public void Multiple_conditions_can_be_added()
        {
            var conditionOne = ConditionProperties("Enabled");
            var conditionTwo = ConditionProperties("Not");

            CreateToggle();
            Toggle.AddCondition(Editor, conditionOne);
            Toggle.AddCondition(Editor, conditionTwo);

            Events.Length.ShouldBe(2);
            Event <ConditionAdded>(0).Data.ConditionID.ShouldBe(ConditionID.Parse(0));
            Event <ConditionAdded>(1).Data.ConditionID.ShouldBe(ConditionID.Parse(1));
        }
示例#8
0
        public void Conditions_maintain_order()
        {
            var ids = Enumerable.Range(0, 15).Select(ConditionID.Parse).ToArray();

            CreateToggle();

            foreach (var id in ids)
            {
                Toggle.AddCondition(Editor, ConditionProperties("enabled"));
            }

            Toggle.Conditions.Select(c => c.ID).ShouldBe(ids);
        }
示例#9
0
        public void Conditions_can_be_added_to_conditions_supporting_children()
        {
            CreateToggle(t => { t.AddCondition(Editor, ConditionProperties("any")); });

            Toggle.AddCondition(Editor, ConditionProperties("enabled"), parentConditionID: ConditionID.Parse(0));

            var parent = Toggle
                         .Conditions
                         .ShouldHaveSingleItem()
                         .ShouldBeOfType <AnyCondition>();

            parent
            .Children
            .ShouldHaveSingleItem()
            .ShouldBeOfType <EnabledCondition>();
        }
示例#10
0
        public void Trying_to_remove_a_non_existing_condition_throws()
        {
            CreateToggle();

            var additions = 5;
            var toRemove  = additions + 3;

            for (int i = 0; i < additions; i++)
            {
                Toggle.AddCondition(Editor, ConditionProperties("enabled"));
            }

            Should
            .Throw <ConditionNotFoundException>(() => Toggle.RemoveCondition(Editor, ConditionID.Parse(toRemove)))
            .Message.ShouldContain(toRemove.ToString());
        }
示例#11
0
        public void Adding_a_condition_generates_a_well_formed_event()
        {
            var condition = new Dictionary <string, object>
            {
                { ConditionBuilder.TypeKey, "InGroup" },
                { "GroupName", "testGroup" },
                { "SearchKey", "searchValue" }
            };

            CreateToggle();
            Toggle.AddCondition(Editor, condition);

            SingleEvent <ConditionAdded>(e => e.ShouldSatisfyAllConditions(
                                             () => e.Properties.ShouldBe(condition),
                                             () => e.Editor.ShouldBe(Editor),
                                             () => e.ConditionID.ShouldBe(ConditionID.Parse(0)),
                                             () => e.ParentConditionID.ShouldBeNull()
                                             ));
        }
示例#12
0
        public void Next_condition_id_is_correct_when_adding_a_new_condition_after_load()
        {
            CreateToggle(
                new ConditionAdded(Editor, ConditionID.Parse(0), null, ConditionProperties("enabled")).AsAct(),
                new ConditionRemoved(Editor, ConditionID.Parse(0)).AsAct(),
                new ConditionAdded(Editor, ConditionID.Parse(1), null, ConditionProperties("enabled")).AsAct()
                );

            Toggle.AddCondition(Editor, ConditionProperties("disabled"));

            var expected = ConditionID.Parse(2);

            Toggle
            .Conditions
            .OfType <DisabledCondition>()
            .Last()
            .ID
            .ShouldBe(expected);
        }
示例#13
0
        public void Condition_ids_always_increment_when_removals_happen()
        {
            CreateToggle();

            var additions = 12;

            for (int i = 0; i < additions; i++)
            {
                Toggle.AddCondition(Editor, ConditionProperties("enabled"));
            }

            Toggle.RemoveCondition(Editor, ConditionID.Parse(5));
            Toggle.RemoveCondition(Editor, ConditionID.Parse(2));

            Toggle.AddCondition(Editor, ConditionProperties("enabled"));

            Events
            .OfType <Event <ConditionAdded> >()
            .Last()
            .Data
            .ConditionID.ShouldBe(ConditionID.Parse(additions));
        }