public void ChecksumShouldPassOnValidPackages() { var filename = "Squirrel.Core.1.0.0.0.nupkg"; var nuGetPkg = IntegrationTestHelper.GetPath("fixtures", filename); var fs = new Mock <IFileSystemFactory>(); var urlDownloader = new Mock <IUrlDownloader>(); ReleaseEntry entry; using (var f = File.OpenRead(nuGetPkg)) { entry = ReleaseEntry.GenerateFromFile(f, filename); } var fileInfo = new Mock <FileInfoBase>(); fileInfo.Setup(x => x.OpenRead()).Returns(File.OpenRead(nuGetPkg)); fileInfo.Setup(x => x.Exists).Returns(true); fileInfo.Setup(x => x.Length).Returns(new FileInfo(nuGetPkg).Length); fs.Setup(x => x.GetFileInfo(Path.Combine(".", "theApp", "packages", filename))).Returns(fileInfo.Object); var fixture = ExposedObject.From( new UpdateManager("http://lol", "theApp", FrameworkVersion.Net40, ".", fs.Object, urlDownloader.Object)); fixture.checksumPackage(entry); }
internal static void WriteTexture(object spriteFontContent, bool alphaOnly, ContentProcessorContext context, string filename) { dynamic sfc = ExposedObject.From(spriteFontContent); // Get a copy of the texture in Color format Texture2DContent originalTexture = sfc.Texture; BitmapContent originalBitmap = originalTexture.Mipmaps[0]; PixelBitmapContent <Color> colorBitmap = new PixelBitmapContent <Color>( originalBitmap.Width, originalBitmap.Height); BitmapContent.Copy(originalBitmap, colorBitmap); Bitmap bitmap = new Bitmap(colorBitmap.Width, colorBitmap.Height, PixelFormat.Format32bppArgb); for (int x = 0; x < colorBitmap.Width; x++) { for (int y = 0; y < colorBitmap.Height; y++) { Color c = colorBitmap.GetPixel(x, y); if (alphaOnly) { c.R = 255; c.G = 255; c.B = 255; // Undo premultiplication } bitmap.SetPixel(x, y, System.Drawing.Color.FromArgb(c.A, c.R, c.G, c.B)); } } bitmap.Save(filename, ImageFormat.Png); bitmap.Dispose(); context.AddOutputFile(filename); }
public void ChecksumShouldFailIfFilesAreMissing() { var filename = "Squirrel.Core.1.0.0.0.nupkg"; var nuGetPkg = IntegrationTestHelper.GetPath("fixtures", filename); var fs = new Mock <IFileSystemFactory>(); var urlDownloader = new Mock <IUrlDownloader>(); ReleaseEntry entry; using (var f = File.OpenRead(nuGetPkg)) { entry = ReleaseEntry.GenerateFromFile(f, filename); } var fileInfo = new Mock <FileInfoBase>(); fileInfo.Setup(x => x.OpenRead()).Returns(File.OpenRead(nuGetPkg)); fileInfo.Setup(x => x.Exists).Returns(false); fs.Setup(x => x.GetFileInfo(Path.Combine(".", "theApp", "packages", filename))).Returns(fileInfo.Object); var fixture = ExposedObject.From( new UpdateManager("http://lol", "theApp", FrameworkVersion.Net40, ".", fs.Object, urlDownloader.Object)); bool shouldDie = true; try { // NB: We can't use Assert.Throws here because the binder // will try to pick the wrong method fixture.checksumPackage(entry); } catch (Exception) { shouldDie = false; } shouldDie.ShouldBeFalse(); }
private async void ExtendChangesetDetailPage(ITeamExplorerPage page) { await Task.Delay(1000); Check.TryCatch <Exception>(() => { var grid = ((dynamic)ExposedObject.From(TeamExplorer.CurrentPage.PageContent)).Content as Grid; if (grid != null) { var header = grid.FindDescendants <FlowDocumentScrollViewer>(viewer => viewer.Uid == "changesetPageHeader").FirstOrDefault(); if (header != null) { var changeset = page.FindChangesetFromTeamExplorerPage(); if (changeset != null) { header.Visibility = Visibility.Collapsed; var stackPanel = new StackPanel { Orientation = Orientation.Vertical, Margin = new Thickness(2, 3, 0, 3) }; stackPanel.Children.Add(new TextBox { Text = string.Format("Changeset {0}", changeset.ChangesetId), IsReadOnly = true, Background = System.Windows.Media.Brushes.Transparent, BorderThickness = new Thickness(0), FontWeight = FontWeights.SemiBold, FontSize = 16 }); var stackPanel2 = new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(0, 0, 0, 3) }; stackPanel2.Children.Add(new TextLink { Margin = new Thickness(4, 5, 0, 4), Text = string.Format(changeset.CommitterDisplayName), Background = System.Windows.Media.Brushes.Transparent, BorderThickness = new Thickness(0), Command = StaticCommands.UserInfoCommand, CommandParameter = changeset.Committer }); stackPanel2.Children.Add(new TextBox { Margin = new Thickness(2, 4, 0, 4), Text = string.Format(changeset.CreationDate.ToString(CultureInfo.CurrentCulture)), Background = System.Windows.Media.Brushes.Transparent, BorderThickness = new Thickness(0), IsReadOnly = true }); stackPanel.Children.Add(stackPanel2); grid.Children.Add(stackPanel); Grid.SetColumn(stackPanel, 0); } } } }); }
public static dynamic Expose(this object obj) { var asType = obj as Type; if (asType != null) { return(ExposedClass.From(asType)); } return(ExposedObject.From(obj)); }
public void FindDependentPackagesForDummyPackage() { var inputPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.0.0.0.nupkg"); var fixture = ExposedObject.From(new ReleasePackage(inputPackage)); var sourceDir = IntegrationTestHelper.GetPath("..", "packages"); (new DirectoryInfo(sourceDir)).Exists.ShouldBeTrue(); IEnumerable <IPackage> results = fixture.findAllDependentPackages(null, sourceDir, null, null); results.Count().ShouldBeGreaterThan(0); }
public void FindPackageInOurLocalPackageList() { var inputPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.0.0.0.nupkg"); var sourceDir = IntegrationTestHelper.GetPath("..", "packages"); (new DirectoryInfo(sourceDir)).Exists.ShouldBeTrue(); var fixture = ExposedObject.From(new ReleasePackage(inputPackage)); IPackage result = fixture.findPackageFromName("xunit", VersionUtility.ParseVersionSpec("[1.0,2.0]"), sourceDir, null); result.Id.ShouldEqual("xunit"); result.Version.Version.Major.ShouldEqual(1); result.Version.Version.Minor.ShouldEqual(9); }
public static object GetTestResultsToolWindowContextHelperInstance() { return(Check.TryCatch <object, Exception>(() => { var resultToolWindowInstance = GetTestResultsToolWindowInstance(); if (resultToolWindowInstance != null) { object mContext = ((dynamic)ExposedObject.From(resultToolWindowInstance)).m_context as object; if (mContext != null) { return mContext; } } return null; })); }
// Wichtig: Die rückgabe hier muss die gleiche sein wie bei GetCommiterUniqueName(Changset) damit ein Changset mapping für eine TeamFoundationIdentity funktioniert public static string GetUniqueName(this TeamFoundationIdentity identity) { PropertyInfo propertyInfo = identity.GetType().GetProperty("UniqueName"); if (propertyInfo != null) { return(ExposedObject.From(identity).UniqueName); } try { var identifier = new SecurityIdentifier(identity.Descriptor.Identifier); var ntAccount = (NTAccount)(identifier.Translate(typeof(NTAccount))); return(ntAccount.ToString()); } catch (Exception) { return(identity.DisplayName); } }
public void ChecksumShouldFailIfFilesAreBogus() { var filename = "Squirrel.Core.1.0.0.0.nupkg"; var nuGetPkg = IntegrationTestHelper.GetPath("fixtures", filename); var fs = new Mock <IFileSystemFactory>(); var urlDownloader = new Mock <IUrlDownloader>(); ReleaseEntry entry; using (var f = File.OpenRead(nuGetPkg)) { entry = ReleaseEntry.GenerateFromFile(f, filename); } var fileInfo = new Mock <FileInfoBase>(); fileInfo.Setup(x => x.OpenRead()).Returns(new MemoryStream(Encoding.UTF8.GetBytes("Lol broken"))); fileInfo.Setup(x => x.Exists).Returns(true); fileInfo.Setup(x => x.Length).Returns(new FileInfo(nuGetPkg).Length); fileInfo.Setup(x => x.Delete()).Verifiable(); fs.Setup(x => x.GetFileInfo(Path.Combine(".", "theApp", "packages", filename))).Returns(fileInfo.Object); var fixture = ExposedObject.From( new UpdateManager("http://lol", "theApp", FrameworkVersion.Net40, ".", fs.Object, urlDownloader.Object)); bool shouldDie = true; try { fixture.checksumPackage(entry); } catch (Exception ex) { this.Log().InfoException("Checksum failure", ex); shouldDie = false; } shouldDie.ShouldBeFalse(); fileInfo.Verify(x => x.Delete(), Times.Once()); }
internal static void WriteMetrics(object spriteFontContent, ContentProcessorContext context, string filename) { dynamic sfc = ExposedObject.From(spriteFontContent); using (FileStream fs = File.Open(filename, FileMode.Create, FileAccess.Write)) { using (BinaryWriter bw = new BinaryWriter(fs, Encoding.Unicode)) { // Identifier and version: bw.Write((int)0x6E457845); // ExEn bw.Write((int)0x746E6F46); // Font bw.Write((int)0); // Write common properties bw.Write((int)sfc.LineSpacing); bw.Write((int)sfc.Spacing); if (bw.WriteBoolean(((char?)sfc.DefaultCharacter).HasValue)) { bw.Write(((char?)sfc.DefaultCharacter).Value); } // Write glyph list: int count = sfc.CharacterMap.Count; bw.Write(count); for (int i = 0; i < count; i++) { bw.Write((char)sfc.CharacterMap[i]); bw.Write((Rectangle)sfc.Glyphs[i]); bw.Write((Rectangle)sfc.Cropping[i]); bw.Write((Vector3)sfc.Kerning[i]); } } } context.AddDependency(filename); }
static void Main(string[] args) { var foo = ExposedObject.From(new Foo()); string stuff = foo.Bar.Baz._stuff; Console.WriteLine(stuff); foo.Name = "Bilbo"; Console.WriteLine(foo.Name); Console.WriteLine(foo.DoubleIt()); Console.WriteLine(foo.Reverse("Bilbo")); Console.WriteLine(foo._field2); foo._field2 = "Hello, Bilbo!"; Console.WriteLine(foo._field2); var realList = new List <int>(); var exposedList = ExposedObject.From(realList); // Read a private field - prints 0 Console.WriteLine(exposedList._size); // Modify a private field exposedList._items = new int[] { 5, 4, 3, 2, 1 }; // Modify another private field exposedList._size = 5; // Call a private method exposedList.EnsureCapacity(20); // Add a value to the list exposedList.Add(0); // Enumerate the list. Prints "5 4 3 2 1 0" foreach (var x in exposedList) { Console.WriteLine(x); } ThisIsAnUnrelatedInterface newInstance = ExposedObject.New <ThisIsAnUnrelatedInterface>(typeof(ImVisible), "MyName"); Console.WriteLine(newInstance.Name); // Call a static method var staticJumble = ExposedClass.From(typeof(StaticJumble)); string reversed = staticJumble.Reversed("Prow scuttle parrel provost Sail ho shrouds spirits boom mizzenmast yardarm. Pinnace holystone mizzenmast quarter crow's nest nipperkin grog yardarm hempen halter furl. Swab barque interloper chantey doubloon starboard grog black jack gangway rutters."); Console.WriteLine(reversed); var internalJumble = ExposedClass.From("Super.Secret.Library.InternalJumble", typeof(ImVisible).Assembly); reversed = internalJumble.Reversed(reversed); Console.WriteLine(reversed); var internalPrivateJumble = ExposedClass.From("Super.Secret.Library.InternalPrivateJumble", typeof(ImVisible).Assembly); reversed = internalPrivateJumble.MeToo.Reversed(reversed); Console.WriteLine(reversed); // Call a generic method var enumerableType = ExposedClass.From(typeof(System.Linq.Enumerable)); Console.WriteLine( enumerableType.Max(new[] { 1, 3, 5, 3, 1 })); }
public bool ShowDialog(Workspace workSpace = null, int pageToSelect = 0, bool?closeButtonOnly = null) { if (closeButtonOnly == null) { closeButtonOnly = pageToSelect == 4; } if (workSpace == null) { workSpace = versionControlServer.GetWorkspace(Environment.MachineName, versionControlServer.AuthorizedUser); } workSpace.Refresh(); //Thread.Sleep(2000); PendingChange[] pendingChange = workSpace.GetPendingChanges(); PendingChange[] checkedinPendingChange; if (workingFolder != null) { checkedinPendingChange = workSpace.GetPendingChanges(workingFolder.ServerItem, RecursionType.Full); } else if (changes != null && changes.Any()) { checkedinPendingChange = changes; } else { checkedinPendingChange = pendingChange; } //PendingChange[] checkedinPendingChange = pendingChange.Where(c => c.ServerItem.Contains(workingFolder.ServerItem)).ToArray(); //Assembly controlsAssembly = Assembly.LoadFile(controlsAssemblyPath); Assembly controlsAssembly = typeof(Microsoft.TeamFoundation.VersionControl.Controls.LocalPathLinkBox).Assembly; Type vcCheckinDialogType = controlsAssembly.GetType("Microsoft.TeamFoundation.VersionControl.Controls.DialogCheckin"); ConstructorInfo ci = vcCheckinDialogType.GetConstructor( BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(Workspace), typeof(PendingChange[]), typeof(PendingChange[]), typeof(string), typeof(CheckinNote), typeof(WorkItemCheckedInfo[]), typeof(string) }, null); checkInDialog = (Form)ci.Invoke(new object[] { workSpace, pendingChange, checkedinPendingChange, "", null, null, "" }); checkedPendingChanges = vcCheckinDialogType.GetProperty("CheckedChanges", BindingFlags.Instance | BindingFlags.NonPublic); checkedWorkItems = vcCheckinDialogType.GetProperty("CheckedWorkItems", BindingFlags.Instance | BindingFlags.NonPublic); checkinNotes = vcCheckinDialogType.GetProperty("CheckinNotes", BindingFlags.Instance | BindingFlags.NonPublic); comment = vcCheckinDialogType.GetProperty("Comment", BindingFlags.Instance | BindingFlags.NonPublic); policyFailureOverrideReason = vcCheckinDialogType.GetProperty("PolicyFailureOverrideReason", BindingFlags.Instance | BindingFlags.NonPublic); policyFailures = vcCheckinDialogType.GetProperty("PolicyFailures", BindingFlags.Instance | BindingFlags.NonPublic); if (Application.OpenForms.Count > 0 && Application.OpenForms[0] != null) { checkInDialog.Owner = Application.OpenForms[0]; checkInDialog.StartPosition = FormStartPosition.CenterParent; } dynamic dynamicForm = ExposedObject.From(checkInDialog); dynamic checkinsChannelControl = ExposedObject.From(dynamicForm.m_channelControl); // PendingCheckinsChannelControl //dynamic conflictsChannel = ExposedObject.From(((dynamic)checkinsChannelControl).ConflictsControl); //dynamic conflictsPresenter = ExposedObject.From(((dynamic)conflictsChannel).m_conflictPresenter); //dynamic conflictStore = ExposedObject.From(((dynamic)conflictsPresenter).m_store); if (pageToSelect != 0) { checkinsChannelControl.SelectedChannel = pageToSelect; var channel = checkinsChannelControl.SelectedChannel; } if (closeButtonOnly == true) { try { dynamicForm.buttonOK.Visible = false; dynamicForm.buttonCancel.Text = "Close"; } catch (Exception e) { Console.WriteLine(e); } } checkInDialog.ShowDialog(); this.DialogResult = checkInDialog.DialogResult; System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor; if (DialogResult != DialogResult.Cancel) { PendingChange[] selectedPendingChange = (PendingChange[])checkedPendingChanges.GetValue(checkInDialog, null); WorkItemCheckinInfo[] checkedWorkItemInfo = (WorkItemCheckinInfo[])checkedWorkItems.GetValue(checkInDialog, null); string comments = (string)comment.GetValue(checkInDialog, null); string policyReason = (string)policyFailureOverrideReason.GetValue(checkInDialog, null); CheckinNote notes = (CheckinNote)checkinNotes.GetValue(checkInDialog, null); PolicyFailure[] failures = (PolicyFailure[])policyFailures.GetValue(checkInDialog, null); PolicyOverrideInfo overrideinfo = new PolicyOverrideInfo(policyReason, failures); try { workSpace.CheckIn(selectedPendingChange, comments, notes, checkedWorkItemInfo, overrideinfo); } catch (Exception exp) { System.Windows.Forms.MessageBox.Show("Check in Failed due to " + exp.Message); return(false); } } else { return(true); } return(true); }