public void WhenAddTraitTwiceShouldReplace() { // Arrange var container = new UnityContainer(); var parent = new StubObservableObject(); var collection = new ViewModelTraitCollection(parent, new TraitDependencyResolver(container)); // Act var b0 = collection.Add <StubViewModelTrait>(); b0.Id = "b0"; var b1 = collection.Add <StubViewModelTrait>(); b1.Id = "b1"; // Assert Assert.That(b0, Is.Not.Null); Assert.That(b1, Is.Not.Null); Assert.That(collection.Contains <StubViewModelTrait>(), Is.True); Assert.That(b0.IsDisposed, Is.True); Assert.That(b1.IsDisposed, Is.False); Assert.That(b1.Target, Is.EqualTo(parent)); }
public void WhenAddTrait_AndNullDependencyResolver_ShouldAdd() { // Arrange var container = new UnityContainer(); var parent = new StubObservableObject(); var collection = new ViewModelTraitCollection(parent, new NullTraitDependencyResolver()); // Act var b = collection.Add <StubViewModelTrait>(); // Assert Assert.That(b, Is.Null); Assert.That(collection.Contains <StubViewModelTrait>(), Is.False); }
public void WhenAddTraitShouldAdd() { // Arrange var container = new UnityContainer(); var parent = new StubObservableObject(); var collection = new ViewModelTraitCollection(parent, new TraitDependencyResolver(container)); // Act var b = collection.Add <StubViewModelTrait>(); // Assert Assert.That(b, Is.Not.Null); Assert.That(collection.Contains <StubViewModelTrait>(), Is.True); Assert.That(b.Target, Is.EqualTo(parent)); }
public void WhenDisposingParentShouldDispose() { // Arrange var container = new UnityContainer(); var parent = new MyObservableObject(); var collection = new ViewModelTraitCollection(parent, container); // Act var b0 = collection.Add <MyViewModelTrait>(); parent.Dispose(); // Assert Assert.That(b0.IsDisposed, Is.True); }
public void WhenAddBehaviourShouldAdd() { // Arrange var container = new UnityContainer(); var parent = new MyObservableObject(); var collection = new ViewModelTraitCollection(parent, container); // Act var b = collection.Add <MyViewModelTrait>(); // Assert Assert.That(b, Is.Not.Null); Assert.That(collection.Contains <MyViewModelTrait>(), Is.True); Assert.That(b.Target, Is.EqualTo(parent)); }
public void WhenDisposingParentShouldDispose() { // Arrange var container = new UnityContainer(); var parent = new StubObservableObject(); var collection = new ViewModelTraitCollection(parent, new TraitDependencyResolver(container)); var child = new StubDisposable(); // Act var b0 = collection.Add <StubViewModelTrait>(); child.DisposeWith(b0); parent.Dispose(); // Assert Assert.That(parent.IsDisposed, Is.True); Assert.That(b0.IsDisposed, Is.True); Assert.That(child.IsDisposed, Is.True); }
/// <summary> /// Adds the type of Trait to the <see cref="ViewModelTraitCollection"/>. This will be instantiated with the current /// dependency injection container and any dependencies of the Trait will be resolved and injected automatically. /// </summary> /// <typeparam name="T">The type of <see cref="IViewModelTrait"/> to add</typeparam> /// <returns>The <see cref="IViewModelTrait"/> instance</returns> public T WithTrait <T>() where T : IViewModelTrait { return(ViewModelTraits.Add <T>()); }