public void CanSetupTreeStructureWithUpdates()
        {
            string document = ComplexObject
                              .Create()
                              .WithId(SetTo.Value("ID123"))
                              .WithItems(
                item => item
                .WithId(SetTo.Value("ARandomGuid"))
                .WithTags(
                    tag1 => tag1
                    .WithKey(SetTo.Value("Importance"))
                    .WithValue(SetTo.Value("High")),
                    tag2 => tag2
                    .WithKey(SetTo.Value("Level"))
                    .WithValue(SetTo.Null),
                    tag3 => tag3
                    .WithKey(SetTo.Value("Games"))
                    .WithValue(SetTo.Null)))
                              .WithName(SetTo.Value("Test"))
                              .UpdateExistingTagAtIndex(0,
                                                        item => item
                                                        .UpdateExistingTagAtIndex(1, tag => tag.WithValue(SetTo.Value("Medium")))
                                                        .WithTags(Updated.ByRemovingAtIndex(0)));

            Assert.Equal(
                @"{""id"":""ID123"",""items"":[{""id"":""ARandomGuid"",""tags"":[{""key"":""Level"",""value"":""Medium""},{""key"":""Games"",""value"":null}]}],""name"":""Test""}",
                document);
        }
        public void SetToNull_JsonContainsNullProperty()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("property", SetTo.Null());

            Assert.Equal(@"{""property"":null}", document);
        }
        public void SettingEmptyStringProperty_JsonContainsEmptyPropertyName()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("", SetTo.Value(""));

            Assert.Equal(@"{"""":""""}", document);
        }
示例#4
0
        public void SetToEmptyArrayFunc_ExpectedJsonPatternReturned()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("first", SetTo.AnEmptyArray)
                              .And("second", SetTo.Value("test2"));

            Assert.Equal($@"{{""first"":[],""second"":""test2""}}", document);
        }
示例#5
0
        public void WithoutThenWith_PropertyAppearsInJson()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .Without("first")
                              .With("first", SetTo.Value("There"));

            Assert.Equal(@"{""first"":""There""}", document);
        }
示例#6
0
        public void AddingPropertiesUsingSetToFalse_ExpectedJsonPatternReturned()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("first", SetTo.False())
                              .And("second", SetTo.Value("test2"));

            Assert.Equal($@"{{""first"":false,""second"":""test2""}}", document);
        }
示例#7
0
        public void SetToCollectionWithOneEmptyObject_ExpectedJsonPatternReturned()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("first", SetTo.AnArrayContaining(item => { }))
                              .And("second", SetTo.Value("test2"));

            Assert.Equal($@"{{""first"":[{{}}],""second"":""test2""}}", document);
        }
        public void AddingPropertiesWithValues_PropertiesAppearInJson()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("first", SetTo.Value("test1"))
                              .And("second", SetTo.Value("test2"))
                              .With("third", SetTo.Value(true));

            Assert.Equal(@"{""first"":""test1"",""second"":""test2"",""third"":true}", document);
        }
示例#9
0
        public void UpdateAllowsToModifyExistingSetValue()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("first", SetTo.Value("test1"))
                              .With("first", Updated.By(v => v + " and test2"))
                              .And("second", SetTo.Value(true));

            Assert.Equal(@"{""first"":""test1 and test2"",""second"":true}", document);
        }
示例#10
0
        public void UpdateAllowsToModifyExistingSetValueUsingStrongTyping()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("first", SetTo.Value("test1"))
                              .And("second", SetTo.Value(true))
                              .And("second", Updated.By <bool>(v => !v));

            Assert.Equal(@"{""first"":""test1"",""second"":false}", document);
        }
        public void AddingPropertiesUsingSetToRandomGuid_ExpectedJsonPatternReturned()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("first", SetTo.RandomGuid())
                              .And("second", SetTo.Value("test2"));

            var guidRegex = @"[0-9A-F]{8}-([0-9A-F]{4}-){3}[0-9A-F]{12}";

            Assert.True(Regex.IsMatch(document, $@"{{""first"":""{guidRegex}"",""second"":""test2""}}"));
        }
示例#12
0
        public void SetToCollectionWithTwoComplexObjects_ExpectedJsonPatternReturned()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("first", SetTo.AnArrayContaining(
                                        item => { item.With("first", SetTo.Value("hasValue")); },
                                        item => { item.With("second", SetTo.Value("alsoHasAValue")); }))
                              .And("second", SetTo.Value("test2"));

            Assert.Equal(
                $@"{{""first"":[{{""first"":""hasValue""}},{{""second"":""alsoHasAValue""}}],""second"":""test2""}}",
                document);
        }
示例#13
0
        public void SetToCollectionThenUpdatedByRemoving_ExpectedJsonPatternReturned()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("first", SetTo.AnArrayContaining(
                                        item => item.With("aProperty", SetTo.Value("AValue")),
                                        item => { }))
                              .And("second", SetTo.Value("test2"))
                              .With("first", Updated.ByRemovingAtIndex(0))
                              .With("first", Updated.AtIndex(0,
                                                             item => item.With("second", SetTo.Value("NewValue"))));

            Assert.Equal($@"{{""first"":[{{""second"":""NewValue""}}],""second"":""test2""}}", document);
        }
示例#14
0
        public void CanSetCustomPropertiesAndGenericProperties()
        {
            string document = CustomObject
                              .Create()
                              .WithId(SetTo.Value("ID123"))
                              .With("description", SetTo.Value("This is a description"))
                              .WithName(SetTo.Value("Test"))
                              .With("Age", SetTo.Value(42))
                              .WithCat(SetTo.Null);

            Assert.Equal(
                @"{""id"":""ID123"",""description"":""This is a description"",""name"":""Test"",""Age"":42,""cat"":null}",
                document);
        }
示例#15
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="script">Script handle</param>
        /// <param name="dungeon">Dungeon handle</param>
        public SetToControl(SetTo script, Dungeon dungeon)
        {
            if (dungeon == null || script == null)
            {
                MessageBox.Show("Dungeon == NULL or script == NULL !", "SetToControl", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            InitializeComponent();

            Action  = script;
            Dungeon = dungeon;
            SquareControl.SetSquare(script.Square);
            TargetBox.SetTarget(Dungeon, Action.Target);
        }
示例#16
0
        public void SetToCollectionThenInsertAtIndex0_ExpectedJsonPatternReturned()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("first", SetTo.AnArrayContaining(
                                        item => item.With("number", SetTo.Value("one")),
                                        item => { }))
                              .And("second", SetTo.Value("test2"))
                              .With("first", Updated.WithArrayItemsInsertedAtIndex(0,
                                                                                   item => item.With("number", SetTo.Value("zero"))))
                              .With("first", Updated.AtIndex(2,
                                                             item => item.With("aNother", SetTo.Value("NewValue"))));

            Assert.Equal($@"{{""first"":[{{""number"":""zero""}},{{""number"":""one""}},{{""aNother"":""NewValue""}}],""second"":""test2""}}", document);
        }
示例#17
0
        public void AddingPropertiesUsingWithAndAnd_PropertiesAppearInJson()
        {
            string document = JsonBuilder
                              .CreateObject()
                              .With("first", SetTo.Value("test1"))
                              .And("second", SetTo.Value("test2"))
                              .With("third", SetTo.Null)
                              .And("fourth", SetTo.Null)
                              .With("fifth", SetTo.Null())
                              .And("sixth", SetTo.Null())
                              .With("seventh")
                              .And("eighth");

            Assert.Equal(
                @"{""first"":""test1"",""second"":""test2"",""third"":null,""fourth"":null,""fifth"":null,""sixth"":null,""seventh"":null,""eighth"":null}",
                document);
        }
示例#18
0
        /// <summary>
        /// Loads a party
        /// </summary>
        /// <param name="filename">Xml data</param>
        /// <returns>True if team successfuly loaded, otherwise false</returns>
        public virtual bool Load(XmlNode xml)
        {
            if (xml == null)
            {
                return(false);
            }


            Action = null;

            switch (xml.Name)
            {
            case SpawnMonster.Tag:
            {
                Action = new SpawnMonster();
            }
            break;

            case EnableTarget.Tag:
            {
                Action = new EnableTarget();
            }
            break;

            case DisableTarget.Tag:
            {
                Action = new DisableTarget();
            }
            break;

            case ActivateTarget.Tag:
            {
                Action = new ActivateTarget();
            }
            break;

            case DeactivateTarget.Tag:
            {
                Action = new DeactivateTarget();
            }
            break;

            case ChangePicture.Tag:
            {
                Action = new ChangePicture();
            }
            break;

            case ChangeText.Tag:
            {
                Action = new ChangeText();
            }
            break;

            case DisableChoice.Tag:
            {
                Action = new DisableChoice();
            }
            break;

            case EnableChoice.Tag:
            {
                Action = new EnableChoice();
            }
            break;

            case EndChoice.Tag:
            {
                Action = new EndChoice();
            }
            break;

            case EndDialog.Tag:
            {
                Action = new EndDialog();
            }
            break;

            case GiveExperience.Tag:
            {
                Action = new GiveExperience();
            }
            break;

            case GiveItem.Tag:
            {
                Action = new GiveItem();
            }
            break;

            case Healing.Tag:
            {
                Action = new Healing();
            }
            break;

            case JoinCharacter.Tag:
            {
                Action = new JoinCharacter();
            }
            break;

            case PlaySound.Tag:
            {
                Action = new PlaySound();
            }
            break;

            case SetTo.Tag:
            {
                Action = new SetTo();
            }
            break;

            case Teleport.Tag:
            {
                Action = new Teleport();
            }
            break;

            case ToggleTarget.Tag:
            {
                Action = new ToggleTarget();
            }
            break;

            case DisplayMessage.Tag:
            {
                Action = new DisplayMessage();
            }
            break;

            default:
            {
                Trace.WriteLine("[ScriptBase] Load() : Unknown node \"" + xml.Name + "\" found.");
                return(false);
            }
            }

            if (Action == null)
            {
                return(false);
            }


            Action.Load(xml);

            return(true);
        }
 internal ComplexObject WithItems(params Action <ItemObject>[] initialisers)
 {
     return(With("items", SetTo.AnArrayContaining(initialisers)));
 }
 internal ItemObject WithTags(params Action <TagObject>[] initialisers)
 {
     return(With("tags", SetTo.AnArrayContaining(initialisers)));
 }
示例#21
0
    public static void SetTo <V, K>(this ISourceCache <V, K> cache, Func <V, K> keySelector, IEnumerable <V> items, SetTo setTo = Noggog.SetTo.Whitewash)
        where K : notnull
    {
        if (setTo == Noggog.SetTo.Whitewash)
        {
            SetTo(cache, items);
            return;
        }
        var toRemove = new HashSet <K>(cache.Keys);
        var keyPairs = items.Select(i => new KeyValuePair <K, V>(keySelector(i), i)).ToArray();

        toRemove.Remove(keyPairs.Select(kv => kv.Key));
        cache.Remove(toRemove);
        switch (setTo)
        {
        case Noggog.SetTo.SkipExisting:
            foreach (var item in keyPairs)
            {
                if (!cache.Lookup(item.Key).HasValue)
                {
                    cache.AddOrUpdate(item.Value);
                }
            }
            break;

        case Noggog.SetTo.SetExisting:
            cache.AddOrUpdate(items);
            break;

        default:
            throw new NotImplementedException();
        }
    }