public void PropertiesCanBeAssignedAndRetrieved() { dynamic shape = new Clay(Cat(new PropBehavior())); shape.Foo = "textbox"; Assert.That((object)shape.Foo, Is.EqualTo("textbox")); }
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")); }
public dynamic New(string shapeName, Action <dynamic> initialize) { var item = new Clay(new PropBehavior()); initialize(item); return(item); }
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)); }
public void TakeClay(Clay clay) { clay.transform.SetParent(transform, false); Destroy(clay.gameObject); _hasClay = true; StartCoroutine(TransformClayToBrick()); }
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"); }
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"); }
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]")); }
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"); }
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]")); }
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"); }
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")); }
public void DifferentInstanceCreatedEachCall() { dynamic factory = new Clay(new ClayFactoryBehavior()); object alpha1 = factory.Alpha(); object alpha2 = factory.Alpha(); Assert.That(alpha1, Is.Not.SameAs(alpha2)); }
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")); }
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>()); }
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")); }
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); }
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")); }
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")); }
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(); }
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")); }
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")); }
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 .*")); }
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")); }
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")); }
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()); }
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")); }
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); }
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)); }
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); }
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); }