public async Task AddAsync() { ICalculator calculator = await Factory.CreateClient <ICalculator>(); for (int i = 0; i < OperationsPerInvoke; i++) { await calculator.AddAsync(1, 1); } }
public async Task InstalledService_ShouldRun() { if (Environment.OSVersion.Platform != PlatformID.Win32NT) Assert.Ignore("The related feature is Windows exclusive."); using var factory = new RpcClientFactory(HOST); ICalculator calculator = await factory.CreateClient<ICalculator>(); Assert.That(await calculator.AddAsync(1, 1), Is.EqualTo(2)); }
public Task <int> SumOfAggregatesAsync(int[] array1, int[] array2) { IPrincipal principal = Thread.CurrentPrincipal; string message = "The IPrincipal was not passed on thread to remote service on cluster"; if (principal is ClaimsPrincipal) { ClaimsPrincipal claimsPrincipal = principal as ClaimsPrincipal; Claim claim = claimsPrincipal.Claims.FirstOrDefault(x => x.Value.Equals("TestClaimValue1")); if (claim != null) { message = "Successfully passed the IPrincipal on the thread to the remote service on the cluster"; } } ServiceEventSource.Current.ServiceMessage(this, message); int sum1 = array1.Aggregate((x, y) => x + y); int sum2 = array2.Aggregate((x, y) => x + y); Thread.CurrentPrincipal = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim("TestClaim2", "TestClaimValue1") })); ServiceProxyFactory proxyFactory = new ServiceProxyFactory(c => new ServiceRemotingClientFactoryWrapper( new WcfServiceRemotingClientFactory(callbackClient: c))); ICalculator calculator = proxyFactory.CreateServiceProxy <ICalculator>(new Uri("fabric:/SFDelPerms/Stateless1")); //ICalculator calculator = ServiceProxy.Create<ICalculator>(new Uri("fabric:/LoggingPOC/Stateless1")); return(calculator.AddAsync(sum1, sum2)); }
private static async Task DecorateTestAsync() { var builder = new ContainerBuilder(); builder.RegisterType <ConsoleLogger>() .As <ILogger>() .SingleInstance(); #region Decorate builder.RegisterType <Calculator>() .Decorate <ICalculator>(builder); builder.RegisterType <CalculatorX>() .Decorate <ICalculator>(builder) //, decoratorConfig: x => x.InstancePerDependency()) .Decorate(builder, "A"); builder.RegisterType <CalculatorY>() .Decorate <ICalculator>(builder, "A"); #endregion // Decorate var container = builder.Build(); #region Test bool r = container.IsRegistered <ICalculator>(); bool ra = container.IsRegisteredWithKey <ICalculator>("A"); ICalculator f = container.Resolve <ICalculator>(); ICalculator f1 = container.Resolve <ICalculator>(); if (f != f1) { Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("NOT SINGLETOE !!!"); Console.ResetColor(); } Console.WriteLine(f.GetType().Name); Console.WriteLine(f); int i = await f.AddAsync(1, 2); i = f.Sub(17, 20); Console.WriteLine(); ICalculator[] fs = container.Resolve <ICalculator[]>(); foreach (var item in fs) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"** {item} **"); Console.ResetColor(); item.Add(3, 4); } Console.WriteLine(); ICalculator fa = container.ResolveKeyed <ICalculator>("A"); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("####### A ######"); Console.ResetColor(); fa.Add(9, 8); Console.WriteLine(); ICalculator[] fsa = container.ResolveKeyed <ICalculator[]>("A"); foreach (var item in fsa) { Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine($"##### {item} ######"); Console.ResetColor(); item.Add(3, 1); } #endregion // Test }