Exemplo n.º 1
0
        public void ChecksumShouldPassOnValidPackages()
        {
            var filename      = "Shimmer.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);
        }
Exemplo n.º 2
0
        public void ChecksumShouldFailIfFilesAreMissing()
        {
            var filename      = "Shimmer.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();
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
                        }
                    }
                }
            });
        }
Exemplo n.º 5
0
        public static dynamic Expose(this object obj)
        {
            var asType = obj as Type;

            if (asType != null)
            {
                return(ExposedClass.From(asType));
            }

            return(ExposedObject.From(obj));
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
 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;
     }));
 }
Exemplo n.º 9
0
        // 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);
            }
        }
Exemplo n.º 10
0
        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());
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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 }));
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            var someInt = 50;
            Expression <Func <Cat, string> >         catExpression  = cat => cat.SayMew(someInt);
            Expression <Func <int, int, int> >       sum            = (x, y) => x + y;
            Expression <Func <Cat, string> >         property       = cat => cat.Owner.FullName;
            Expression <Func <string, string, Cat> > catCreationExp = (CatName, OwnerName) => new Cat(CatName)
            {
                Owner = new Owner
                {
                    FullName = OwnerName
                }
            };

            Html.EditorFor <Cat>(c => c.Name);

            //var func = catExpression.Compile();
            //Console.WriteLine(func(new Cat()));

            //ParseExpression(property, string.Empty);

            var typeCat = typeof(Cat);
            //Generating Expresion Trees
            // () => 42

            //42
            var constant = Expression.Constant(42);
            //()=>
            var lambda = Expression.Lambda <Func <int> >(constant);
            var func   = lambda.Compile();

            //() => new Cat();
            var catExpr         = Expression.New(typeCat);
            var catLambda       = Expression.Lambda <Func <Cat> >(catExpr);
            var catConstruction = catLambda.Compile();
            var catt            = catConstruction();


            //cat => cat.sayMew(42);
            //42
            var constant42 = Expression.Constant(42);
            //cat
            var catExprParam = Expression.Parameter(typeCat, "cat");
            //Method cat.sayMew(42);
            var methodInfo = typeCat.GetMethod(nameof(Cat.SayMew));
            var call       = Expression.Call(catExprParam, methodInfo, constant);

            var lambdaCat = Expression.Lambda <Func <Cat, string> >(call, catExprParam);
            //var funcc = lambdaCat.Compile();
            //Console.WriteLine(funcc(new Cat()));

            //(cat, number) => cat.sayMew(number);
            var catExprParam1    = Expression.Parameter(typeCat, "cat");
            var numberParametar2 = Expression.Parameter(typeof(int), "number");
            //Method cat.sayMew(number);
            var methodInfo2 = typeCat.GetMethod(nameof(Cat.SayMew));
            var call2       = Expression.Call(catExprParam1, methodInfo, numberParametar2);

            var lambdaCat2 = Expression.Lambda <Func <Cat, int, string> >(call2, catExprParam1, numberParametar2);
            //var func2 = lambdaCat2.Compile();
            //Console.WriteLine(func2(new Cat(), 100));

            //MVC
            //RedirectToAction("Index", new {id = 5, query = "Test"})
            //id = 5, query = "Test"
            var obj  = new { id = 5, query = "Test" };
            var dict = new Dictionary <string, object>();

            obj.GetType()
            .GetProperties()
            .Select(pr => new
            {
                Name  = pr.Name,
                Value = pr.GetValue(obj)
            })
            .ToList()
            .ForEach(pr =>
            {
                dict[pr.Name] = pr.Value;
            });

            PropertyHelper.Get(obj)
            .Select(pr => new
            {
                Name  = pr.Name,
                Value = pr.Getter(obj)
            })
            .ToList()
            .ForEach(pr =>
            {
                dict[pr.Name] = pr.Value;
            });

            dict.Count();

            var     cat       = new Cat("SomeCatname");
            dynamic someClass = new ExposedObject(cat);

            Console.WriteLine(someClass.SomeProperty);
        }
Exemplo n.º 14
0
        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);
        }