コード例 #1
0
        public async Task TestThatStorageExceptionsAreRetried()
        {
            var fetchUpdateSessionStatusStub = StubsUtils.Sequence <Func <Task <UpdateSessionStatus> > >()
                                               .Once(() => AsyncUtils.AsyncTaskThatThrows <UpdateSessionStatus>(new StorageException()))
                                               .Once(() => Task.FromResult(new UpdateSessionStatus(Enumerable.Empty <UpdateDomainEntity>(), null, null)));

            IUpdateSessionTable updateSessionTableStub = new StubIUpdateSessionTable()
                                                         .FetchUpdateSessionStatus((superClusterId) => fetchUpdateSessionStatusStub.Next())
                                                         .TryExecuteTransaction(transaction => Task.FromResult(true))
                                                         .DeleteInstanceEntity((superClusterId, instanceId) => Task.FromResult(true))
                                                         .GetActiveUpdateDomain((superClusterId) => Task.FromResult("1"));

            ContainerBuilder builder = AzureStorageUpdateSessionDiModule.RegisterTypes("superClusterId", "superClusterId",
                                                                                       "instanceId", "1", EmulatorConnectionString, Ttl);

            builder.RegisterInstance(updateSessionTableStub);
            IUpdateSessionManager updateSessionManager = new AzureStorageUpdateSessionDiModule(builder.Build())
                                                         .UpdateSessionManager;

            Assert.True(await updateSessionManager.TryStartUpdateSession());

            await updateSessionManager.EndUpdateSession();

            Assert.Equal(2, fetchUpdateSessionStatusStub.CallCount);
        }