protected override Expression VisitMethodCall(MethodCallExpression node) { var instanceType = node.Object == null ? null : node.Object.Type; var map = new[] { new { Param = instanceType, Arg = node.Object } }.ToList(); map.AddRange(node.Method.GetParameters() .Zip(node.Arguments, (p, a) => new { Param = p.ParameterType, Arg = a })); // for any local collection parameters in the method, make a // replacement argument which will print its elements var replacements = (map.Where(x => x.Param != null && x.Param.IsGenericType) .Select(x => new {x, g = x.Param.GetGenericTypeDefinition()}) .Where(@t => @t.g == typeof (IEnumerable<>) || @t.g == typeof (List<>)) .Where(@t => @t.x.Arg.NodeType == ExpressionType.Constant) .Select(@t => new {@t, elementType = @t.x.Param.GetGenericArguments().Single()}) .Select( @t => new { @[email protected], Replacement = Expression.Constant("{" + string.Join("|", (IEnumerable) ((ConstantExpression) @[email protected]).Value) + "}") })).ToList(); if (replacements.Any()) { var args = map.Select(x => (from r in replacements where r.Arg == x.Arg select r.Replacement).SingleOrDefault() ?? x.Arg).ToList(); node = node.Update(args.First(), args.Skip(1)); } return base.VisitMethodCall(node); }
public void FilePathMatcherTest() { string[] testFiles = new [] {"c:/temp/subfolder/file.js", "c:/temp/file.cs", "c:/projects/temp/file.cs", "c:/projects/file.js", "c:/projects/file.min.js"}; List<string> matches = new List<string>(FilePathMatcher.MatchFiles("*.js",testFiles,false)); List<string> expected = new List<string>(new[] {"c:/temp/subfolder/file.js", "c:/projects/file.js", "c:/projects/file.min.js"}); Assert.AreEqual(3,matches.Count,"Matches single extension pattern *.js"); Assert.AreEqual(string.Join(",", expected),string.Join(",",matches),"List matches"); matches = new List<string>(FilePathMatcher.MatchFiles("*.min.js",testFiles,true)); Assert.AreEqual(4,matches.Count,"Matches exclusion pattern *.min.js"); matches = new List<string>(FilePathMatcher.MatchFiles("temp/",testFiles,true)); expected = new List<string>(new[] {"c:/projects/file.js", "c:/projects/file.min.js"}); Assert.AreEqual(string.Join(",",expected),string.Join(",",matches),"List matches on excluding a folder path"); }
public void MultipleExtensionsTest(string url, string match, string pathInfo) { string[] files = new[] { "~/1.one", "~/2.two", "~/1.1/2/3.3", "~/one/two/3/4.4", "~/one/two/3/4/5/6/foo.htm" }; string[] extensions = new[] { "aspx", "hao", "one", "two", "3", "4" }; ConstraintTest(files, extensions, url, match, pathInfo); }
private static IList<object> ToList(object obj) { var list = new List<object>(); if (obj == null) { return list; } var types = new[] { typeof(string), typeof(ObjectId), typeof(Commit), typeof(TagAnnotation), typeof(Tag), typeof(Branch), typeof(DetachedHead), typeof(Reference), typeof(DirectReference), typeof(SymbolicReference) }; if (types.Contains(obj.GetType())) { list.Add(obj); return list; } list.AddRange(((IEnumerable)obj).Cast<object>()); return list; }
public void test_flatten_strings() { var a1 = new[] { "1", "2", "3" }; var a2 = new[] { "5", "6" }; var a3 = new object[] { "4", a2 }; var a4 = new object[] { a1, a3 }; assert_equal(new[] { "1", "2", "3", "4", "5", "6" }, a4.Flatten()); assert_equal(new object[] { a1, a3 }, a4); var a5 = new object[] { a1, new object[0], a3 }; assert_equal(new object[] { "1", "2", "3", "4", "5", "6" }, a5.Flatten()); assert_equal(new object[0], new object[0].Flatten()); assert_equal(new object[0], new object[] { new object[] { new object[] { new object[] { }, new object[] { } }, new object[] { new object[] { } }, new object[] { } }, new object[] { new object[] { new object[] { } } } }.Flatten()); var a8 = new object[] { new object[] { "1", "2" }, "3" }; var a9 = a8.Flatten(0); assert_equal(a8, a9); assert_equal(new object[] { "abc" }, new object[] { new object[] { new string[0] }, new[] { "abc" } }.Flatten()); assert_equal(new object[] { "abc" }, new object[] { new[] { "abc" }, new object[] { new string[0] } }.Flatten()); }
//プレイヤーを生成させるコルーチン関数 IEnumerator CreatePlayer() { Vector3 pos = new Vector3(Random.Range (-20.0f,20.0f),0.0f,(-20.0f,20.0f)); //ネットワーク上のプレイヤーを動的に生成 Network.Instantiate(player,pos,Quaternion.identity,0); yield return null; }
public void EvalReturnsSimplePropertyValue() { var obj = new { Foo = "Bar" }; ViewDataDictionary vdd = new ViewDataDictionary(obj); Assert.Equal("Bar", vdd.Eval("Foo")); }
public void OrderedSetIsInOrder() { var names = new[] {"First B", "Second B"}; const int TheId = 100; var a = new A {Name = "First", Id = TheId}; var b = new B {Name = names[1], OrderBy = 3, AId = TheId}; a.Items.Add(b); var b2 = new B {Name = names[0], OrderBy = 1, AId = TheId}; a.Items.Add(b2); ISession s = OpenSession(); s.Save(a); s.Flush(); s.Close(); s = OpenSession(); var newA = s.Get<A>(a.Id); Assert.AreEqual(2, newA.Items.Count); int counter = 0; foreach (B item in newA.Items) { Assert.AreEqual(names[counter], item.Name); counter++; } s.Close(); }
public void FillBackwardThenForwardTest() { var sp = new StockPrices(new[] { float.NaN, 1, float.NaN, 2, float.NaN }); sp.ReplaceNanFill(FillDirection.Backward).ReplaceNanFill(FillDirection.Forward); var expected = new[] { 1f, 1f, 2f, 2f, 2f }; CollectionAssert.AreEqual(expected, sp.Prices); }
public void ExecuteAsync_Returns_CorrectResponse() { // Arrange AuthenticationHeaderValue expectedChallenge1 = CreateChallenge(); AuthenticationHeaderValue expectedChallenge2 = CreateChallenge(); IEnumerable<AuthenticationHeaderValue> challenges = new[] { expectedChallenge1, expectedChallenge2 }; using (HttpRequestMessage expectedRequest = CreateRequest()) { IHttpActionResult result = CreateProductUnderTest(challenges, expectedRequest); // Act Task<HttpResponseMessage> task = result.ExecuteAsync(CancellationToken.None); // Assert Assert.NotNull(task); task.WaitUntilCompleted(); using (HttpResponseMessage response = task.Result) { Assert.NotNull(response); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); Assert.Equal(2, response.Headers.WwwAuthenticate.Count); Assert.Same(expectedChallenge1, response.Headers.WwwAuthenticate.ElementAt(0)); Assert.Same(expectedChallenge2, response.Headers.WwwAuthenticate.ElementAt(1)); Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); Assert.Same(expectedRequest, response.RequestMessage); } } }
public void ShouldCompareIntegerArraysAsDifferent() { var first = new[] { 1, 2, 3 }; var second = new[] { 1, 4, 3 }; Assert.That(first.CollectionEqual(second), Is.False, "Thought different integer arrays was equal"); }
public void CanResolveObjectAndType() { var lines = new[] {"object VifPackage: TVifPackage", "end"}; var vif = new VifObjectBuilder().Build(lines); Assert.AreEqual("VifPackage", vif.Name); Assert.AreEqual("TVifPackage", vif.Clazz); }
public void ShouldCompareIntegerArraysAsEqual() { var first = new[] { 1, 2, 3 }; var second = new[] { 1, 2, 3 }; Assert.That(first.CollectionEqual(second), Is.True, "Thought equal integer arrays wasn't equal"); }
void UpdateMesh() { Vector3[] vertices = new [] { new Vector3( 0f, 0f, 0f ), new Vector3( width, 0f, 0f ), new Vector3( 0f, height, 0f ), new Vector3( width, height, 0f ) }; int[] triangles = new [] { 0, 2, 1, 2, 3, 1 }; Vector3[] normals = new [] { -Vector3.forward, -Vector3.forward, -Vector3.forward, -Vector3.forward }; Vector2[] uv = new [] { new Vector2( 0, 0 ), new Vector2( 1, 0 ), new Vector2( 0, 1 ), new Vector2( 1, 1 ) }; mesh.vertices = vertices; mesh.triangles = triangles; mesh.normals = normals; mesh.uv = uv; }
public void CastWithFrom() { IEnumerable strings = new[] { "first", "second", "third" }; var query = from string x in strings select x; query.AssertSequenceEqual("first", "second", "third"); }
public void EvalWithModelAndDictionaryPropertyEvaluatesDictionaryValue() { var obj = new { Foo = new Dictionary<string, object> { { "Bar", "Baz" } } }; ViewDataDictionary vdd = new ViewDataDictionary(obj); Assert.Equal("Baz", vdd.Eval("Foo.Bar")); }
//Methods public BasePlayer createNewRandomPlayer() { CreatePlayer player = new BasePlayer (string playerName, int playerID, int teamID, int macro, int micro, int strategy, int multitasking, int scouting, int score, int performance){ //Name switchInt = Random.Range(1-10); switch(switchInt) { case 1: playerName = "Janik von Rotz"; case 2: playerName = "Luca Kündig"; case 3: playerName = "Stefan Beeler"; case 4: playerName = "Reno Meyer"; case 5: playerName = "Alexander Hauck"; case 6: playerName = "Mike Monticoli"; case 7: playerName = "Kevin Stadelmann"; case 8: playerName = "Sandro Ritz"; case 9: playerName = "Michael Lötscher"; } //ID playerID = Random.Range (1-255 } }
Vector3[] NewPath() { Vector3 point1 = new Vector3 (-10,0); Vector3 point2 = new Vector3(-5, Random.Range(-5, 5)); Vector3 point3 = new Vector3 (0, Random.Range(-5, 5)); Vector3[] datPath = new [] {point1, point2, point3}; return datPath; }
public ActionResult About() { ViewBag.Message = "Your app description page."; var model = new { Title = "Test Liquid View Engine", Content = "Xin chào bạn đến với Hien's Blog" }; //return template.Render(Hash.FromAnonymousObject(new { Title = "Test Liquid view engine" })); return View(model); }
public void ShuffleTest_IntEnumerable() { IEnumerable original = new[] { 1, 2, 3, 4, 5 }; object obj = new ShuffleFormatter().Run(original, null, null, null); Assert.IsNotNull(obj); }
public void AddRangeCollectionChangedEventContainsAddedObjects() { var protArray = new[] { _protocol1, _protocol2, _protocol3 }; IList nodeListFromEvent = new ArrayList(); _protocolList.CollectionChanged += (sender, args) => nodeListFromEvent = args.NewItems; _protocolList.AddRange(protArray); Assert.That(nodeListFromEvent, Is.EquivalentTo(protArray)); }
public void CanBuildSimpleVif() { var lines = new[] {"object foo", "end"}; var vifBuilder = new VifObjectBuilder(); var single = vifBuilder.Build(lines); Assert.AreEqual(2, single.Lines.Count()); AssertChildCount(single, 0); }
public void GetDictionaryWorks() { var obj = new { a = "valueA", b = 134 }; var d = JsDictionary.GetDictionary(obj); Assert.AreStrictEqual(d, obj); Assert.AreEqual(2, d.Keys.Count); Assert.AreEqual(d["a"], "valueA"); Assert.AreEqual(d["b"], 134); }
private void SwitchViewImplementation() { var hashtable1 = (Hashtable) typeof (BooViewEngine).GetField("compilations", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(BooViewEngine); var hashtable2 = (Hashtable) typeof (BooViewEngine).GetField("constructors", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(BooViewEngine); hashtable1[@"subview\listItem.brail"] = typeof (DummySubView); var typeArray1 = new[] {typeof (BooViewEngine), typeof (TextWriter), typeof (IEngineContext), typeof (Controller), typeof (IControllerContext)}; hashtable2[typeof (DummySubView)] = typeof (DummySubView).GetConstructor(typeArray1); }
public void ReturnImageSourceTest() { LoadInputDocument("PictureWidth.xhtml"); var expected = new[] { "Pictures/Home.jpg", "Pictures/Garden.jpg" }; string stringContent = actualDocument.InnerXml; string[] actual = Common.ReturnImageSource(stringContent); Assert.AreEqual(expected, actual); }
public void EvalEvaluatesDictionaryThenModel() { var obj = new { Foo = "NotBar" }; ViewDataDictionary vdd = new ViewDataDictionary(obj); vdd.Add("Foo", "Bar"); Assert.Equal("Bar", vdd.Eval("Foo")); }
public void GetEnumerator_generic_version() { var data = new[] { 1f, 2f }; var graphicStream = new GraphicStream<float>(GraphicStreamUsage.Color, data); Assert.IsNotNull(graphicStream); Assert.AreElementsEqual(data, graphicStream); }
public void CorrectInstanceSetupSequence() { var expectedSequence = new[] { SetupSequence.Begin, SetupSequence.AfterSetProperties, SetupSequence.AfterAssociatedToParent, SetupSequence.End }; sut.Process(source.InstanceWithChild); var listener = (TestListener)sut.LifecycleListener; CollectionAssert.AreEqual(expectedSequence, listener.InvocationOrder); }
public void CanBuildRecursiveVifWithExtralinesInBody() { var lines = new[] {"object VifPackage: TVifPackage", "object VifPackage: TVifPackage", "foo", "bar", "end", "foo", "bar", "end"}; var vifBuilder = new VifObjectBuilder(); var single = vifBuilder.Build(lines); Assert.AreEqual(4, single.Lines.Count()); AssertChildCount(single, 1); }
public void CastWithJoin() { var ints = Enumerable.Range(0, 10); IEnumerable strings = new[] { "first", "second", "third" }; var query = from x in ints join string y in strings on x equals y.Length select x + ":" + y; query.AssertSequenceEqual("5:first", "5:third", "6:second"); }