コード例 #1
0
        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();
        }
コード例 #2
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();
        }