// //테스트를 작성할 때 다음 추가 특성을 사용할 수 있습니다. // //ClassInitialize를 사용하여 클래스의 첫 번째 테스트를 실행하기 전에 코드를 실행합니다. //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //ClassCleanup을 사용하여 클래스의 테스트를 모두 실행한 후에 코드를 실행합니다. //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //TestInitialize를 사용하여 각 테스트를 실행하기 전에 코드를 실행합니다. //[TestInitialize()] //public void MyTestInitialize() //{ //} // //TestCleanup을 사용하여 각 테스트를 실행한 후에 코드를 실행합니다. //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion static public void TestValue <T>(T expectedValue) { PromiseTest.TestFulfilled <T>(default(T), internalPromise => { internalPromise.Then( result => expectedValue ).Then( result => { Assert.AreEqual(expectedValue, result); } ); } ); PromiseTest.TestRejected <T>(new Exception(), internalPromise => { internalPromise.Catch( (exception) => { return(expectedValue); } ).Then( result => { Assert.AreEqual(expectedValue, result); } ); } ); }
public void SecondOnfulfillCallTest() { var expectedResult = new object(); object sentResult = null; PromiseTest.TestFulfilled <object>(expectedResult, promise => { promise.Then( null ).Then( (result) => { sentResult = result; } ); }); SetTimeout(() => Assert.AreEqual(expectedResult, sentResult), 50); }
public void ThrowExceptionInHandlerMakeRejectedTest() { Exception sentException = null; PromiseTest.TestFulfilled <object>(new object(), promise => { object thenPromise = null; thenPromise = promise.Then( result => thenPromise ); ((Promise)thenPromise).Then( null, (exception) => { sentException = exception; } ); }); SetTimeout(() => Assert.AreEqual("Type error. The resolved result is same as the promise.", sentException.Message), 50); sentException = null; PromiseTest.TestRejected <object>(new Exception(), promise => { object thenPromise = null; thenPromise = promise.Then(null, exception => thenPromise ); ((Promise)thenPromise).Then( null, (exception) => { sentException = exception; } ); }); SetTimeout(() => Assert.AreEqual("Type error. The resolved result is same as the promise.", sentException.Message), 50); }
public void SecondOnRejectCallTest() { var expectedException = new Exception(); Exception sentException = null; PromiseTest.TestRejected <object>(expectedException, promise => { promise.Then( null, null ).Then( null, (exception) => { sentException = exception; } ); }); SetTimeout(() => Assert.AreEqual(expectedException, sentException), 50); }
public void ThrowExceptionInHandlerMakeRejectedTest() { var expectedException = new Exception(); Exception sentException = null; PromiseTest.TestFulfilled <object>(new object(), promise => { promise.Then( result => { throw expectedException; } ).Then( null, (exception) => { sentException = exception; } ); }); SetTimeout(() => Assert.AreEqual(expectedException, sentException), 50); sentException = null; PromiseTest.TestRejected <object>(new Exception(), promise => { promise.Then(null, exception => { throw expectedException; } ).Then( null, (exception) => { sentException = exception; } ); }); SetTimeout(() => Assert.AreEqual(expectedException, sentException), 50); }
// //테스트를 작성할 때 다음 추가 특성을 사용할 수 있습니다. // //ClassInitialize를 사용하여 클래스의 첫 번째 테스트를 실행하기 전에 코드를 실행합니다. //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //ClassCleanup을 사용하여 클래스의 테스트를 모두 실행한 후에 코드를 실행합니다. //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //TestInitialize를 사용하여 각 테스트를 실행하기 전에 코드를 실행합니다. //[TestInitialize()] //public void MyTestInitialize() //{ //} // //TestCleanup을 사용하여 각 테스트를 실행한 후에 코드를 실행합니다. //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion static public void TestPromiseResolution <T>(T resolveObj, Func <object> factory, Action <Promise <T> > test) { PromiseTest.TestFulfilled <T>(resolveObj, internalPromise => { internalPromise.Then(result => factory()); test(internalPromise); } ); PromiseTest.TestRejected <T>(new Exception(), internalPromise => { internalPromise.Catch( (exception) => { return(factory()); } ); test(internalPromise); } ); }