예제 #1
0
 public IActionResult Get(double a, double b)
 {
     return(Ok(new
     {
         elementOne = a,
         elemetTwo = b,
         sum = _addService.Add(a, b)
     }));
 }
예제 #2
0
        /// <summary>
        /// Tests the fact that the ISimpleServiceContainer set as parameter is conform to the way the interface should be used.
        /// </summary>
        /// <typeparam name="T">the service implemented by the servicecontainer's baseprovider </typeparam>
        /// <param name="container">the ISimpleServiceContainer implementation to test</param>
        /// <param name="baseProviderServiceToTest"></param>
        public void IServiceContainerConformanceTest <T>(ISimpleServiceContainer container, ISimpleServiceContainer baseProvider, T baseProviderServiceToTest)
        {
            Func <IAddService> creatorFunc = () => new AddServiceImpl();

            IServiceContainerCoAndContravariance(container, creatorFunc);

            IServiceContainerConformanceAddRemove(container, creatorFunc);

            IServiceContainerConformanceAddFailsWhenExisting(container, creatorFunc);

            IServiceContainerConformanceRemoveRecursive(container);

            container.Add <IAddService>(creatorFunc);
            container.Add <ISubstractService>(new SubstractServiceImpl());

            IAddService service = container.GetService <IAddService>();

            Assert.That(service != null);
            Assert.That(service.GetType(), Is.EqualTo(typeof(AddServiceImpl)));
            Assert.That(service.Add(1, 1), Is.EqualTo(2));

            ISubstractService substractService = container.GetService <ISubstractService>();

            Assert.That(substractService != null);
            Assert.That(substractService.GetType(), Is.EqualTo(typeof(SubstractServiceImpl)));
            Assert.That(substractService.Substract(1, 1), Is.EqualTo(0));

            //clear test
            container.Clear();

            Assert.That(container.GetService <IAddService>(), Is.Null);
            Assert.That(container.GetService <ISubstractService>(), Is.Null);

            //base provider test
            if (baseProvider != null && baseProviderServiceToTest != null)
            {
                T baseService = container.GetService <T>();
                Assert.That(baseService != null, "The baseProvider contains the specified service.");

                container.Remove(typeof(T));
                baseService = container.GetService <T>();
                Assert.That(baseService != null, "Trying to remove a base service from a child provider does nothing.");

                container.AddDisabled(typeof(T));
                Assert.That(container.GetService <T>(), Is.Null, "Access to this service is disabled");

                baseProvider.Remove(typeof(T));
                Assert.That(container.GetService <T>(), Is.Null, "Access to this service is disabled & The service doesn't exist anymore on the baseProvider");

                container.Remove(typeof(T));
                Assert.That(container.GetService <T>(), Is.Null, "The service doesn't exist anymore on the baseProvider");

                baseProvider.Add(baseProviderServiceToTest);
                Assert.That(container.GetService <T>(), Is.Not.Null, "Back to the beginning's state, the service is retrieved from the base provider.");
            }
        }
예제 #3
0
        public void SimpleServiceContainerFallbackTest()
        {
            int removedServicesCount = 0;

            SimpleServiceContainer container = new SimpleServiceContainer();

            container.Add(typeof(IAddService), new AddServiceImpl(), o => removedServicesCount++);

            IAddService service = container.GetService <IAddService>();

            Assert.That(service != null);
            Assert.That(service.GetType(), Is.EqualTo(typeof(AddServiceImpl)));
            Assert.That(service.Add(1, 1), Is.EqualTo(2));

            Assert.That(removedServicesCount, Is.EqualTo(0));
            container.Remove(typeof(IAddService));
            Assert.That(removedServicesCount, Is.EqualTo(1));

            Assert.That(container.GetService(typeof(IAddService)), Is.Null);
            Assert.That(container.GetService <IAddService>(), Is.Null);
            Assert.Throws <CKException>(() => container.GetService <IAddService>(true));
        }
 public int Add(int op1, int op2)
 {
     return(_addService.Add(op1, op2));
 }
예제 #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Client started.");

            Console.WriteLine("==== simple sample ================================================================");

            ISeparationLayer separationLayer = SeparationLayerFactory.Create();
            IAddService      addService      = separationLayer.GetService <IAddService>();
            double           x = 3;
            double           y = 5;
            double           r = addService.Add(3, 5);

            Console.WriteLine("[addService demo] {0} + {1} => {2}", x, y, r);

            Console.WriteLine("==== Synchronously sample ================================================================");

            x = 30;
            y = 50;
            SeparationOperation <IAddService> addServiceOperation1 = separationLayer.CreateOperation <IAddService>();

            addServiceOperation1
            .Perform(() => { r = addServiceOperation1.Service.Add(x, y); })
            .Synchronously()
            .OnFinishInvoke(() => Console.WriteLine("finish"))
            .PostOperation();
            Console.WriteLine("[addService demo] {0} + {1} => {2}", x, y, r);

            Console.WriteLine("==== Asynchronously sample ================================================================");

            x = 300;
            y = 500;
            SeparationOperation <IAddService> addServiceOperation2 = separationLayer.CreateOperation <IAddService>();
            IAsyncOperation operation2 = addServiceOperation2
                                         .Perform(() => { r = addServiceOperation2.Service.Add(x, y); })
                                         .Asynchronously()
                                         .OnFinishInvoke(() => Console.WriteLine("finish"))
                                         .PostOperation();

            Console.WriteLine("waiting, r={0}", r);
            operation2.Wait();
            Console.WriteLine("[addService demo] {0} + {1} => {2}", x, y, r);

            Console.WriteLine("==== Cancel/Progress sample ================================================================");

            x = 3000;
            y = 5000;
            r = 0;
            SeparationOperation <IAddService> addServiceOperation3 = separationLayer.CreateOperation <IAddService>();
            IAsyncOperation operation3 = addServiceOperation3
                                         .Perform(() => { r = addServiceOperation3.Service.Add(x, y); })
                                         .Asynchronously()
                                         .OnErrorInvoke(e => Console.WriteLine("Error: {0}", e.Message))
                                         .OnCancelInvoke(() => Console.WriteLine("cancel"))
                                         .OnProgressInvoke(progressMessage => Console.WriteLine("{0} from {1}", progressMessage.Progress, progressMessage.Total))
                                         .OnFinishInvoke(() => Console.WriteLine("finish"))
                                         .PostOperation();

            Console.WriteLine("waiting, r={0}", r);
            Thread.Sleep(3000);
            operation3.Cancel();
            operation3.Wait();

            Console.WriteLine("==== Error sample ================================================================");

            SeparationOperation <IAddService> addServiceOperation4 = separationLayer.CreateOperation <IAddService>();
            IAsyncOperation operation4 = addServiceOperation4
                                         .Perform(() => { r = addServiceOperation3.Service.Add(0, 0); })
                                         .Asynchronously()
                                         .OnErrorInvoke(e => Console.WriteLine("Error: {0}", e.Message))
                                         .OnCancelInvoke(() => Console.WriteLine("cancel"))
                                         .OnFinishInvoke(() => Console.WriteLine("finish"))
                                         .PostOperation();

            Console.WriteLine("waiting, r={0}", r);
            operation4.Wait();

            Console.WriteLine("Client completed.");
        }
예제 #6
0
 public int Add(int x, int y)
 {
     return(add.Add(x, y));
 }
예제 #7
0
 public int Calculate(int num1, int num2)
 {
     Console.WriteLine("**--- CalcService calc executed ---**");
     return(_addService.Add(num1, num2));
 }