Exemple #1
0
        public RestoreObservable(IElasticClient elasticClient, IRestoreRequest restoreRequest)
        {
            elasticClient.ThrowIfNull(nameof(elasticClient));
            restoreRequest.ThrowIfNull(nameof(restoreRequest));

            _elasticClient  = elasticClient;
            _restoreRequest = restoreRequest;

            _restoreStatusHumbleObject            = new RestoreStatusHumbleObject(elasticClient, restoreRequest);
            _restoreStatusHumbleObject.Completed += StopTimer;
            _restoreStatusHumbleObject.Error     += StopTimer;
        }
        public void OnCompleted_WhenRecoveredEqualsToTotalForAllFiles()
        {
            var elastickClientMock = ElastickClientMock(RecoveryStatusFixture("test", 1, 1));

            var sut = new RestoreStatusHumbleObject(elastickClientMock.Object,
                                                    RestoreRequestFixture());

            sut.Next      += (sender, args) => Assert.Fail();
            sut.Completed += (sender, args) => Assert.NotNull(args.RecoveryStatusResponse);
            sut.Error     += (sender, args) => Assert.Fail(args.Exception.Message);

            sut.CheckStatus();
        }
        public void OnNext_WhenRecoveredLessThanTotalForAllFiles()
        {
            var elastickClientMock = ElastickClientMock(RecoveryStatusFixture("test", 1, 2));

            var sut = new RestoreStatusHumbleObject(elastickClientMock.Object,
                                                    RestoreRequestFixture());

            sut.Next      += (sender, args) => Assert.AreEqual(1, args.RecoveryStatusResponse.Indices.Count);
            sut.Completed += (sender, args) => Assert.Fail("Can't complete");
            sut.Error     += (sender, args) => Assert.Fail(args.Exception.Message);

            sut.CheckStatus();
        }
        public void ShouldCallRecoveryStatus()
        {
            var elastickClientMock = new Mock <IElasticClient>();

            var sut = new RestoreStatusHumbleObject(elastickClientMock.Object,
                                                    RestoreRequestFixture());

            sut.CheckStatus();

            elastickClientMock.Verify(x => x
                                      .RecoveryStatus(
                                          It.Is <RecoveryStatusRequest>(
                                              request =>
                                              request.Indices.Count() == 1 &&
                                              request.Indices.ElementAt(0).Name == "test" &&
                                              request.Indices.ElementAt(0).Type == typeof(object) &&
                                              request.Detailed)),
                                      Times.AtLeastOnce);
        }
        public void RestoreResponseInvalid_Exception()
        {
            var elastickClientMock   = new Mock <IElasticClient>();
            var recoveryResponseMock = new Mock <IRecoveryStatusResponse>();

            recoveryResponseMock.Setup(x => x.IsValid).Returns(false);

            elastickClientMock.Setup(x => x.RecoveryStatus(It.IsAny <IRecoveryStatusRequest>()))
            .Returns(() => recoveryResponseMock.Object);

            var sut = new RestoreStatusHumbleObject(elastickClientMock.Object,
                                                    RestoreRequestFixture());

            sut.Next      += (sender, args) => Assert.Fail("");
            sut.Completed += (sender, args) => Assert.Fail("Can't complete");
            sut.Error     += (sender, args) =>
            {
                throw args.Exception;
            };

            sut.CheckStatus();
        }
        public void ShouldCallRecoveryStatus_Rename()
        {
            var elastickClientMock = new Mock <IElasticClient>();

            RestoreRequest restoreRequestFixture = RestoreRequestFixture("test_tmp");

            restoreRequestFixture.RenamePattern     = "_(.+)";
            restoreRequestFixture.RenameReplacement = "_restored_$1";

            var sut = new RestoreStatusHumbleObject(elastickClientMock.Object,
                                                    restoreRequestFixture);

            sut.CheckStatus();

            elastickClientMock.Verify(x => x
                                      .RecoveryStatus(
                                          It.Is <RecoveryStatusRequest>(
                                              request =>
                                              request.Indices.Count() == 1 &&
                                              request.Indices.ElementAt(0).Name == Regex.Replace("test_tmp", restoreRequestFixture.RenamePattern, restoreRequestFixture.RenameReplacement) &&
                                              request.Indices.ElementAt(0).Type == typeof(object) &&
                                              request.Detailed)),
                                      Times.AtLeastOnce);
        }