Ejemplo n.º 1
0
        public void PropertiesCanBeAssignedAndRetrieved()
        {
            dynamic shape = new Clay(Cat(new PropBehavior()));

            shape.Foo = "textbox";
            Assert.That((object)shape.Foo, Is.EqualTo("textbox"));
        }
Ejemplo n.º 2
0
        public void UsingArrayWithVarietyOfCollectionInterfaces()
        {
            dynamic array = new Clay(new InterfaceProxyBehavior(), new ArrayBehavior());

            array.Add("a", "b", "c", "d");

            ICollection <string> collectionString = array;

            Assert.That(collectionString.Contains("e"), Is.False);
            collectionString.Add("e");
            Assert.That(collectionString.Contains("e"), Is.True);
            Assert.That(collectionString.Count, Is.EqualTo(5));

            Assert.That(collectionString.Count(), Is.EqualTo(5));


            IList <string> listString = array;

            Assert.That(listString.IndexOf("b++"), Is.EqualTo(-1));
            Assert.That(listString.IndexOf("c"), Is.EqualTo(2));
            listString.Insert(2, "b++");
            Assert.That(listString.IndexOf("b++"), Is.EqualTo(2));
            Assert.That(listString.IndexOf("c"), Is.EqualTo(3));
            listString.RemoveAt(2);
            Assert.That(listString.IndexOf("b++"), Is.EqualTo(-1));
            Assert.That(listString.IndexOf("c"), Is.EqualTo(2));

            Assert.That(listString[1], Is.EqualTo("b"));
            Assert.That(listString[2], Is.EqualTo("c"));
        }
Ejemplo n.º 3
0
        public dynamic New(string shapeName, Action <dynamic> initialize)
        {
            var item = new Clay(new PropBehavior());

            initialize(item);
            return(item);
        }
Ejemplo n.º 4
0
        public int Solve2(string input)
        {
            var clay = new Clay(GetClayCoordinates(input));

            var(reservoir, waterfall) = SolveInternal(clay);
            // OutputGrid(clay, reservoir, waterfall);
            return(reservoir.Count(p => p.Y <= clay.MaxY && p.Y >= clay.MinY));
        }
Ejemplo n.º 5
0
Archivo: Fire.cs Proyecto: atil/ld36
    public void TakeClay(Clay clay)
    {
        clay.transform.SetParent(transform, false);
        Destroy(clay.gameObject);
        _hasClay = true;

        StartCoroutine(TransformClayToBrick());
    }
Ejemplo n.º 6
0
        public void InvokeMemberContainsNameWithImpromptuInterface()
        {
            var clay = new Clay(new TestBehavior()).ActLike<ISimpeleClassMeth>();
            var result = clay.Action3();
            Assert.IsTrue(result.Contains("[name:Action3]"), "Does Not Match Argument Name");
            Assert.IsTrue(result.Contains("[count:0]"), "Does Not Match Argument Count");

        }
Ejemplo n.º 7
0
 public override string ToString()
 {
     if (Set)
     {
         return(string.Format("W{0}, C{1}, I{2}", Wood.ToString("#,0"), Clay.ToString("#,0"), Iron.ToString("#,0")));
     }
     return("Nothing");
 }
Ejemplo n.º 8
0
        public void InvokeMemberContainsName()
        {
            dynamic clay   = new Clay(new TestBehavior());
            var     result = clay.Hello();

            Assert.That(result, Does.Contain("[name:Hello]"));
            Assert.That(result, Does.Contain("[count:0]"));
        }
Ejemplo n.º 9
0
        public void InvokeMemberContainsNameWithImpromptuInvoke()
        {
            var clay = new Clay(new TestBehavior());
            var result = Impromptu.InvokeMember(clay, "Help", "Test");
            Assert.IsTrue(result.Contains("[name:Help]"), "Does Not Match Argument Name");
            Assert.IsTrue(result.Contains("[count:1]"), "Does Not Match Argument Count");

        }
Ejemplo n.º 10
0
        public void InvokeBinder()
        {
            dynamic clay   = new Clay(new TestBehavior());
            var     result = clay();

            Assert.That(result, Does.Contain("[name:<null>]"));
            Assert.That(result, Does.Contain("[count:0]"));
        }
Ejemplo n.º 11
0
        public void InvokeMemberContainsNameWithImpromptuInterface()
        {
            var clay   = new Clay(new TestBehavior()).ActLike <ISimpeleClassMeth>();
            var result = clay.Action3();

            Assert.IsTrue(result.Contains("[name:Action3]"), "Does Not Match Argument Name");
            Assert.IsTrue(result.Contains("[count:0]"), "Does Not Match Argument Count");
        }
Ejemplo n.º 12
0
        public void InvokeMemberContainsNameWithImpromptuInvoke()
        {
            var clay   = new Clay(new TestBehavior());
            var result = Impromptu.InvokeMember(clay, "Help", "Test");

            Assert.IsTrue(result.Contains("[name:Help]"), "Does Not Match Argument Name");
            Assert.IsTrue(result.Contains("[count:1]"), "Does Not Match Argument Count");
        }
Ejemplo n.º 13
0
        public void FactoryMethodCopiesPropertiesOfOptionalArgument()
        {
            dynamic factory = new Clay(new ClayFactoryBehavior());
            var     alpha   = factory.Alpha(new { One = 1, Two = "dos" });

            Assert.That(alpha.One, Is.EqualTo(1));
            Assert.That(alpha.Two, Is.EqualTo("dos"));
        }
Ejemplo n.º 14
0
        public void DifferentInstanceCreatedEachCall()
        {
            dynamic factory = new Clay(new ClayFactoryBehavior());
            object  alpha1  = factory.Alpha();
            object  alpha2  = factory.Alpha();

            Assert.That(alpha1, Is.Not.SameAs(alpha2));
        }
Ejemplo n.º 15
0
        public void AddCallsCanBeChained()
        {
            dynamic array = new Clay(new ArrayBehavior());

            array.Add("Alpha").Add("Beta");

            Assert.That(array[0], Is.EqualTo("Alpha"));
            Assert.That(array[1], Is.EqualTo("Beta"));
        }
Ejemplo n.º 16
0
        public void InvokingMethodsCreateDynamicObjectWithBehaviors()
        {
            dynamic factory = new Clay(new ClayFactoryBehavior());
            object  alpha   = factory.Alpha();

            Assert.That(alpha, Is.Not.Null);
            Assert.That(alpha, Is.AssignableTo <IDynamicMetaObjectProvider>());
            Assert.That(alpha, Is.AssignableTo <IClayBehaviorProvider>());
        }
Ejemplo n.º 17
0
        public void UsingViaSystemInterfacesWithLinqExtensionMethods()
        {
            dynamic array = new Clay(new InterfaceProxyBehavior(), new ArrayBehavior());

            array.Add("a", "b", "c", "d", "e");

            IEnumerable enumerableBase = array;
            ICollection collectionBase = array;
            IList       listBase       = array;

            IEnumerable <object> enumerableObject = array;
            ICollection <object> collectionObject = array;
            IList <object>       listObject       = array;

            IEnumerable <string> enumerableString = array;
            ICollection <string> collectionString = array;
            IList <string>       listString       = array;

            Assert.That(enumerableBase.Cast <object>().Reverse().Skip(1).Take(3).Last(), Is.EqualTo("b"));
            Assert.That(collectionBase.Cast <object>().Reverse().Skip(1).Take(3).Last(), Is.EqualTo("b"));
            Assert.That(listBase.Cast <object>().Reverse().Skip(1).Take(3).Last(), Is.EqualTo("b"));

            Assert.That(enumerableBase.OfType <object>().Reverse().Skip(1).Take(3).Last(), Is.EqualTo("b"));
            Assert.That(collectionBase.OfType <object>().Reverse().Skip(1).Take(3).Last(), Is.EqualTo("b"));
            Assert.That(listBase.OfType <object>().Reverse().Skip(1).Take(3).Last(), Is.EqualTo("b"));

            Assert.That(enumerableBase.Cast <string>().Reverse().Skip(1).Take(3).Last(), Is.EqualTo("b"));
            Assert.That(collectionBase.Cast <string>().Reverse().Skip(1).Take(3).Last(), Is.EqualTo("b"));
            Assert.That(listBase.Cast <string>().Reverse().Skip(1).Take(3).Last(), Is.EqualTo("b"));

            Assert.That(enumerableBase.OfType <string>().Reverse().Skip(1).Take(3).Last(), Is.EqualTo("b"));
            Assert.That(collectionBase.OfType <string>().Reverse().Skip(1).Take(3).Last(), Is.EqualTo("b"));
            Assert.That(listBase.OfType <string>().Reverse().Skip(1).Take(3).Last(), Is.EqualTo("b"));

            Assert.That(enumerableObject.Reverse().Skip(1).Take(3).Last(), Is.EqualTo("b"));
            Assert.That(collectionObject.Reverse().Skip(1).Take(3).Last(), Is.EqualTo("b"));
            Assert.That(listObject.Reverse().Skip(1).Take(3).Last(), Is.EqualTo("b"));

            Assert.That(enumerableString.Reverse().Skip(1).Take(3).Last(), Is.EqualTo("b"));
            Assert.That(collectionString.Reverse().Skip(1).Take(3).Last(), Is.EqualTo("b"));
            Assert.That(listString.Reverse().Skip(1).Take(3).Last(), Is.EqualTo("b"));

            var enumerator = enumerableString.GetEnumerator();

            Assert.That(enumerator.MoveNext(), Is.True);
            Assert.That(enumerator.Current, Is.EqualTo("a"));


            enumerator = collectionString.GetEnumerator();
            Assert.That(enumerator.MoveNext(), Is.True);
            Assert.That(enumerator.Current, Is.EqualTo("a"));

            enumerator = listString.GetEnumerator();
            Assert.That(enumerator.MoveNext(), Is.True);
            Assert.That(enumerator.Current, Is.EqualTo("a"));
        }
Ejemplo n.º 18
0
 public static bool wantsToCraftOnObject(Player p, int item, int craftObject)
 {
     if (craftObject == CLAY_TABLE)
     {
         if (item == CLAY)
         {
             resetCrafting(p);
             Clay.displayClayOptions(p, 1);
             p.setTemporaryAttribute("craftType", 1);
             return(true);
         }
         else
         {
             for (int j = 0; j < CLAY_ITEMS.Length; j++)
             {
                 if (item == (int)CLAY_ITEMS[j][0])
                 {
                     p.getPackets().sendMessage("This item must now be baked in a clay oven.");
                     return(true);
                 }
             }
         }
     }
     else if (craftObject == CLAY_OVEN)
     {
         if (craftObject == CLAY)
         {
             p.getPackets().sendMessage("This clay must be moulded into an item first.");
             return(true);
         }
         for (int j = 0; j < CLAY_ITEMS.Length; j++)
         {
             if (item == (int)CLAY_ITEMS[j][0])
             {
                 resetCrafting(p);
                 Clay.displayClayOptions(p, 2);
                 p.setTemporaryAttribute("craftType", 2);
                 return(true);
             }
         }
     }
     else if (craftObject == 11666)
     { // Furnace
         if (item == GOLD_BAR)
         {
             Jewellery.displayJewelleryInterface(p);
             return(true);
         }
         else if (item == SILVER_BAR)
         {
             Silver.displaySilverOptions(p);
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 19
0
        public void AddGrowsArray()
        {
            dynamic array = new Clay(new ArrayBehavior());

            array.Add("Alpha");
            array.Add("Beta");

            Assert.That(array[0], Is.EqualTo("Alpha"));
            Assert.That(array[1], Is.EqualTo("Beta"));
        }
Ejemplo n.º 20
0
        public void FactoryMethodUsesNamedParameters()
        {
            dynamic factory = new Clay(new ClayFactoryBehavior());

            var alpha = factory.Alpha(new { Red = "#f00" }, One: 1, Two: "dos");

            Assert.That(alpha.One, Is.EqualTo(1));
            Assert.That(alpha.Two, Is.EqualTo("dos"));
            Assert.That(alpha.Red, Is.EqualTo("#f00"));
        }
Ejemplo n.º 21
0
 public void WriteXml(System.Xml.XmlWriter w, DateTime?Date)
 {
     w.WriteStartElement("Resources");
     if (Date.HasValue)
     {
         w.WriteAttributeString("Date", Date.Value.ToString(System.Globalization.CultureInfo.InvariantCulture));
     }
     w.WriteElementString("Wood", Wood.ToString());
     w.WriteElementString("Clay", Clay.ToString());
     w.WriteElementString("Iron", Iron.ToString());
     w.WriteEndElement();
 }
Ejemplo n.º 22
0
        public void InsertAndRemoveAtIndexes()
        {
            dynamic array = new Clay(new ArrayBehavior());

            array.Add("a", "b", "c", "d").Insert(2, "b++").RemoveAt(3);

            Assert.That(array.Count, Is.EqualTo(4));
            Assert.That(array[0], Is.EqualTo("a"));
            Assert.That(array[1], Is.EqualTo("b"));
            Assert.That(array[2], Is.EqualTo("b++"));
            Assert.That(array[3], Is.EqualTo("d"));
        }
Ejemplo n.º 23
0
        public void AddTakesZeroOrMoreArguments()
        {
            dynamic array = new Clay(new ArrayBehavior());

            array.Add().Add("Alpha").Add(null).Add("Beta", "Gamma", "Delta");

            Assert.That(array[0], Is.EqualTo("Alpha"));
            Assert.That((object)array[1], Is.Null);
            Assert.That(array[2], Is.EqualTo("Beta"));
            Assert.That(array[3], Is.EqualTo("Gamma"));
            Assert.That(array[4], Is.EqualTo("Delta"));
        }
Ejemplo n.º 24
0
        public void SetIndexThrowsFallbackException()
        {
            dynamic alpha = new Object();
            dynamic beta  = new Clay(new TestMemberBehavior());

            var ex1 = Assert.Throws <RuntimeBinderException>(() => { alpha[0] = 1; });

            Assert.That(ex1.Message, Is.StringMatching(@"Cannot apply indexing with \[\] to an expression of type .*"));

            var ex2 = Assert.Throws <RuntimeBinderException>(() => { beta[0] = 2; });

            Assert.That(ex2.Message, Is.StringMatching(@"Cannot apply indexing with \[\] to an expression of type .*"));
        }
Ejemplo n.º 25
0
        public void InsertMayTakeSeveral()
        {
            dynamic array = new Clay(new ArrayBehavior());

            array.Add("a", "b", "c", "d").Insert(2, "b2", "b3", "b4").RemoveAt(3);

            Assert.That(array.Count, Is.EqualTo(6));
            Assert.That(array[0], Is.EqualTo("a"));
            Assert.That(array[1], Is.EqualTo("b"));
            Assert.That(array[2], Is.EqualTo("b2"));
            Assert.That(array[3], Is.EqualTo("b4"));
            Assert.That(array[4], Is.EqualTo("c"));
            Assert.That(array[5], Is.EqualTo("d"));
        }
Ejemplo n.º 26
0
        public void GetMemberThrowsFallbackException()
        {
            dynamic alpha = new Object();
            dynamic beta  = new Clay(new TestMemberBehavior());

            var ex1 = Assert.Throws <RuntimeBinderException>(() => { var hi = alpha.Hello1; });

            Assert.That(ex1.Message, Is.StringEnding("does not contain a definition for 'Hello1'"));

            var ex2 = Assert.Throws <RuntimeBinderException>(() => { var hi = beta.Hello2; });

            Assert.That(ex2.Message, Is.StringEnding("does not contain a definition for 'Hello2'"));

            Assert.That(beta.Sample, Is.EqualTo("Data"));
        }
Ejemplo n.º 27
0
 public override object InvokeMember(Func <object> proceed, object self, string name, INamedEnumerable <object> args)
 {
     if (name == "Array")
     {
         dynamic x = new Clay(
             new InterfaceProxyBehavior(),
             new PropBehavior(),
             new ArrayPropAssignmentBehavior(),
             new ArrayBehavior(),
             new NilResultBehavior());
         x.AddRange(args);
         return(x);
     }
     return(proceed());
 }
Ejemplo n.º 28
0
        public void InvokeMemberThrowsFallbackException()
        {
            dynamic alpha = new Object();
            dynamic beta  = new Clay(new TestMemberBehavior());

            var ex1 = Assert.Throws <RuntimeBinderException>(() => alpha.Hello1());

            Assert.That(ex1.Message, Does.EndWith("does not contain a definition for 'Hello1'"));

            var ex2 = Assert.Throws <RuntimeBinderException>(() => beta.Hello2());

            Assert.That(ex2.Message, Does.EndWith("does not contain a definition for 'Hello2'"));

            Assert.That(beta.Sample(), Is.EqualTo("Data"));
        }
Ejemplo n.º 29
0
        public void IteratingListReturnsValues()
        {
            dynamic array = new Clay(new ArrayBehavior(), new InterfaceProxyBehavior());

            array.Add("a", "b", "c", "d");

            var expectedCharacters = "abcd".GetEnumerator();

            foreach (var item in array)
            {
                Assert.That(expectedCharacters.MoveNext(), Is.True);
                Assert.That(item, Is.EqualTo(expectedCharacters.Current.ToString()));
            }
            Assert.That(expectedCharacters.MoveNext(), Is.False);
        }
Ejemplo n.º 30
0
        public void LengthAndCountShowCurrentSize()
        {
            dynamic array = new Clay(new ArrayBehavior());

            Assert.That(array.Length, Is.EqualTo(0));
            Assert.That(array.Count, Is.EqualTo(0));
            Assert.That(array.Length(), Is.EqualTo(0));
            Assert.That(array.Count(), Is.EqualTo(0));

            array.Add("Alpha");
            array.Add("Beta");

            Assert.That(array.Length, Is.EqualTo(2));
            Assert.That(array.Count, Is.EqualTo(2));
            Assert.That(array.Length(), Is.EqualTo(2));
            Assert.That(array.Count(), Is.EqualTo(2));
        }
Ejemplo n.º 31
0
        public void ContainsRemoveAndIndexOfFunctionAsNormalListWouldDictate()
        {
            dynamic array = new Clay(new ArrayBehavior());

            array.Add("a", "b", "c", "d");

            Assert.That(array.Contains("b"), Is.True);
            Assert.That(array.Contains("e"), Is.False);
            Assert.That(array.IndexOf("b"), Is.EqualTo(1));
            Assert.That(array.IndexOf("e"), Is.EqualTo(-1));
            Assert.That(array.Remove("b"), Is.True);
            Assert.That(array.Remove("e"), Is.False);

            Assert.That(array.Contains("b"), Is.False);
            Assert.That(array.IndexOf("b"), Is.EqualTo(-1));
            Assert.That(array.Remove("b"), Is.False);
        }
Ejemplo n.º 32
0
        public void CallingGetEnumeratorDirectlyOnDynamic()
        {
            dynamic array = new Clay(new ArrayBehavior(), new InterfaceProxyBehavior());

            array.Add("hello");

            IEnumerator enum1 = array.GetEnumerator();

            Assert.That(enum1.MoveNext(), Is.True);
            Assert.That(enum1.Current, Is.EqualTo("hello"));
            Assert.That(enum1.MoveNext(), Is.False);

            IEnumerator <object> enum2 = array.GetEnumerator();

            Assert.That(enum2.MoveNext(), Is.True);
            Assert.That(enum2.Current, Is.EqualTo("hello"));
            Assert.That(enum2.MoveNext(), Is.False);
        }