Example #1
0
        public void TestJobDeleteRetry()
        {
            var dataContextMock = new Mock <IMediaDataServiceContext>();

            int exceptionCount = 2;

            var job = new JobData {
                Name = "testData", Id = "id:someid"
            };
            var fakeResponse = new TestMediaDataServiceResponse {
                AsyncState = job
            };
            var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed);

            dataContextMock.Setup((ctxt) => ctxt.AttachTo("Jobs", job));
            dataContextMock.Setup((ctxt) => ctxt.DeleteObject(job));

            dataContextMock.Setup((ctxt) => ctxt
                                  .SaveChangesAsync(job))
            .Returns(() => Task.Factory.StartNew <IMediaDataServiceResponse>(() =>
            {
                if (--exceptionCount > 0)
                {
                    throw fakeException;
                }
                return(fakeResponse);
            }));

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

            job.SetMediaContext(_mediaContext);

            job.Delete();

            Assert.AreEqual(0, exceptionCount);
        }
        public void TestJobDeleteRetry()
        {
            var dataContextMock = new Mock<IMediaDataServiceContext>();

             int exceptionCount = 2;

             var job = new JobData { Name = "testData", Id = "id:someid" };
             var fakeResponse = new TestMediaDataServiceResponse { AsyncState = job };
             var fakeException = new WebException("test", WebExceptionStatus.ConnectionClosed);

             dataContextMock.Setup((ctxt) => ctxt.AttachTo("Jobs", job));
             dataContextMock.Setup((ctxt) => ctxt.DeleteObject(job));

             dataContextMock.Setup((ctxt) => ctxt
                 .SaveChangesAsync(job))
                 .Returns(() => Task.Factory.StartNew<IMediaDataServiceResponse>(() =>
                 {
                     if (--exceptionCount > 0) throw fakeException;
                     return fakeResponse;
                 }));

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

             job.SetMediaContext(_mediaContext);

             job.Delete();

             Assert.AreEqual(0, exceptionCount);
        }