/// <summary> /// Initializes a new instance of the <see cref="Mock{T}"/> class. /// </summary> internal Mock(ActorExecutionContext.Mock context, T value) : base(value) { this.Context = context; this.RegisterActor = context.CreateActor(typeof(SharedRegisterActor <T>)); context.SendEvent(this.RegisterActor, SharedRegisterEvent.SetEvent(value)); }
/// <summary> /// Initializes a new instance of the <see cref="Mock{T}"/> class. /// </summary> internal Mock(ControlledRuntime runtime, T value) : base(value) { this.Runtime = runtime; this.RegisterActor = this.Runtime.CreateActor(typeof(SharedRegisterActor <T>)); this.Runtime.SendEvent(this.RegisterActor, SharedRegisterEvent.SetEvent(value)); }
/// <summary> /// Gets current value of the register. /// </summary> public override T GetValue() { var op = this.Context.Runtime.GetExecutingOperation <ActorOperation>(); this.Context.SendEvent(this.RegisterActor, SharedRegisterEvent.GetEvent(op.Actor.Id)); var e = op.Actor.ReceiveEventAsync(typeof(SharedRegisterResponseEvent <T>)).Result as SharedRegisterResponseEvent <T>; return(e.Value); }
/// <summary> /// Reads and updates the register. /// </summary> public override T Update(Func <T, T> func) { var op = this.Context.Scheduler.GetExecutingOperation <ActorOperation>(); this.Context.SendEvent(this.RegisterActor, SharedRegisterEvent.UpdateEvent(func, op.Actor.Id)); var e = op.Actor.ReceiveEventAsync(typeof(SharedRegisterResponseEvent <T>)).Result as SharedRegisterResponseEvent <T>; return(e.Value); }
/// <summary> /// Sets current value of the register. /// </summary> public override void SetValue(T value) { this.Context.SendEvent(this.RegisterActor, SharedRegisterEvent.SetEvent(value)); }