public void Fire_OneMatchingFact_CanResolveDependencyFromContext() { //Arrange var service1 = new TestService1(); var service2 = new TestService2(); Session.DependencyResolver = new TestDependencyResolver(service1, service2); var fact = new FactType { TestProperty = "Valid Value 1" }; Session.Insert(fact); ITestService1 resolvedService1 = null; GetRuleInstance <TestRule>().Action = ctx => { resolvedService1 = ctx.Resolve <ITestService1>(); }; //Act Session.Fire(); //Assert AssertFiredOnce(); Assert.Same(service1, resolvedService1); }
public void Thread_Behavior() { _c.Register(new ComponentDefinition <ITestService1, TestService1>(Lifestyle.PerThread)); ITestService1 t1 = null; ITestService1 t2 = null; ITestService1 t3 = null; ITestService1 t4 = null; var th1 = new Thread( () => { Thread.Sleep(10); t1 = _c.Get <ITestService1>(); t2 = _c.Get <ITestService1>(); } ); var th2 = new Thread( () => { Thread.Sleep(10); t3 = _c.Get <ITestService1>(); t4 = _c.Get <ITestService1>(); } ); th1.Start(); th2.Start(); th1.Join(); th2.Join(); Assert.NotNull(t1); Assert.NotNull(t3); Assert.AreSame(t1, t2); Assert.AreSame(t3, t4); Assert.AreNotSame(t1, t3); }
public bool InitializeService() { _service = new TestService1Client("WSHttpBinding_ITestService1"); string s = _service.GetData(1); if(!String.IsNullOrEmpty(s)) return true; return false; }
public override void Define() { FactType fact = null; ITestService1 service1 = null; ITestService2 service2 = null; Dependency() .Resolve(() => service1) .Resolve(() => service2); When() .Match <FactType>(() => fact, f => f.TestProperty.StartsWith("Valid")); Then() .Do(ctx => Action(ctx)) .Do(ctx => service1.Action(fact.TestProperty)) .Do(ctx => service2.Action(fact.TestProperty)) .Do(ctx => SomeAction(fact, service1, service2)); }
public void Pooled_Behavior() { _c.Register(new ComponentDefinition <ITestService1, TestService1>(Lifestyle.Pooled)); var o1 = _c.Get <ITestService1>(); var o2 = _c.Get <ITestService1>(); Assert.AreNotSame(o1, o2); _c.Release(o1); var o3 = _c.Get <ITestService1>(); Assert.AreSame(o1, o3); ITestService1 s1 = null; using (var w1 = new ContainerObjectWrapper <ITestService1>(_c)) { s1 = w1.Object; } using (var w1 = new ContainerObjectWrapper <ITestService1>(_c)) { Assert.AreSame(s1, w1.Object); } }
private void SomeAction(FactType fact, ITestService1 service1, ITestService2 service2) { service1.Action(fact.TestProperty); service2.Action(fact.TestProperty); }
public async Task <ActionResult <object> > Get(int id, [FromServices] ITestService testService, [FromServices] ITestService1 testService1) { // string html = await testService1.GetHtml(); //var rrr = typeof(Func<Task>).GetConstructors(System.Reflection.BindingFlags.Default); //IServiceCollection serviceCollection = HttpContext.RequestServices.GetService(typeof(IServiceCollection)) as IServiceCollection; //testService.GetValueVoidAsync(id, null, new TestServiceParam //{ // Name = "asasdsad" //}); //return await testService.GetValueAsync(id, "asdasd"); //await testService.PostValueForm2Async(id, "", new TestServiceParam //{ // Name = "testName" //}, new TestServiceParam //{ // Name = "name" //}); //testService.GetValueVoid(id, new TestServiceParam //{ // Name = "testName" //}, new TestServiceParam //{ // Name = "name" //}); //await testService.PostValueAsync(); //await testService.PostValueAsync(id, "", new TestServiceParam()); return(testService.GetQueryResultValue(id.ToString(), new TestServiceParam { Name = "asasdsad" })); return(await testService.GetQueryResultValueAsync(id.ToString(), new TestServiceParam { Name = "asasdsad" })); testService.GetValueVoidAsync(id, "", null); return("ok"); }
public TestService2B(ITestService1 nested) { this.NestedService = nested; }
public WeatherForecastController(ILogger <WeatherForecastController> logger, ITestService1 testService1, ITestService2 testService2) { _logger = logger; _testService1 = testService1; _testService2 = testService2; }
public void Initialize(ITestService1 testService1) => _testService1 = testService1;