Ejemplo n.º 1
0
        public void TestAssumptionAboutParams()
        {
            using (CaptureConsole) {
                var a = ItemsViaParams("very", "happy", "person");
                var b = ItemsWithoutParams(new[] {
                    "very", "happy", "person"
                });
                var c = ItemsViaParams(a);

                Assert.True(a.SequenceEqual(b));
                Assert.True(a.SequenceEqual(c));
                Assert.True(c.SequenceEqual(b));

                var items = Flatten(a, "more").ToArray();


                foreach (var i in items)
                {
                    Console.WriteLine(i);
                }

                var q = new int[] {
                    1, 2, 3
                };

                IEnumerable twoItems = a.Take(2).Concat(c).ConcatSingleItem(new string[] { "Help", null, "me" }).ConcatSingleItem(q);

                foreach (var i in Flatten(twoItems))
                {
                    Console.WriteLine(i);
                }
            }
        }
Ejemplo n.º 2
0
 public bool TakesAFileStream(FileStream ms)
 {
     Console.WriteLine("HUH?");
     Console.WriteLine("Type of stream is {0}", ms.GetType().Name);
     Console.WriteLine("Name of stream is {0}", ms.Name);
     return(ms != null);
 }
Ejemplo n.º 3
0
        public void ResolvePackageSourceTest()
        {
            using (CaptureConsole) {
                lock (Provider) {
                    Reset();

                    Console.WriteLine("hi");

                    Assert.NotNull(Provider);

                    // ask without any parameters
                    var sources = Provider.ResolvePackageSources(Host()).ToArray();
                    AssertNoErrors();
                    Assert.NotEmpty(sources);
                    foreach (var source in sources)
                    {
                        Console.WriteLine("Source {0} => {1}", source.Name, source.Location);
                    }

                    sources = Provider.ResolvePackageSources(Host(new {
                        // override just GetSources()
                        GetSources = new Func <IEnumerable <string> >(() => "source2".SingleItemAsEnumerable())
                    })).ToArray();
                    AssertNoErrors();
                    Assert.Equal(1, sources.Length);
                    Assert.Equal("location2", sources[0].Location);
                    Assert.Equal(_providerName, sources[0].ProviderName);
                    Assert.Equal(Provider, sources[0].Provider);
                }
            }
        }
Ejemplo n.º 4
0
        public string DoSomething(string someText, ThePluginImplementationOfTheRequest theRequest)
        {
            // since we're able to use the request object as the plugin's strongly type version
            // we can call methods on it directly.
            Tests.Set("BadImplementationwithHandlerCalled");

            Console.WriteLine("We get into the call, but we're going to throw.");
            throw new Exception("ha ha");
        }
Ejemplo n.º 5
0
 public void TestUsingStaticOnDyanmicType()
 {
     using (CaptureConsole) {
         Assert.Throws <RuntimeBinderException>(() => {
             dynamic x = new TUSODT();
             Console.WriteLine(x.Hello());
         });
     }
 }
Ejemplo n.º 6
0
 public Delegate CreateDelegate(string method, string[] parameterNames, Type[] parameterTypes, Type returnType)
 {
     if (method == "AddPackageSource4")
     {
         return(new Func <string, string, bool>((s, s1) => {
             Console.WriteLine("works finehere.");
             return true;
         }));
     }
     return(null);
 }
Ejemplo n.º 7
0
 internal void UseSecretData(SecureString secret)
 {
     using (CaptureConsole) {
         IntPtr bstr = Marshal.SecureStringToBSTR(secret);
         try {
             // Use the bstr here
             string plainPass = Marshal.PtrToStringUni(bstr);
             Console.WriteLine("Plain {0}", plainPass);
         } finally {
             // Make sure that the clear text data is zeroed out
             Marshal.ZeroFreeBSTR(bstr);
         }
     }
 }
Ejemplo n.º 8
0
        public void TestPipeline()
        {
            using (CaptureConsole) {
                dynamic ps = new DynamicPowershell();
                DynamicPowershellResult result = ps.Dir(@"c:\");

                DynamicPowershellResult result2 = ps.TestPath(result);

                foreach (var r in result2)
                {
                    Console.WriteLine(r);
                }
            }
        }
Ejemplo n.º 9
0
        public void FindPackageTest()
        {
            using (CaptureConsole) {
                var packages = Provider.FindPackage("test", null, null, null, new BasicHostImpl()).ToArray();

                Assert.Equal(2, packages.Length);
                var pkg1 = packages[0];
                Assert.Equal("first", pkg1.Name);
                Assert.Equal("1.0", pkg1.Version);
                Assert.Equal(Iso19770_2.VersionScheme.MultipartNumeric, pkg1.VersionScheme);
                Assert.Equal("testvalue", pkg1.Attributes[XNamespace.Get("http://oneget.org/oneget") + "testkey"]);

                Assert.Equal(1, pkg1.Meta.Count());
                Assert.Equal("first package", pkg1.Summary);
                Assert.Equal("first package", pkg1.Meta.FirstOrDefault()["summary"]);
                Assert.Equal("Shiny", pkg1.Meta.FirstOrDefault()["Something"]);

                Assert.Equal(2, pkg1.Links.Count());
                Assert.Equal(new Uri("swidtest:second/1.1"), pkg1.Links.FirstOrDefault().HRef);
                Assert.Equal("requires", pkg1.Links.FirstOrDefault().Relationship);

                Assert.Equal(1, pkg1.Dependencies.Count());
                Assert.Equal("swidtest:second/1.1", pkg1.Dependencies.FirstOrDefault());

                Assert.Equal(1, pkg1.Entities.Count());
                Assert.Contains("publisher", pkg1.Entities.FirstOrDefault().Roles);

                Assert.NotNull(pkg1.Payload);
                Assert.Null(pkg1.Evidence);

                Assert.Equal(1, pkg1.Payload.Directories.Count());
                Assert.Equal(1, pkg1.Payload.Directories.FirstOrDefault().Files.Count());
                Assert.Equal(1, pkg1.Payload.Resources.Count());

                Assert.Equal(1, packages[1].Dependencies.Count());
                Assert.Equal("swidtest:third/[1.0]", packages[1].Dependencies.FirstOrDefault());

                foreach (var pkg in packages)
                {
                    Console.WriteLine("PKG : {0}", pkg.SwidTagText);
                }
            }
        }
Ejemplo n.º 10
0
        public void TestAsFunction()
        {
            using (CaptureConsole) {
                var d = new DynInst();
                var t = d.As <Two>();
                t();

                var p = new {
                    Two = new Func <bool>(() => {
                        Console.WriteLine("In Func<bool> for Two!");
                        return(true);
                    })
                };

                var q = p.As <Two>();
                q();

                var z = new {
                };

                // this creates a dummy function now.

                var tz = z.As <Two>();
                tz();

                Func <bool> fTwo = new Func <bool>(() => {
                    Console.WriteLine("In fTwo");
                    return(true);
                });

                fTwo.As <Two>()();

                Assert.Throws <Exception>(() => {
                    Func <string> fThree = new Func <string>(() => {
                        Console.WriteLine("In fThree");
                        return("true");
                    });

                    fThree.As <Two>()();
                });
            }
        }
Ejemplo n.º 11
0
        public void TestSecureString()
        {
            using (CaptureConsole) {
                var password = "******";
                var p        = password.ToCharArray();
                var s        = new SecureString();
                foreach (char c in p)
                {
                    s.AppendChar(c);
                }
                UseSecretData(s);

                var ps = s.ToProtectedString("garrett");
                Console.WriteLine("PS: {0}", ps);

                var ss = ps.FromProtectedString("garret");
                //Console.WriteLine("ss: {0}", ss);
                UseSecretData(ss);
            }
        }
Ejemplo n.º 12
0
        public void TestGetTypes()
        {
            using (CaptureConsole) {
                var asm   = Assembly.GetExecutingAssembly();
                var types = asm.GetTypes();

                foreach (var t in types)
                {
                    if (t.IsEnum)
                    {
                        Console.WriteLine("ENUM: {0}", t.Name);
                        continue;
                    }
                    if (t.IsDelegate())
                    {
                        Console.WriteLine("Delegate: {0}", t.Name);
                        continue;
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public void TestChaining()
        {
            using (CaptureConsole) {
                var instance = DynamicInterface.DynamicCast <IDynTest>(
                    new {
                    One = new Action(() => { Console.WriteLine("Instance1::One"); }),
                }, new {
                    Two = new Func <bool>(() => {
                        Console.WriteLine("Instance1::Two");
                        return(true);
                    })
                }
                    );

                instance.One();

                // override 1:one
                var instance2 = DynamicInterface.DynamicCast <IDynTest>(
                    new {
                    One = new Action(() => { Console.WriteLine("Instance3::One"); }),
                    Two = new Func <bool>(() => { return(instance.Two()); })
                }
                    , instance);

                var instance3 = DynamicInterface.DynamicCast <IDynTest>(
                    new {
                    Four = new Func <int, string>((i) => {
                        Console.WriteLine("Instance3::Four");
                        return("::" + i);
                    }),
                }, instance2);

                instance3.One();
                instance3.Two();
                instance3.Three();
                instance3.Four(100);
                instance3.Five(100, "hi");
            }
        }
Ejemplo n.º 14
0
        public void TestWhichWayWorksForAggregate()
        {
            using (CaptureConsole) {
                var a = new string[] {
                    "one"
                };
                var b = new string[] {
                    "one", "two"
                };
                var c = new string[] {
                    "one", "two", "three"
                };

                var aa = a.Aggregate((current, each) => current + "," + each);
                var bb = b.Aggregate((current, each) => current + "," + each);
                var cc = c.Aggregate((current, each) => current + "," + each);

                Console.WriteLine(aa);
                Console.WriteLine(bb);
                Console.WriteLine(cc);

                Console.WriteLine(GetType().GetMethod("SampleMethod").ToSignatureString());
            }
        }
Ejemplo n.º 15
0
 public string Three()
 {
     Console.WriteLine("In three");
     return("Three");
 }
Ejemplo n.º 16
0
 public bool Two()
 {
     Console.WriteLine("In Two");
     return(true);
 }
Ejemplo n.º 17
0
 public void One()
 {
     Console.WriteLine("In One");
 }
Ejemplo n.º 18
0
 public virtual string Five(int a, string b)
 {
     Console.WriteLine("DefaultImplementation");
     return("NO ANSWER");
 }
Ejemplo n.º 19
0
 public bool AddPackageSource(string name, string location)
 {
     Console.WriteLine("name: {0}, location: {1}", name, location);
     return(true);
 }
Ejemplo n.º 20
0
        public void CheckForAcceptableTypes()
        {
            using (CaptureConsole) {
                var x = new ActualImplementation().As <ClientInterface>();
                var y = x.ActuallyReturnsString();
                var z = x.ActuallyReturnsFileStream();

                Console.WriteLine("Y is {0}", y.GetType().Name);
                Console.WriteLine("Z is {0}", z.GetType().Name);

                // this function doesn't match anything in the implemention
                // so a stub method gets created (which returns null)
                // MemoryStream a = x.ActuallyRetunsMemoryStream();
                // Assert.Null(a);

                // the clientinterface is more restricted than the implementation
                // but that's ok.
                MemoryStream ms = new MemoryStream();
                Assert.True(x.TakesAStream(ms));

                // the clientinterface is less restrictive than the implementation
                // and that's not ok.
                Assert.False(x.TakesAFileStream(ms));

                var shouldWork = new {
                    TakesAStream = new Func <Stream, bool>(stream => { return(stream != null); })
                }.As <ClientInterface>();

                Assert.True(shouldWork.TakesAStream(ms));

                var shouldNotWork = new {
                    TakesAFileStream = new Func <MemoryStream, bool>(stream => {
                        Console.WriteLine("never called");
                        return(stream != null);
                    })
                }.As <ClientInterface>();

                Assert.False(shouldWork.TakesAFileStream(ms));

                var shouldWorkToo = new {
                    ActuallyReturnsString = new Func <object>(() => "hello")
                }.As <ClientInterface>();

                Assert.NotNull(shouldWorkToo.ActuallyReturnsString());

                var shouldNotWorkToo = new {
                    ActuallyRetunsMemoryStream = new Func <Stream>(() => new MemoryStream())
                }.As <ClientInterface>();

                Assert.Null(shouldNotWorkToo.ActuallyRetunsMemoryStream());

                Func <object> fReturnsAString = new Func <object>(() => "hello");

                var fShouldWork = fReturnsAString.As <ReturnsAnObject>();

                Assert.NotNull(fShouldWork());

                Assert.Throws <Exception>(() => {
                    // this shouldn't work because the return type object
                    // can't be expressed as a string.
                    var fShouldNotWork = fReturnsAString.As <ReturnsAString>();
                });
            }
        }
Ejemplo n.º 21
0
 public string CallBackToTheHost(string someText)
 {
     Console.WriteLine(someText);
     return("Success");
 }
Ejemplo n.º 22
0
 public string Four(int a)
 {
     Console.WriteLine("Four {0}", a);
     return("Four" + a);
 }
Ejemplo n.º 23
0
 public void OnUnhandledException(string methodName, Exception e)
 {
     Console.WriteLine("Method : {0}", methodName);
     Console.WriteLine("Exception: {0}/{1}/{2}", e.GetType().Name, e.Message, e.StackTrace);
     Tests.Set("UnhandledExceptionCalled");
 }
Ejemplo n.º 24
0
 public string Five(int a, string b)
 {
     Console.WriteLine("Five {0} {1}", a, b);
     return("Four" + a + b);
 }
Ejemplo n.º 25
0
 public void OnUnhandledException(string methodName, Exception exception)
 {
     Console.WriteLine("Unexpected Exception thrown in '{0}::{1}' -- {2}\\{3}\r\n{4}", PackageProviderName, methodName, exception.GetType().Name, exception.Message, exception.StackTrace);
 }