Example #1
0
        public async Task AddPropOverwriteString()
        {
            /*
             * ADDPROP ( d s1 s2 i -- )
             *
             * Sets property associated with s1 in object d. Note that if s2 is null "", then i will be used.
             * Otherwise, s2 is always used. All four parameters must be on the stack; none may be omitted.
             * If the effective user of the program does not control the object in question and the property begins with an underscore `_',
             * the property cannot be changed. The same goes for properties beginning with a dot `.' which cannot be read without permission.
             */

            var testObj = ThingRepository.Instance.Make <Thing>();

            {
                var stack = new Stack <ForthDatum>(new[] {
                    new ForthDatum(testObj.id),
                    new ForthDatum("propName"),
                    new ForthDatum("propValue1"),
                    new ForthDatum(123)
                });
                var parameters = new ForthPrimativeParameters(null, stack.ClonePreservingOrder(), null, Dbref.NOT_FOUND, Dbref.NOT_FOUND, Dbref.NOT_FOUND, null, null, null, null, default);
                var result1    = await AddProp.ExecuteAsync(parameters);

                Assert.NotNull(result1);
                Assert.IsTrue(result1.IsSuccessful);

                Assert.NotNull(testObj.properties);
                Assert.AreEqual(1, testObj.properties.Count);
                Assert.IsTrue(testObj.properties.ContainsKey("propName"));
                var prop = testObj.properties["propName"];
                Assert.NotNull(prop);
                Assert.AreEqual("propName", prop.Name);
                Assert.AreEqual(PropertyType.String, prop.Type);
                Assert.AreEqual("propValue1", prop.Value);
            }

            {
                var stack = new Stack <ForthDatum>(new[] {
                    new ForthDatum(testObj.id),
                    new ForthDatum("propName"),
                    new ForthDatum("propValue2"),
                    new ForthDatum(123)
                });
                var parameters = new ForthPrimativeParameters(null, stack.ClonePreservingOrder(), null, Dbref.NOT_FOUND, Dbref.NOT_FOUND, Dbref.NOT_FOUND, null, null, null, null, default);
                var result2    = await AddProp.ExecuteAsync(parameters);

                Assert.NotNull(result2);
                Assert.IsTrue(result2.IsSuccessful);

                Assert.NotNull(testObj.properties);
                Assert.AreEqual(1, testObj.properties.Count);
                Assert.IsTrue(testObj.properties.ContainsKey("propName"));
                var prop = testObj.properties["propName"];
                Assert.NotNull(prop);
                Assert.AreEqual("propName", prop.Name);
                Assert.AreEqual(PropertyType.String, prop.Type);
                Assert.AreEqual("propValue2", prop.Value);
            }
        }
Example #2
0
        public async Task GetProp_String()
        {
            /*
             * GETPROP (d s -- ?)
             *
             * Gets the value of a given property, and puts it on the stack.
             * This can return a lock, a string, a dbref, or an integer, depending on the type of the property.
             * Permissions are the same as those for GETPROPSTR. This primitive returns 0 if no such property exists,
             * of if it is a valueless propdir.
             */

            var testObj = ThingRepository.Instance.Make <Thing>();

            // Set the property up
            {
                var stack = new Stack <ForthDatum>(new[] {
                    new ForthDatum(testObj.id),
                    new ForthDatum("propName"),
                    new ForthDatum("propValue1"),
                    new ForthDatum(123)
                });
                var parameters = new ForthPrimativeParameters(null, stack.ClonePreservingOrder(), null, Dbref.NOT_FOUND, Dbref.NOT_FOUND, Dbref.NOT_FOUND, null, null, null, null, default);
                var result1    = await AddProp.ExecuteAsync(parameters);

                Assert.NotNull(result1);
                Assert.IsTrue(result1.IsSuccessful);

                Assert.NotNull(testObj.properties);
                Assert.AreEqual(1, testObj.properties.Count);
                Assert.IsTrue(testObj.properties.ContainsKey("propName"));
                var prop = testObj.properties["propName"];
                Assert.NotNull(prop);
                Assert.AreEqual("propName", prop.Name);
                Assert.AreEqual(PropertyType.String, prop.Type);
                Assert.AreEqual("propValue1", prop.Value);
            }

            // Now get
            {
                var stack = new Stack <ForthDatum>(new[] {
                    new ForthDatum(testObj.id),
                    new ForthDatum("propName")
                });

                var local      = stack.ClonePreservingOrder();
                var parameters = new ForthPrimativeParameters(null, local, null, Dbref.NOT_FOUND, Dbref.NOT_FOUND, Dbref.NOT_FOUND, null, null, null, null, default);
                var result     = await GetProp.ExecuteAsync(parameters);

                Assert.NotNull(result);
                Assert.IsTrue(result.IsSuccessful, result.Reason);

                Assert.AreEqual(1, local.Count);
                var pop = local.Pop();
                Assert.AreEqual(DatumType.String, pop.Type);
                Assert.AreEqual("propValue1", pop.Value);
            }
        }
Example #3
0
        public async Task GetPropStr_String()
        {
            /*
             * GETPROPSTR ( d s -- s )
             *
             * s must be a string. Retrieves string associated with property s in object d.
             * If the property is cleared, "" (null string) is returned.
             */

            var testObj = ThingRepository.Instance.Make <Thing>();

            // Set the property up
            {
                var stack = new Stack <ForthDatum>(new[] {
                    new ForthDatum(testObj.id),
                    new ForthDatum("propName"),
                    new ForthDatum("propValue1"),
                    new ForthDatum(123)
                });
                var parameters = new ForthPrimativeParameters(null, stack.ClonePreservingOrder(), null, Dbref.NOT_FOUND, Dbref.NOT_FOUND, Dbref.NOT_FOUND, null, null, null, null, default);
                var result1    = await AddProp.ExecuteAsync(parameters);

                Assert.NotNull(result1);
                Assert.IsTrue(result1.IsSuccessful);

                Assert.NotNull(testObj.properties);
                Assert.AreEqual(1, testObj.properties.Count);
                Assert.IsTrue(testObj.properties.ContainsKey("propName"));
                var prop = testObj.properties["propName"];
                Assert.NotNull(prop);
                Assert.AreEqual("propName", prop.Name);
                Assert.AreEqual(PropertyType.String, prop.Type);
                Assert.AreEqual("propValue1", prop.Value);
            }

            // Now get
            {
                var stack = new Stack <ForthDatum>(new[] {
                    new ForthDatum(testObj.id),
                    new ForthDatum("propName")
                });

                var local      = stack.ClonePreservingOrder();
                var parameters = new ForthPrimativeParameters(null, local, null, Dbref.NOT_FOUND, Dbref.NOT_FOUND, Dbref.NOT_FOUND, null, null, null, null, default);
                var result     = await GetPropStr.ExecuteAsync(parameters);

                Assert.NotNull(result);
                Assert.IsTrue(result.IsSuccessful, result.Reason);

                Assert.AreEqual(1, local.Count);
                var pop = local.Pop();
                Assert.AreEqual(DatumType.String, pop.Type);
                Assert.AreEqual("propValue1", pop.Value);
            }
        }