public async Task CanOnlyAddOneComponentTest() { Resolver resolver = Mocks.GetResolver(); resolver.Builder.RegisterType <OnlyOneComponent>().As <IOnlyOneComponent>(); resolver.Build(); for (int i = 0; i < 100; i++) { OnlyOneComponent.LastID = 0; AGSEmptyEntity entity = new AGSEmptyEntity("Test" + Guid.NewGuid(), resolver); List <Task> tasks = new List <Task>(); for (int j = 0; j < 10; j++) { tasks.Add(Task.Run(() => entity.AddComponent <IOnlyOneComponent>())); } await Task.WhenAll(tasks); var component = entity.AddComponent <IOnlyOneComponent>(); component.AssertOne(); } }
public void BindingCalledForExplicitTypeAlreadyAdded() { AGSEmptyEntity entity = new AGSEmptyEntity("test", Mocks.GetResolver()); AGSCropSelfComponent crop = new AGSCropSelfComponent(); entity.AddComponent <ICropSelfComponent>(crop); bool bindingCalled = false; entity.Bind <ICropSelfComponent>(c => { Assert.AreSame(crop, c); bindingCalled = true; }, _ => Assert.Fail("Component was somehow removed")); Assert.IsTrue(bindingCalled); }
public void BindingCalledForExplicitType() { AGSEmptyEntity entity = new AGSEmptyEntity("test", Mocks.GetResolver()); AGSCropSelfComponent crop = new AGSCropSelfComponent(); bool bindingCalled = false; entity.Bind <ICropSelfComponent>(c => { Assert.AreSame(crop, c); bindingCalled = true; }, _ => {}); Assert.IsFalse(bindingCalled); entity.AddComponent <ICropSelfComponent>(crop); Assert.IsTrue(bindingCalled); }