public void GivenClassToProxyWithNoProperties_WhenBuildingProxy_ReturnAnNSubstituteProxyOfThatClass()
        {
            var proxyBuilder = new ProxyBuilder <Customer>(new Dictionary <string, Func <object> >());

            var proxy = proxyBuilder.Build();

            proxy.DidNotReceive().CustomerForHowManyYears(Arg.Any <DateTime>());
        }
        public void GivenClassToProxyWithNoProperties_WhenBuildingProxy_ReturnAnNSubstituteProxyOfThatClass()
        {
            var proxyBuilder = new ProxyBuilder<Customer>(new Dictionary<string, Func<object>>());

            var proxy = proxyBuilder.Build();

            proxy.DidNotReceive().CustomerForHowManyYears(Arg.Any<DateTime>());
        }
        public void GivenClassToProxyWithNoProperties_WhenBuildingProxy_ReturnAClassWithNoReturnsValuesSet()
        {
            var proxyBuilder = new ProxyBuilder <Customer>(new Dictionary <string, object>());

            var proxy = proxyBuilder.Build();

            Assert.That(proxy.FirstName, Is.EqualTo(string.Empty));
            Assert.That(proxy.LastName, Is.EqualTo(string.Empty));
            Assert.That(proxy.YearJoined, Is.EqualTo(0));
        }
        public void GivenClassToProxyWithNoProperties_WhenBuildingProxy_ReturnAClassWithNoReturnsValuesSet()
        {
            var proxyBuilder = new ProxyBuilder <Customer>(new Dictionary <string, Func <object> >());

            var proxy = proxyBuilder.Build();

            proxy.FirstName.ShouldBe(string.Empty);
            proxy.LastName.ShouldBe(string.Empty);
            proxy.YearJoined.ShouldBe(0);
        }
        public void GivenClassToProxyWithNoProperties_WhenBuildingProxy_ReturnAClassWithNoReturnsValuesSet()
        {
            var proxyBuilder = new ProxyBuilder<Customer>(new Dictionary<string, Func<object>>());

            var proxy = proxyBuilder.Build();

            proxy.FirstName.ShouldBe(string.Empty);
            proxy.LastName.ShouldBe(string.Empty);
            proxy.YearJoined.ShouldBe(0);
        }
        public void GivenClassToProxyWithSinglePropertyValue_WhenBuildingProxy_ReturnAClassWithReturnValueSetFromFunction()
        {
            int nonce = new Random().Next(0, 100);
            var proxyBuilder = new ProxyBuilder<Customer>(new Dictionary<string, Func<object>> {{"FirstName", () => "FirstName" + nonce}});

            var proxy = proxyBuilder.Build();

            proxy.FirstName.ShouldBe("FirstName" + nonce);
            proxy.LastName.ShouldBe(string.Empty);
            proxy.YearJoined.ShouldBe(0);
        }
        public void GivenClassToProxyWithSinglePropertyValue_WhenBuildingProxy_ReturnAClassWithReturnValueSet()
        {
            var proxyBuilder = new ProxyBuilder <Customer>(new Dictionary <string, object> {
                { "FirstName", "FirstName" }
            });

            var proxy = proxyBuilder.Build();

            Assert.That(proxy.FirstName, Is.EqualTo("FirstName"));
            Assert.That(proxy.LastName, Is.EqualTo(string.Empty));
            Assert.That(proxy.YearJoined, Is.EqualTo(0));
        }
        public void GivenClassToProxyWithSinglePropertyValue_WhenBuildingProxy_ReturnAClassWithReturnValueSet()
        {
            var proxyBuilder = new ProxyBuilder <Customer>(new Dictionary <string, object> {
                { "FirstName", "FirstName" }
            });

            var proxy = proxyBuilder.Build();

            proxy.FirstName.ShouldBe("FirstName");
            proxy.LastName.ShouldBe(string.Empty);
            proxy.YearJoined.ShouldBe(0);
        }
        public static T CreateProxy <T>(this T @this, ProxyContext context, params IInvocationHandler[] handlers)
            where T : class
        {
            @this.CheckCreatePreconditions(handlers);

            var targetType = @this.GetType();

            ProxyBuilder.Build(targetType, context);
            var arguments = new object[] { @this, handlers };

            return(Activator.CreateInstance(BuiltProxies.Mappings[targetType], arguments) as T);
        }
        public void GivenClassWithSomeVirtualProperties_WhenBuildingProxy_ThenOnlyVirtualMembersAreProxied()
        {
            var proxyBuilder = new ProxyBuilder <Company>(new Dictionary <string, Func <object> >()
            {
                { "Name", () => "Vandelay Industries" },
                { "EmployeeCount", () => 100 }
            });

            var proxy = proxyBuilder.Build();

            proxy.Name.ShouldBe("Vandelay Industries");
            proxy.EmployeeCount.ShouldBe(0);
        }
        public void GivenClassWithSomeVirtualProperties_WhenBuildingProxy_ThenOnlyVirtualMembersAreProxied()
        {
            var proxyBuilder = new ProxyBuilder <Company>(new Dictionary <string, object>()
            {
                { "Name", "Vandelay Industries" },
                { "EmployeeCount", 100 }
            });

            var proxy = proxyBuilder.Build();

            Assert.That(proxy.Name, Is.EqualTo("Vandelay Industries"));
            Assert.That(proxy.EmployeeCount, Is.EqualTo(0));
        }
        public void GivenClassToProxyWithSinglePropertyValue_WhenBuildingProxy_ReturnAClassWithReturnValueSetFromFunction()
        {
            int nonce        = new Random().Next(0, 100);
            var proxyBuilder = new ProxyBuilder <Customer>(new Dictionary <string, Func <object> > {
                { "FirstName", () => "FirstName" + nonce }
            });

            var proxy = proxyBuilder.Build();

            proxy.FirstName.ShouldBe("FirstName" + nonce);
            proxy.LastName.ShouldBe(string.Empty);
            proxy.YearJoined.ShouldBe(0);
        }
        public void GivenClassWithSomeVirtualProperties_WhenBuildingProxy_ThenOnlyVirtualMembersAreProxied()
        {
            var proxyBuilder = new ProxyBuilder<Company>(new Dictionary<string, Func<object>>()
            {
                {"Name", () => "Vandelay Industries"},
                {"EmployeeCount", () => 100}
            });

            var proxy = proxyBuilder.Build();

            proxy.Name.ShouldBe("Vandelay Industries");
            proxy.EmployeeCount.ShouldBe(0);
        }
        public void GivenClassToProxyWithMultiplePropertyValues_WhenBuildingProxy_ReturnAClassWithReturnValueSet()
        {
            var proxyBuilder = new ProxyBuilder <Customer>(new Dictionary <string, Func <object> >
            {
                { "FirstName", () => "FirstName" },
                { "LastName", () => "LastName" },
                { "YearJoined", () => 1 },
            }
                                                           );

            var proxy = proxyBuilder.Build();

            proxy.FirstName.ShouldBe("FirstName");
            proxy.LastName.ShouldBe("LastName");
            proxy.YearJoined.ShouldBe(1);
        }
        public void GivenClassToProxyWithMultiplePropertyValues_WhenBuildingProxy_ReturnAClassWithReturnValueSet()
        {
            var proxyBuilder = new ProxyBuilder<Customer>(new Dictionary<string, Func<object>>
                {
                    { "FirstName", () => "FirstName" },
                    { "LastName", () => "LastName" },
                    { "YearJoined", () => 1 },
                }
            );

            var proxy = proxyBuilder.Build();

            proxy.FirstName.ShouldBe("FirstName");
            proxy.LastName.ShouldBe("LastName");
            proxy.YearJoined.ShouldBe(1);
        }
Beispiel #16
0
        public void Init()
        {
            proxyBuilder = new ProxyBuilder();
            client = new Mock<RpcClient>(new Mock<RpcController>().Object);

            Type proxyType = proxyBuilder.Build(typeof(ISampleService));
            service = (ISampleService)Activator.CreateInstance(proxyType, client.Object);

            pendingCall = new PendingCall(0, null, null, null, null);
            resultMessage = new RpcMessage.Result();
            resultMessage.CallResult = new RpcMessage.Parameter();
            pendingCall.ReceiveResult(resultMessage);

            client.Setup(c => c.Call(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<RpcMessage.Parameter[]>(),
                It.IsAny<AsyncCallback>(), It.IsAny<object>()))
                .Returns(pendingCall);
        }
Beispiel #17
0
        public void Init()
        {
            proxyBuilder = new ProxyBuilder();
            client       = new Mock <RpcClient>(new Mock <RpcController>().Object);

            Type proxyType = proxyBuilder.Build(typeof(ISampleService));

            service = (ISampleService)Activator.CreateInstance(proxyType, client.Object);

            pendingCall              = new PendingCall(0, null, null, null, null);
            resultMessage            = new RpcMessage.Result();
            resultMessage.CallResult = new RpcMessage.Parameter();
            pendingCall.ReceiveResult(resultMessage);

            client.Setup(c => c.Call(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <RpcMessage.Parameter[]>(),
                                     It.IsAny <AsyncCallback>(), It.IsAny <object>()))
            .Returns(pendingCall);
        }
        public void BuildWithCollection()
        {
            this.Initialize();
            var generator1 = new AssemblyGenerator("BuildWithList1", new Dictionary <string, ReadOnlyCollection <MethodGenerator> >()
            {
                { "Type1", new List <MethodGenerator>()
                  {
                      new MethodGenerator("Method1", true),
                      new MethodGenerator("Method2", false)
                  }.AsReadOnly() },
                { "Type2", new List <MethodGenerator>()
                  {
                      new MethodGenerator("Method1", true),
                      new MethodGenerator("Method2", false)
                  }.AsReadOnly() }
            });

            var generator2 = new AssemblyGenerator("BuildWithList2", new Dictionary <string, ReadOnlyCollection <MethodGenerator> >()
            {
                { "Type1", new List <MethodGenerator>()
                  {
                      new MethodGenerator("Method1", true),
                      new MethodGenerator("Method2", false)
                  }.AsReadOnly() },
            });

            var assembly1 = generator1.Generate();
            var assembly2 = generator2.Generate();

            var types = new List <Type>();

            types.AddRange(assembly1.GetTypes());
            types.AddRange(assembly2.GetTypes());
            ProxyBuilder.Build(types.AsReadOnly());

            var proxyAssemblies = new HashSet <Assembly>();

            foreach (var type1 in assembly1.GetTypes())
            {
                proxyAssemblies.Add(Activator.CreateInstance(type1).CreateProxy(this).GetType().Assembly);
            }

            Assert.Equal(1, proxyAssemblies.Count);
        }
Beispiel #19
0
        internal ClassDeclarationSyntax BuildType(Compilation compilation)
        {
            var visitorBuilder = new ProxyBuilder(compilation);

            return(visitorBuilder.Build(TypeName, OriginType, _ctorTypes.ToArray()));
        }
 public void BuildWithEmptyCollection()
 {
     this.Initialize();
     Assert.Throws <ArgumentException>(() => ProxyBuilder.Build(new List <Type>().AsReadOnly()));
 }
 public void BuildWithNullCollection()
 {
     this.Initialize();
     Assert.Throws <ArgumentNullException>(() => ProxyBuilder.Build((null as ReadOnlyCollection <Type>)));
 }
Beispiel #22
0
 public void NotAnInterfaceFailureTest()
 {
     proxyBuilder.Build(typeof(NotAnInterfaceService));
 }
 public void BuildWithNullTarget()
 {
     this.Initialize();
     Assert.Throws <ArgumentNullException>(() => ProxyBuilder.Build((null as Type)));
 }
 public void BuildWithTypeThatImplementsIProxy()
 {
     this.Initialize();
     Assert.Throws <ArgumentException>(() => ProxyBuilder.Build(typeof(BadProxyClassWithCorrectTarget)));
 }
 public void BuildWithNullContextOnTarget()
 {
     this.Initialize();
     Assert.Throws <ArgumentNullException>(() => ProxyBuilder.Build(typeof(SimpleClass), null));
 }