public void TestAnotherTypeSetter()
 {
     var builder = new DynamicProxyBuilder("RecycleBin.DynamicProxy.Proxy");
      var person = new Person("Alice", new DateTime(2000, 10, 2));
      var proxy = (IPerson)builder.CreateProxy(typeof(IPerson), person);
      Assert.That(proxy.AnotherTypeProperty = null, Throws.TypeOf<NotSupportedException>());
 }
 public void TestAnotherTypeMethod()
 {
     var builder = new DynamicProxyBuilder("RecycleBin.DynamicProxy.Proxy");
      var person = new Person("Alice", new DateTime(2000, 10, 2));
      var proxy = (IPerson)builder.CreateProxy(typeof(IPerson), person);
      proxy.AnotherTypeMethod(null);
 }
 public void TestProxyInterface()
 {
     string log = string.Format("[{0}] something", DateTime.Now);
      var console = new StringBuilder();
      using (var stdout = new StringWriter(console))
      {
     Console.SetOut(stdout);
     var builder = new DynamicProxyBuilder("RecycleBin.DynamicProxy.Proxy");
     var proxy = (IRecordable)builder.CreateProxy(typeof(IProxyRecordable), Console.Out, typeof(TextWriter));
     Logger.LogMessage(log, proxy);
      }
      var expected = log + Environment.NewLine;
      Assert.That(console.ToString(), Is.EqualTo(expected));
 }
 public void TestWrongTarget()
 {
     var builder = new DynamicProxyBuilder("RecycleBin.DynamicProxy.Proxy");
      var person = new Person("Alice", new DateTime(2000, 10, 2));
      var proxy = (IPerson)builder.CreateProxy(typeof(IPerson), person);
      Assert.That(proxy[1, 2], Throws.TypeOf<NotSupportedException>());
 }
 public void TestProxy()
 {
     var builder = new DynamicProxyBuilder("RecycleBin.DynamicProxy.Proxy");
      var person = new Person("Alice", new DateTime(2000, 10, 2));
      var proxy = (IPerson)builder.CreateProxy(typeof(IPerson), person);
      Assert.That(proxy, Is.Not.Null);
      Assert.That(proxy.Name, Is.EqualTo(person.Name));
      Assert.That(proxy.Date, Is.EqualTo(person.Birthday));
      Assert.That(proxy[1], Is.EqualTo(person[1]));
      var today = DateTime.Now;
      Assert.That(proxy.GetValue(today), Is.EqualTo(person.GetAge(today)));
      person.Name = "Bob";
      Assert.That(proxy.Name, Is.EqualTo("Bob"));
 }