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));
        }
        public void TestRestEntityRefresh()
        {
            var dataContextMock = new Mock<IMediaDataServiceContext>();

            var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed);
            var fakeResponse = new[] {new StreamingEndpointData {Name = "test"}};
            int exceptionCount = 2;

            dataContextMock.Setup((ctxt) => ctxt
                .Execute<StreamingEndpointData>(It.IsAny<Uri>()))
                .Returns(() =>
                {
                    if (--exceptionCount > 0) throw fakeException;
                    return fakeResponse;
                });

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

            var target = new TestRestEntity(_mediaContext);

            target.Refresh();

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