Пример #1
0
        public void TestRestEntityExecuteActionAsync()
        {
            var dataContextMock = new Mock <IMediaDataServiceContext>();

            var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed);

            int exceptionCount = 2;

            dataContextMock.Setup((ctxt) => ctxt
                                  .Execute(It.IsAny <Uri>(), "POST"))
            .Returns(() =>
            {
                if (--exceptionCount > 0)
                {
                    throw fakeException;
                }
                throw new NotImplementedException(TestMediaDataServiceResponse.TestMediaDataServiceResponseExceptionMessage);
            });

            _mediaContext.MediaServicesClassFactory = new TestMediaServicesClassFactory(dataContextMock.Object);

            var target = new TestRestEntity(_mediaContext);

            try
            {
                target.ExecuteActionAsyncTest();
            }
            catch (AggregateException ax)
            {
                NotImplementedException x = ax.InnerException as NotImplementedException;
                Assert.AreEqual(TestMediaDataServiceResponse.TestMediaDataServiceResponseExceptionMessage, x.Message);
            }

            dataContextMock.Verify((ctxt) => ctxt.Execute(It.IsAny <Uri>(), "POST"), Times.Exactly(2));
        }