public void TimeSpanComponent_Dispose() { using var t = new TestComponent(TimeSpan.FromMilliseconds(500), this.Logger); t.Initialize(); t.Dispose(); Assert.IsTrue(t.IsDisposed); t.Initialize(); }
public void Dispose_RemovesEventListenersForBindings() { var viewModel = new TestViewModel(); var serviceProvider = new Mock <IServiceProvider>(); var wemf = new Mock <IWeakEventManagerFactory>(); var wem = new Mock <IWeakEventManager>(); var bindingFactory = new Mock <IBindingFactory>(); var binding = new Mock <IBinding>(); serviceProvider.Setup(x => x.GetService(typeof(IWeakEventManagerFactory))).Returns(wemf.Object) .Verifiable(); serviceProvider.Setup(x => x.GetService(typeof(IBindingFactory))).Returns(bindingFactory.Object) .Verifiable(); wemf.Setup(x => x.Create()).Returns(wem.Object).Verifiable(); wem.Setup(x => x.AddWeakEventListener(It.IsAny <IBinding>(), nameof(IBinding.BindingValueChanged), It.IsAny <Action <IBinding, EventArgs> >())).Verifiable(); wem.Setup(x => x.RemoveWeakEventListener(It.IsAny <IBinding>())).Verifiable(); bindingFactory.Setup(x => x.Create(It.IsAny <INotifyPropertyChanged>(), It.IsAny <PropertyInfo>(), It.IsAny <IWeakEventManager>())).Returns(binding.Object).Verifiable(); binding.Setup(x => x.GetValue()).Returns("Test").Verifiable(); binding.Setup(x => x.Initialize()).Verifiable(); binding.Setup(x => x.Dispose()).Verifiable(); var component = new TestComponent(serviceProvider.Object); component.AddBinding(viewModel, x => x.TestProperty); component.Dispose(); serviceProvider.Verify(); wemf.Verify(); bindingFactory.Verify(); binding.Verify(); wem.Verify(); serviceProvider.VerifyNoOtherCalls(); wemf.VerifyNoOtherCalls(); bindingFactory.VerifyNoOtherCalls(); binding.VerifyNoOtherCalls(); wem.VerifyNoOtherCalls(); }
public void TimeSpanComponent_Usage() { using var t = new TestComponent(TimeSpan.FromMilliseconds(500), this.Logger); Assert.AreEqual(0, t.Count); Assert.IsFalse(t.IsInitialized); Assert.IsFalse(t.IsDisposed); t.Initialize(); Assert.AreEqual(1, t.Count); Assert.IsTrue(t.IsInitialized); t.Initialize(); Assert.AreEqual(1, t.Count); Thread.Sleep(1000); Assert.AreEqual(1, t.Count); t.Initialize(); Assert.AreEqual(2, t.Count); Assert.IsTrue(t.IsInitialized); t.Initialize(); Assert.AreEqual(2, t.Count); Thread.Sleep(2000); Assert.AreEqual(2, t.Count); t.Initialize(); Assert.AreEqual(3, t.Count); t.Initialize(); t.Dispose(); Assert.IsTrue(t.IsDisposed); }