public void Sailor_method_should_return_a_Sailor_instance() { ISailor s = A.Sailor(); //Sailor method should return a Sailor instance Assert.True(s.GetType().IsAssignableFrom(typeof(Sailor))); }
public void Sailor_method_should_return_a_new_Sailor_instance_every_call() { ISailor s = A.Sailor(); ISailor s1 = A.Sailor(); //Sailor method should return a Sailor instance Assert.False(Object.ReferenceEquals(s, s1)); }
public void Value_get_should_return_the_correct_value_if_state_is_fulfilled() { ISailor s = A.Sailor(); IPromise promise = s.Promise; s.Resolve(3); //a fulfilled promise value should return the parameter passed to the Sailor.Fulfill method Assert.Equal(3, (int)s.Promise.Value); }
public void Reason_get_should_return_throw_if_state_is_fulfilled() { ISailor s = A.Sailor(); IPromise promise = s.Promise; s.Resolve(50); //a fulfilled promise value should remain null var ex = Assert.Throws(typeof(InvalidOperationException), new Assert.ThrowsDelegateWithReturn(() => { return(s.Promise.Reason); })); Assert.NotNull(ex); }
public void Reason_get_should_return_the_reason_why_a_promise_has_been_rejected_if_state_is_rejected() { ISailor s = A.Sailor(); IPromise promise = s.Promise; Exception exc = new Exception("Exception"); s.Reject(exc); //a rejected promise reason should return the exception passed to the Sailor.Reject method Assert.Equal(exc, s.Promise.Reason); }
public IPromise Run() { ISailor sailor = A.Sailor(); new Thread( delegate() { try { while (true) { //My long execution... Thread.Sleep(1000); sailor.Notify("Something happened"); } } catch (Exception exception) { sailor.Reject(exception); } finally { sailor.Finally(); } } ).Start(); return(sailor.Promise); }