public void Update_ItemPassed_ShouldReplaceLinks([Substitute] LinkDatabase linkDb, Db db)
    {
      var datasourceItemId = ID.NewID;

      db.Add(new DbItem("source")
      {
        Children =
        {
          new DbItem("_Local")
          {
            new DbItem("DatasourceItem")
          }
        },
        Fields =
        {
          "testField"
        }
      });
      ;
      db.Add(new DbItem("target")
      {
        Children =
        {
          new DbItem("_Local")
          {
            new DbItem("DatasourceItem")
          }
        },
        Fields =
        {
          "testField"
        }
      });
      ;


      var sourceItem = db.GetItem("/sitecore/content/source");
      var targetItem = db.GetItem("/sitecore/content/target");
      var datasourceItem = db.GetItem("/sitecore/content/source/_Local/DatasourceItem");
      var targetDatasourceItem = db.GetItem("/sitecore/content/target/_Local/DatasourceItem");
      var itemLinks = new[]
      {
        new ItemLink(sourceItem, FieldIDs.LayoutField, datasourceItem, string.Empty)
      };

      linkDb.GetReferences(sourceItem).Returns(itemLinks.ToArray());
      using (new LinkDatabaseSwitcher(linkDb))
      {
        using (new EditContext(targetItem))
        {
          targetItem["__Renderings"] = datasourceItem.ID.ToString();
        }
        var referenceReplacer = new UpdateLocalDatasourceReferencesService(sourceItem, targetItem);

        referenceReplacer.Update();

        var expectedValue = targetDatasourceItem.ID.ToString();
        targetItem["__Renderings"].Should().Be(expectedValue);
      }
    }
        /// <summary>
        ///   Simulate that a given key is pressed. (Down and up)
        /// </summary>
        public static void SimulateKeyPress( Key key )
        {
            var virtualKey = (ushort)KeyInterop.VirtualKeyFromKey( key );
            var keyPress = new []
            {
                new User32.Input
                {
                    Type = User32.InputEventType.Keyboard,
                    KeyboardInput = new User32.KeyboardInput
                    {
                        VirtualKey = virtualKey,
                    }
                },
                new User32.Input
                {
                    Type = User32.InputEventType.Keyboard,
                    KeyboardInput = new User32.KeyboardInput
                    {
                        VirtualKey = virtualKey,
                        Flags = User32.KeyboardInputFlags.KeyUp
                    }
                }
            };

            User32.SendInput( (uint)keyPress.Length, keyPress.ToArray(), User32.Input.Size );
        }
        public void then_derived_types_add_children_command_are_provided()
        {
            var collectionAddCommandTitles =
                commandContainer.ChildCommands.OfType<DefaultCollectionElementAddCommand>().Select(c => c.Title);

            var expectedCommandTitles =
                new[] { typeof(TestHandlerAnotherDerivedData).Name, typeof(TestHandlerSonOfDerivedData).Name }.Select(
                    s => "Add " + s);

            CollectionAssert.IsSubsetOf(expectedCommandTitles.ToArray(),
                                        collectionAddCommandTitles.ToArray());
        }
        public void Should_Create_Success_Json_And_Append_Messages()
        {
            using (var container = ContextScopeProvider.CreateChildContainer())
            {
                var controller = PrepareController(container);
                var messages = new[] { "Message 1" };
                var json = new WireJson { Success = true, Messages = messages.ToArray() };
                var jsonResult = controller.Json(json);

                Assert.AreEqual(jsonResult.Data, json);
                AssertJson(messages, jsonResult);
            }
        }
        public void Scripting_Shape_Text_Set()
        {
            var page1 = this.GetNewPage();
            var stencil = "basic_u.vss";

            short flags = (short)IVisio.VisOpenSaveArgs.visOpenRO | (short)IVisio.VisOpenSaveArgs.visOpenDocked;
            var app = page1.Application;
            var documents = app.Documents;
            var stencil_doc = documents.OpenEx(stencil, flags);

            var masters1 = stencil_doc.Masters;
            var masters = new[] { masters1["Rounded Rectangle"], masters1["Ellipse"] };
            var point0 = new VA.Drawing.Point(1, 2);
            var point1 = new VA.Drawing.Point(3, 4);
            var points = new[] { point0, point1 };
            Assert.AreEqual(0, page1.Shapes.Count);

            var shapeids = page1.DropManyU(masters, points);
            Assert.AreEqual(2, page1.Shapes.Count);
            Assert.AreEqual(2, shapeids.Length);

            var shapes = page1.Shapes.GetShapesFromIDs(shapeids);
            var client = this.GetScriptingClient();
            var names = new[] { "TestName", "TestName2" };
            var texts = names.ToArray();

            client.Text.Set(shapes, texts);
            client.ShapeSheet.SetName(shapes, names);

            for (int i = 0; i < page1.Shapes.Count; i++)
            {
                var shape = shapes[i];
                var name = names[i];
                var text = texts[i];
                Assert.AreEqual(name, shape.Name);
                Assert.AreEqual(text, shape.Text);
            }

            page1.Delete(0);
        }
예제 #6
0
        private void OutputGameState(Game game)
        {
            Csl.Header(string.Format("Game state {0}, next to move is {1}", game.States.Count, game.GetActivePlayer().Name));

            Csl.StartTable(18, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 10);

            var headers = new[] {"Player"}.Concat(Enumerable.Range(1, 8).Select(x => x.ToString())).Concat(new [] { "Sum" });

            Csl.TableHead(headers.ToArray());

            var white = new[] {game.White.Name}.Concat(game.GetCurrentState().WhiteCells.Select(x => (x is Die) ? ((Die) x).Value.ToString() : "." )).ToList();
            white.Add(game.GetCurrentState().WhiteCells.OfType<Die>().Sum(x => x.Value).ToString());

            Csl.TableRow(white.ToArray());

            var black = new[] { game.Black.Name }.Concat(game.GetCurrentState().BlackCells.Select(x => (x is Die) ? ((Die) x).Value.ToString() : "." )).ToList();
            black.Add(game.GetCurrentState().BlackCells.OfType<Die>().Sum(x => x.Value).ToString());

            Csl.TableRow(black.ToArray());

            Csl.Break(2);
        }
        public void Test()
        {
            var asssembly1src =
                @"
            using System;
            using System.Runtime.CompilerServices;

            public class A
            {
            public void Fine() {}
            unsafe public void NotFine(IntPtr* a) {}
            }

            unsafe public class B
            {
            IntPtr* bad;

            public void Fine() {}
            public void AlsoFine(IntPtr* a) {}

            [MethodImpl(MethodImplOptions.InternalCall)]
            public extern void AlsoFine2();
            }

            public class C
            {
            public void NotFine(B b) {}
            public void Fine() {}
            }

            public class SubB : B
            {
            }

            public class D
            {
            SubB b;
            }
            public class E
            {
            public void NotFine(D d) {}
            }

            ";

            var assembly = CSharpCompiler.CompileTempAssembly(asssembly1src);

            var ad = AssemblyFactory.GetAssembly(assembly);
            var cdf = new CecilDefinitionFinder(ad);
            MethodPrivilegeDetector.CriticalTypes = new[]
                                                        {
                                                            "B",
                                                            "SubB",
                                                            "D",
                                                        }.Select(s => cdf.FindType(s)).Cast<TypeReference>().ToList();
            var results = MethodPrivilegeDetector.MethodsRequiringPrivilegesThemselvesOn(ad).Select(kvp => kvp.Key);

            var expectedresults = new[]
                                  	{
                                  		"System.Void A::NotFine(System.IntPtr*)",
                                  		"System.Void C::NotFine(B)",
                                  		"System.Void E::NotFine(D)",
                                  	}.Select(s => cdf.FindMethod(s));

            CollectionAssert.AreEquivalent(expectedresults.ToArray(),results.ToArray());
        }