public void Without_IoC_Tecture_Choses_Parameterless_Constructor() { var tb = new TectureBuilder(); var tecture = tb.Build(); tecture.Let <TestService1>().Action(); }
public void Trace_Can_Describe_Default_Commands() { var tb = new TectureBuilder(); var tecture = tb.Build(); tecture.BeginTrace(); tecture.Let <Service2>().Action(); tecture.Save(); var trace = tecture.EndTrace(); var explanation = trace.Explain(); const string expectedExplanation = @" 1. [ { ] Test Cycle 2. [// ] Test 3. [ + ] Loop iteration 4. [// ] Test 5. [ + ] Loop iteration 6. [// ] Test 7. [ + ] Loop iteration 8. [ } ] Test Cycle 9. [ <-] Save 10. [// ] <<< Finally block >>> 11. [// ] <<< End of Finally block >>> 12. [ ! ] End "; Assert.Equal(expectedExplanation, explanation); }
public void Tecture_Calls_Dispose_On_All_Services_When_Being_Disposed_Itself() { var tb = new TectureBuilder(); using (var tecture = tb.Build()) { tecture.Let <DisposeService>().Action(); } Assert.Equal(1, DisposeService.Disposed); }
public void Tecture_Ensures_Single_Instance_Of_Services() { var tb = new TectureBuilder(); using (var tecture = tb.Build()) { var s1 = tecture.Let <SaveFinallyService>(); var s2 = tecture.Let <SaveFinallyService>(); Assert.True(object.ReferenceEquals(s1, s2)); } }
public void Tecture_Calls_Init_Exactly_Once_For_Each_Service_In_Instance() { var tb = new TectureBuilder(); using (var tecture = tb.Build()) { tecture.Let <InitService>().Action(); tecture.Let <InitService>().Action(); } Assert.Equal(1, InitService.Initialized); }
public void Service_Must_Contain_AtLeast_One_Private_Constructor() { var tb = new TectureBuilder(); var tecture = tb.Build(); Assert.Throws <MissingMethodException>(() => { tecture.Let <TestService1>().Action(); }); tecture.Let <TestService2>().Action(); }
private ITecture Configure() { var tb = new TectureBuilder(); CommandAspect = new Aspect101.Command(); tb.WithChannel <Test>(x => { x.ForCommand(CommandAspect); x.ForQuery(new Aspect101.Query()); }); tb.WithExceptionHandler(e => true); return(tb.Build()); }
public void General_Tecture_Setup_Test() { var tb = new TectureBuilder(); tb.WithChannel <Test>(x => { x.ForCommand(new Aspect101.Command()); x.ForQuery(new Aspect101.Query()); }); var tecture = tb.Build(); tecture.Let <Service>().Action(); tecture.Save(); }
public void Comment_Command_Works() { var tb = new TectureBuilder(); var tecture = tb.Build(); tecture.BeginTrace(); tecture.Let <Service>().Action(); tecture.Save(); var trace = tecture.EndTrace(); Assert.Equal(5, trace.All.Count()); var cmd = trace.All.FirstOrDefault() as Comment; Assert.NotNull(cmd); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddTransient <ToyFactoryDbContext>(); services.AddTransient(sp => { ILazyDisposable <ToyFactoryDbContext> ld = new LazyDisposable <ToyFactoryDbContext>(() => sp.GetService <ToyFactoryDbContext>()); var tb = new TectureBuilder(); tb.WithChannel <Db>(c => { c.UseEfCoreOrm(ld); c.UseEfCoreDirectSql(ld); }); return(tb.Build()); }); }
public void Tecture_Returns_Specified_Query_Aspect_On_Aspect_Call() { var tb = new TectureBuilder(); var commandAspect = new Aspect101.Command(); var queryAspect = new Aspect101.Query(); tb.WithChannel <Test>(x => { x.ForCommand(commandAspect); x.ForQuery(queryAspect); }); var tecture = tb.Build(); Assert.Equal(commandAspect, tecture.Let <Service2>().GetTestCommandAspect()); Assert.Equal(commandAspect, tecture.Let <Service2>().GetTestCommandAspect()); Assert.Equal(queryAspect, tecture.Let <Service2>().GetTestQueryAspect()); Assert.Equal(queryAspect, tecture.Let <Service2>().GetTestQueryAspect()); }
public void Tecture_Calls_OnSave_Every_Save_And_Calls_Finally_When_SaveChain_Ends() { var tb = new TectureBuilder(); SaveFinallyService sfs = null; using (var tecture = tb.Build()) { sfs = tecture.Let <SaveFinallyService>(); tecture.Let <SaveFinallyService>().Action(); tecture.Save(); tecture.Let <SaveFinallyService>().Action(); tecture.Save(); } Assert.Equal(4, sfs.Counter); Assert.Equal(2, sfs.SaveCount); Assert.Equal(2, sfs.FinallyCount); // and does not call async saves! Assert.Equal(0, sfs.SaveAsyncCount); Assert.Equal(0, sfs.FinallyAsyncCount); }
public void IoC_Resolver_Works_As_Expected() { var tb = new TectureBuilder(); var dependencyMock = new Mock <TestService1.IDependency>(); tb.WithIoc(x => { if (x == typeof(TestService1.IDependency)) { return(dependencyMock.Object); } throw new XunitException("Invalid type provided for IoC call"); }); var tecture = tb.Build(); tecture.Let <TestService1>().Action(); dependencyMock.Verify(x => x.Action(), Times.Once); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddTransient <ToyFactoryDbContext>(); services.AddTransient(sp => { var ld = new LazyDisposable <ToyFactoryDbContext>(() => { var dc = sp.GetService <ToyFactoryDbContext>(); dc.ChangeTracker.AutoDetectChangesEnabled = false; return(dc); }); var tb = new TectureBuilder(); tb.WithChannel <Db>(c => { c.UseEfCoreOrm(ld); c.UseEfCoreDirectSql(ld); }); return(tb.Build()); }); }
public async Task Tecture_Invokes_Save_For_Commands_Enqueued_ASYNC() { var tb = new TectureBuilder(); var commandAspect = new Aspect101.Command(); tb.WithChannel <Test>(x => { x.ForCommand(commandAspect); x.ForQuery(new Aspect101.Query()); }); var tecture = tb.Build(); const string parameter = "AAA"; tecture.Let <Service>().Action(parameter); await tecture.SaveAsync(); Assert.NotNull(commandAspect.TestRunnerInstance); Assert.Single(commandAspect.TestRunnerInstance.CommandsRunAsync); Assert.Empty(commandAspect.TestRunnerInstance.CommandsRun); Assert.Equal(parameter, commandAspect.TestRunnerInstance.CommandsRunAsync[0].Payload); }
public void Tecture_Tries_To_Find_Appropriate_Constructor_For_IoC() { { var tb = new TectureBuilder(); var dependency1Mock = new Mock <TestService2.IDependency1>(); tb.WithIoc(x => { if (x == typeof(TestService2.IDependency1)) { return(dependency1Mock.Object); } throw new XunitException("Invalid type provided for IoC call"); }); var tecture = tb.Build(); tecture.Let <TestService2>().Action(); dependency1Mock.Verify(x => x.Action(), Times.Once); } { var tb = new TectureBuilder(); var dependency2Mock = new Mock <TestService2.IDependency2>(); tb.WithIoc(x => { if (x == typeof(TestService2.IDependency2)) { return(dependency2Mock.Object); } throw new XunitException("Invalid type provided for IoC call"); }); var tecture = tb.Build(); tecture.Let <TestService2>().Action(); dependency2Mock.Verify(x => x.Action(), Times.Once); } { var tb = new TectureBuilder(); var dependency1Mock = new Mock <TestService2.IDependency1>(); var dependency2Mock = new Mock <TestService2.IDependency2>(); tb.WithIoc(x => { if (x == typeof(TestService2.IDependency1)) { return(dependency1Mock.Object); } if (x == typeof(TestService2.IDependency2)) { return(dependency2Mock.Object); } throw new XunitException("Invalid type provided for IoC call"); }); var tecture = tb.Build(); tecture.Let <TestService2>().Action(); dependency1Mock.Verify(x => x.Action(), Times.Once); dependency2Mock.Verify(x => x.Action(), Times.Once); } }