public void PropertiesCanBeSetConcurrentlyWithObjectCreation() { const int personsPerThread = 50; const int threadAmount = 10; var threads = new Thread[threadAmount]; var allViewModels = new TestViewModel[threadAmount][]; for (int i = 0; i < threadAmount; i++) { threads[i] = new Thread((index) => { var localViewModels = new TestViewModel[personsPerThread]; for (int j = 0; j < personsPerThread; j++) { var viewModel = new TestViewModel(); viewModel.Age = 18; viewModel.Age = 19; localViewModels[j] = viewModel; } allViewModels[(int)index] = localViewModels; }); } for (int i = 0; i < threadAmount; i++) { threads[i].Start(i); } for (int i = 0; i < threadAmount; i++) { threads[i].Join(); } var flatenSortedIdentifiers = allViewModels .SelectMany(o => o) .Select(o => o.UniqueIdentifier) .OrderBy(o => o) .ToArray(); var firstId = flatenSortedIdentifiers[0]; Assert.That(flatenSortedIdentifiers, Is.EquivalentTo(Enumerable.Range(firstId, personsPerThread * threadAmount))); }
public async Task CloseAfterCloseProtection() { var auditor = new TestAuditor(); AuditingManager.RegisterAuditor(auditor); var vm = new TestViewModel(); Assert.AreEqual(false, auditor.OnViewModelClosedCalled); await vm.CloseViewModelAsync(null); Assert.AreEqual(true, auditor.OnViewModelClosedCalled); auditor.OnViewModelClosedCalled = false; await vm.CloseViewModelAsync(null); Assert.AreEqual(false, auditor.OnViewModelClosedCalled); }
public async Task IsNotDirtyAtStartupAsync() { var vm = new TestViewModel(); Assert.IsFalse(vm.IsDirty); }