Exemple #1
0
        public void ShouldDispatchAction()
        {
            var store = new MockStore(new MockState(k_MockStateDefault));

            store.Register <PassThroughAction>(MockReducers.PassThrough);
            store.Register <ChangeFooAction>(MockReducers.ReplaceFoo);
            store.Register <ChangeBarAction>(MockReducers.ReplaceBar);

            store.Dispatch(new ChangeFooAction(10));
            Assert.That(store.GetState().Foo, Is.EqualTo(10));
            Assert.That(store.GetState().Bar, Is.EqualTo(k_MockStateDefault));

            store.Dispatch(new ChangeFooAction(20));
            Assert.That(store.GetState().Foo, Is.EqualTo(20));
            Assert.That(store.GetState().Bar, Is.EqualTo(k_MockStateDefault));

            store.Dispatch(new ChangeBarAction(15));
            Assert.That(store.GetState().Foo, Is.EqualTo(20));
            Assert.That(store.GetState().Bar, Is.EqualTo(15));

            store.Dispatch(new ChangeBarAction(30));
            Assert.That(store.GetState().Foo, Is.EqualTo(20));
            Assert.That(store.GetState().Bar, Is.EqualTo(30));

            store.Dispatch(new PassThroughAction());
            Assert.That(store.GetState().Foo, Is.EqualTo(20));
            Assert.That(store.GetState().Bar, Is.EqualTo(30));
        }
Exemple #2
0
        public void GetStateShouldReturnInitialState()
        {
            var store = new MockStore(new MockState(k_MockStateDefault));

            Assert.That(store.GetState().Foo, Is.EqualTo(k_MockStateDefault));
            Assert.That(store.GetState().Bar, Is.EqualTo(k_MockStateDefault));
        }
Exemple #3
0
        public async Task FetchTilesRequest_FakeHttpClient()
        {
            // Arrange
            var request  = new TilesState.FetchTilesRequest();
            var response = "<head><meta property=\"og:title\" content=\"Microsoft launches Spend iOS app that automatically tracks and matches expenses\" />";

            response += "<meta property=\"og:image\" content=\"image\" />";
            response += "<meta property=\"og:description\" content=\"description\" /></head>";
            var mockStore = new MockStore();

            mockStore.SetState(new TilesState());
            var handler = new FetchTilesHandler(mockStore, Pocket(), TileMakerClient(response), GetPocketIOptions());

            // Act
            var result = await handler.Handle(request, CancellationToken.None);

            // Assert
            result.Should().NotBeNull();

            var state = mockStore.GetState <TilesState>();

            state.OriginalTiles.Should().NotBeNullOrEmpty();
            var first = state.OriginalTiles.First();

            first.Title.Should().NotBeNullOrWhiteSpace();
            first.Title.Should().Be("Microsoft launches Spend iOS app that automatically tracks and matches expenses");

            TestConsole.WriteLine(first.Title);
        }
Exemple #4
0
        public async Task IncrementCounterRequest_AmountDefined()
        {
            // Arrange
            var amount  = 7;
            var request = new CounterState.IncrementCounterRequest {
                Amount = amount
            };
            var mockStore = new MockStore();

            mockStore.SetState(new CounterState());
            var handler      = new CounterState.IncrementCounterHandler(mockStore);
            var initialCount = mockStore.GetState <CounterState>().Count;

            // Act
            var result = await handler.Handle(request, CancellationToken.None);

            // Assert
            result.Should().NotBeNull();
            var state = mockStore.GetState <CounterState>();

            state.Count.Should().Be(initialCount + amount);
        }
Exemple #5
0
        public void RegisteringDoesNotChangeState()
        {
            var observer = new MockObserver();
            var store    = new MockStore(new MockState(k_MockStateDefault));

            store.Register(observer.Observe);

            store.Register <PassThroughAction>(MockReducers.PassThrough);
            store.Register <ChangeFooAction>(MockReducers.ReplaceFoo);
            store.Register <ChangeBarAction>(MockReducers.ReplaceBar);

            Assert.That(store.GetState().Foo, Is.EqualTo(k_MockStateDefault));
            store.Unregister(observer.Observe);
        }
Exemple #6
0
        public async Task FetchTilesRequest_RealHttpClient()
        {
            // Arrange
            var request   = new TilesState.FetchTilesRequest();
            var mockStore = new MockStore();

            mockStore.SetState(new TilesState());
            var handler = new FetchTilesHandler(mockStore, Pocket(), RealTileMakerClient(), GetPocketIOptions());

            // Act
            var result = await handler.Handle(request, CancellationToken.None);

            // Assert
            result.Should().NotBeNull();
            var state = mockStore.GetState <TilesState>();

            state.OriginalTiles.Should().NotBeNullOrEmpty();

            foreach (var tile in state.OriginalTiles)
            {
                TestConsole.WriteLine(tile.Title);
            }
        }