Ejemplo n.º 1
0
        public void TestRestEntitySendOperation()
        {
            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.SendOperationTest();
            }
            catch (NotImplementedException x)
            {
                Assert.AreEqual(TestMediaDataServiceResponse.TestMediaDataServiceResponseExceptionMessage, x.Message);
            }

            dataContextMock.Verify((ctxt) => ctxt.Execute(It.IsAny <Uri>(), "POST"), Times.Exactly(2));
        }
Ejemplo n.º 2
0
        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));
        }