public void InitializingOperationWithoutNameGeneratesGuid() { var operation = new RecurringOperation(); Assert.IsTrue(!string.IsNullOrWhiteSpace(operation.GetName())); if (Guid.TryParseExact(operation.GetName(), null, out Guid guid)) { Assert.IsTrue(guid != Guid.Empty); } }
public void InitializingOperationWithNameDoesNotGenerateGuid() { string name = "Test operation"; var operation = new RecurringOperation(name); Assert.AreEqual(name, operation.GetName()); }
public void GetNameReturnsOperationName() { var name = "GetNameTest"; var operation = new RecurringOperation(name); Assert.IsTrue(operation.GetName().Equals(name)); }
public void OperationHasCorrectState() { // Assert state after initialization var operation = new RecurringOperation(); Assert.IsTrue(operation.IsInitialized); Assert.IsNotNull(operation.GetName()); Assert.IsTrue(operation.GetName().Length > 0); Assert.IsNotNull(operation.CanBeStarted); Assert.IsTrue(operation.CanBeStarted); Assert.IsNotNull(operation.IsRecurring); Assert.IsFalse(operation.IsRecurring); Assert.IsNotNull(operation.IsNotRecurring); Assert.IsTrue(operation.IsNotRecurring); Assert.IsNotNull(operation.IsExecuting); Assert.IsFalse(operation.IsExecuting); Assert.IsNotNull(operation.IsPaused); Assert.IsFalse(operation.IsPaused); Assert.IsNotNull(operation.IsIdle); Assert.IsTrue(operation.IsIdle); Assert.IsNotNull(operation.IsCancelled); Assert.IsFalse(operation.IsCancelled); Assert.IsNotNull(operation.IsNotCancelled); Assert.IsTrue(operation.IsNotCancelled); Assert.IsNotNull(operation.Status); Assert.IsTrue(operation.Status == RecurringOperationStatus.Idle); Assert.IsNull(operation.Exception); void DoWork() { Thread.Sleep(100); } // Start recurring RecurringOperationsManager.Instance.StartRecurring( operation, TimeSpan.FromSeconds(0.1), DoWork); // At this point the operation has not yet executed Assert.IsFalse(operation.CanBeStarted); Assert.IsTrue(operation.IsRecurring); Assert.IsFalse(operation.IsNotRecurring); Assert.IsFalse(operation.IsExecuting); Assert.IsFalse(operation.IsIdle); Assert.IsFalse(operation.IsPaused); Assert.IsFalse(operation.IsCancelled); Assert.IsTrue(operation.IsNotCancelled); // Wait for operation to start executing Thread.Sleep(125); // Assert state after starting execution Assert.IsFalse(operation.CanBeStarted); Assert.IsTrue(operation.IsRecurring); Assert.IsFalse(operation.IsNotRecurring); Assert.IsTrue(operation.IsExecuting); Assert.IsFalse(operation.IsIdle); Assert.IsFalse(operation.IsPaused); Assert.IsFalse(operation.IsCancelled); Assert.IsTrue(operation.IsNotCancelled); // Pause the operation RecurringOperationsManager.Instance.PauseRecurring(operation); Thread.Sleep(125); // Assert state after pausing Assert.IsFalse(operation.CanBeStarted); Assert.IsFalse(operation.IsRecurring); Assert.IsTrue(operation.IsNotRecurring); Assert.IsFalse(operation.IsExecuting); Assert.IsTrue(operation.IsIdle); Assert.IsTrue(operation.IsPaused); Assert.IsFalse(operation.IsCancelled); Assert.IsTrue(operation.IsNotCancelled); // Resume the operation RecurringOperationsManager.Instance.ResumeRecurring(operation); Thread.Sleep(125); // Assert state after resuming Assert.IsFalse(operation.CanBeStarted); Assert.IsTrue(operation.IsRecurring); Assert.IsFalse(operation.IsNotRecurring); Assert.IsTrue(operation.IsExecuting); Assert.IsFalse(operation.IsIdle); Assert.IsFalse(operation.IsPaused); Assert.IsFalse(operation.IsCancelled); Assert.IsTrue(operation.IsNotCancelled); // Cancel the operation RecurringOperationsManager.Instance.CancelRecurring(operation); // Assert state after cancelling Assert.IsTrue(operation.CanBeStarted); Assert.IsFalse(operation.IsRecurring); Assert.IsTrue(operation.IsNotRecurring); Assert.IsFalse(operation.IsExecuting); Assert.IsFalse(operation.IsIdle); Assert.IsFalse(operation.IsPaused); Assert.IsTrue(operation.IsCancelled); Assert.IsFalse(operation.IsNotCancelled); }