Пример #1
0
        public void execute_logs_any_error_raised_by_the_inner_action()
        {
            var waitHandle    = new ManualResetEventSlim();
            var logger        = new LoggerMock(MockBehavior.Loose);
            var loggerService = new LoggerServiceMock(MockBehavior.Loose);
            var action        = new ActionMock(MockBehavior.Loose);

            logger
            .When(x => x.Log(LogLevel.Error, It.IsAny <string>()))
            .Do(waitHandle.Set);

            loggerService
            .When(x => x.GetLogger(It.IsAny <Type>()))
            .Return(logger);

            action
            .When(x => x.Execute(It.IsAny <ExecutionContext>()))
            .Return(Observable.Throw <Unit>(new InvalidOperationException("Something bad happened")));

            var sut = new DoNotAwaitActionBuilder()
                      .WithLoggerService(loggerService)
                      .WithInnerAction(action)
                      .Build();

            sut.Execute(new ExecutionContext());

            Assert.True(waitHandle.Wait(TimeSpan.FromSeconds(3)));
        }
Пример #2
0
        public async Task save_async_logs_an_error_if_a_save_callback_fails()
        {
            var logger        = new LoggerMock(MockBehavior.Loose);
            var loggerService = new LoggerServiceMock(MockBehavior.Loose);

            loggerService.When(x => x.GetLogger(typeof(StateService))).Return(logger);
            var service = new StateService(new BlobCacheMock(), loggerService);

            service.RegisterSaveCallback(_ => Task.Run(() => throw new Exce
                                                       ))
        }
        public void save_async_ignores_any_null_tasks_returned_by_saved_callbacks()
        {
            var logger        = new LoggerMock(MockBehavior.Loose);
            var loggerService = new LoggerServiceMock(MockBehavior.Loose);

            loggerService
            .When(x => x.GetLogger(typeof(StateService)))
            .Return(logger);

            var sut = new StateServiceBuilder()
                      .WithLoggerService(loggerService)
                      .Build();

            var firstExecuted  = false;
            var secondExecuted = false;

            sut
            .RegisterSaveCallback(
                _ =>
            {
                firstExecuted = true;
                return(Observable.Return(Unit.Default));
            });
            sut.RegisterSaveCallback(_ => null);
            sut
            .RegisterSaveCallback(
                _ =>
            {
                secondExecuted = true;
                return(Observable.Return(Unit.Default));
            });

            sut.SaveAsync();

            Assert.True(firstExecuted);
            Assert.True(secondExecuted);

            loggerService
            .Verify(x => x.GetLogger(typeof(StateService)))
            .WasCalledExactlyOnce();

            logger
            .Verify(x => x.Error(It.IsAny <string>()))
            .WasNotCalled();

            logger
            .Verify(x => x.Error(It.IsAny <string>(), It.IsAny <object[]>()))
            .WasNotCalled();

            logger
            .Verify(x => x.Error(It.IsAny <Exception>(), It.IsAny <string>(), It.IsAny <object[]>()))
            .WasNotCalled();
        }
Пример #4
0
        public void save_logs_an_error_if_a_save_callback_fails()
        {
            var logger        = new LoggerMock(MockBehavior.Loose);
            var loggerService = new LoggerServiceMock(MockBehavior.Loose);

            loggerService
            .When(x => x.GetLogger(typeof(StateService)))
            .Return(logger);

            var sut = new StateServiceBuilder()
                      .WithLoggerService(loggerService)
                      .Build();

            sut.RegisterSaveCallback(_ => Observable.Throw <Unit>(new Exception("whatever")));

            sut.Save().Subscribe();

            logger
            .Verify(x => x.Log(LogLevel.Error, It.IsAny <string>()))
            .WasCalledExactlyOnce();
        }
Пример #5
0
        public async Task save_async_ignores_any_null_tasks_returned_by_saved_callbacks()
        {
            var logger        = new LoggerMock(MockBehavior.Loose);
            var loggerService = new LoggerServiceMock(MockBehavior.Loose);

            loggerService.When(x => x.GetLogger(typeof(StateService))).Return(logger);
            var service        = new StateService(new BlobCacheMock(), loggerService);
            var firstExecuted  = false;
            var secondExecuted = false;

            service.RegisterSaveCallback(_ => Task.Run(() => firstExecuted = true));
            service.RegisterSaveCallback(_ => null);
            service.RegisterSaveCallback(_ => Task.Run(() => secondExecuted = true));

            await service.SaveAsync();

            Assert.True(firstExecuted);
            Assert.True(secondExecuted);
            loggerService.Verify(x => x.GetLogger(typeof(StateService))).WasCalledExactlyOnce();
            logger.Verify(x => x.Error(It.IsAny <string>())).WasNotCalled();
            logger.Verify(x => x.Error(It.IsAny <string>(), It.IsAny <object[]>())).WasNotCalled();
            logger.Verify(x => x.Error(It.IsAny <Exception>(), It.IsAny <string>(), It.IsAny <object[]>())).WasNotCalled();
        }