Ejemplo n.º 1
0
    public static void XmlSFAttributeRpcEncSingleNsTest()
    {
        BasicHttpBinding binding                    = null;
        EndpointAddress  endpointAddress            = null;
        ChannelFactory <ICalculatorRpcEnc> factory1 = null;
        ICalculatorRpcEnc serviceProxy1             = null;

        // *** SETUP *** \\
        binding         = new BasicHttpBinding();
        endpointAddress = new EndpointAddress(Endpoints.BasicHttpRpcEncSingleNs_Address);
        factory1        = new ChannelFactory <ICalculatorRpcEnc>(binding, endpointAddress);
        serviceProxy1   = factory1.CreateChannel();

        // *** EXECUTE Variation *** \\
        try
        {
            var dateTime  = DateTime.Now;
            var intParams = new IntParams()
            {
                P1 = 5, P2 = 10
            };
            var floatParams = new FloatParams()
            {
                P1 = 5.0f, P2 = 10.0f
            };
            var byteParams = new ByteParams()
            {
                P1 = 5, P2 = 10
            };

            Assert.Equal(3, serviceProxy1.Sum2(1, 2));
            Assert.Equal(intParams.P1 + intParams.P2, serviceProxy1.Sum(intParams));
            Assert.Equal(string.Format("{0}{1}", intParams.P1, intParams.P2), serviceProxy1.Concatenate(intParams));
            Assert.Equal((float)(floatParams.P1 / floatParams.P2), serviceProxy1.Divide(floatParams));
            Assert.Equal((new byte[] { byteParams.P1, byteParams.P2 }), serviceProxy1.CreateSet(byteParams));
            Assert.Equal(dateTime, serviceProxy1.ReturnInputDateTime(dateTime));

            Guid guid = Guid.NewGuid();
            serviceProxy1.AddIntParams(guid, intParams);
            IntParams outputIntParams = serviceProxy1.GetAndRemoveIntParams(guid);
            Assert.NotNull(outputIntParams);
            Assert.Equal(intParams.P1, outputIntParams.P1);
            Assert.Equal(intParams.P2, outputIntParams.P2);
        }
        catch (Exception ex)
        {
            Assert.True(false, ex.Message);
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy1);
        }
    }
Ejemplo n.º 2
0
    private static void RunVariation(string serviceAddress, bool isMultiNs = false)
    {
        BasicHttpBinding             binding         = null;
        EndpointAddress              endpointAddress = null;
        ChannelFactory <ICalculator> factory1        = null;
        ChannelFactory <IHelloWorld> factory2        = null;
        ICalculator serviceProxy1 = null;
        IHelloWorld serviceProxy2 = null;

        // *** SETUP *** \\
        binding         = new BasicHttpBinding();
        endpointAddress = new EndpointAddress(serviceAddress);
        factory1        = new ChannelFactory <ICalculator>(binding, endpointAddress);
        serviceProxy1   = factory1.CreateChannel();
        if (isMultiNs)
        {
            factory2      = new ChannelFactory <IHelloWorld>(binding, endpointAddress);
            serviceProxy2 = factory2.CreateChannel();
        }

        // *** EXECUTE Variation *** \\
        try
        {
            var    dateTime  = DateTime.Now;
            string testStr   = "test string";
            var    intParams = new IntParams()
            {
                P1 = 5, P2 = 10
            };
            var floatParams = new FloatParams()
            {
                P1 = 5.0f, P2 = 10.0f
            };
            var byteParams = new ByteParams()
            {
                P1 = 5, P2 = 10
            };

            Assert.Equal(3, serviceProxy1.Sum2(1, 2));
            Assert.Equal(intParams.P1 + intParams.P2, serviceProxy1.Sum(intParams));
            Assert.Equal(string.Format("{0}{1}", intParams.P1, intParams.P2), serviceProxy1.Concatenate(intParams));
            Assert.Equal((float)(floatParams.P1 / floatParams.P2), serviceProxy1.Divide(floatParams));
            Assert.Equal((new byte[] { byteParams.P1, byteParams.P2 }), serviceProxy1.CreateSet(byteParams));
            Assert.Equal(dateTime, serviceProxy1.ReturnInputDateTime(dateTime));

            Guid guid = Guid.NewGuid();
            serviceProxy1.AddIntParams(guid, intParams);
            IntParams outputIntParams = serviceProxy1.GetAndRemoveIntParams(guid);
            Assert.NotNull(outputIntParams);
            Assert.Equal(intParams.P1, outputIntParams.P1);
            Assert.Equal(intParams.P2, outputIntParams.P2);

            if (isMultiNs)
            {
                Guid guid2 = Guid.NewGuid();
                serviceProxy2.AddString(guid2, testStr);
                Assert.Equal(testStr, serviceProxy2.GetAndRemoveString(guid2));
            }
        }
        catch (Exception ex)
        {
            Assert.True(false, ex.Message);
        }
        finally
        {
            // *** ENSURE CLEANUP *** \\
            ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy1);
            if (isMultiNs)
            {
                ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy2);
            }
        }
    }