Esempio n. 1
0
        public void ShouldShowStateChangesFromContext()
        {
            var haContextMock = new HaContextMock();

            var target = new NumericEntity(haContextMock.Object, "domain.testEntity");
            var stateChangeObserverMock    = new Mock <IObserver <NumericStateChange> >();
            var stateAllChangeObserverMock = new Mock <IObserver <NumericStateChange> >();

            target.StateAllChanges().Subscribe(stateAllChangeObserverMock.Object);
            target.StateChanges().Subscribe(stateChangeObserverMock.Object);

            haContextMock.StateAllChangeSubject.OnNext(new StateChange(target,
                                                                       old:  new EntityState {
                State = "1"
            },
                                                                       @new: new EntityState {
                State = "1"
            }));

            haContextMock.StateAllChangeSubject.OnNext(new StateChange(target,
                                                                       old:  new EntityState {
                State = "1"
            },
                                                                       @new: new EntityState {
                State = "2"
            }));

            stateChangeObserverMock.Verify(o => o.OnNext(It.Is <NumericStateChange>(e => e.New !.State !.Equals(1.0))), Times.Never);
            stateChangeObserverMock.Verify(o => o.OnNext(It.Is <NumericStateChange>(e => e.New !.State !.Equals(2.0))), Times.Once);

            stateAllChangeObserverMock.Verify(o => o.OnNext(It.Is <NumericStateChange>(e => e.Old !.State !.Equals(1.0))), Times.Exactly(2));
            stateAllChangeObserverMock.Verify(o => o.OnNext(It.IsAny <NumericStateChange>()), Times.Exactly(2));
        }
Esempio n. 2
0
    public void ShouldShowStateChangesFromContext()
    {
        var haContextMock = new HaContextMock();

        var entity = new Entity(haContextMock.Object, "domain.testEntity");
        var target = new NumericEntity(entity);

        haContextMock.Setup(m => m.GetState(entity.EntityId)).Returns(new EntityState()
        {
            State = "3.14"
        });

        var stateAllChangeObserverMock = target.StateAllChanges().SubscribeMock();
        var stateChangeObserverMock    = target.StateChanges().SubscribeMock();

        haContextMock.StateAllChangeSubject.OnNext(new StateChange(entity,
                                                                   old: new EntityState {
            State = "1"
        },
                                                                   @new: new EntityState {
            State = "1"
        }));

        haContextMock.StateAllChangeSubject.OnNext(new StateChange(entity,
                                                                   old: new EntityState {
            State = "1"
        },
                                                                   @new: new EntityState {
            State = "2"
        }));

        // Assert
        stateChangeObserverMock.Verify(o => o.OnNext(It.Is <NumericStateChange>
                                                         (e => e.Entity.State.Equals(3.14) &&
                                                         e.Old !.State.Equals(1.0) &&
                                                         e.New !.State.Equals(2.0))), Times.Once);
        stateChangeObserverMock.VerifyNoOtherCalls();

        stateAllChangeObserverMock.Verify(o => o.OnNext(It.Is <NumericStateChange>
                                                            (e => e.Entity.State.Equals(3.14) &&
                                                            e.Old !.State.Equals(1.0) &&
                                                            e.New !.State.Equals(2.0))), Times.Once);

        stateAllChangeObserverMock.Verify(o => o.OnNext(It.Is <NumericStateChange>
                                                            (e => e.Entity.State.Equals(3.14) &&
                                                            e.Old !.State.Equals(1.0) &&
                                                            e.New !.State.Equals(1.0))), Times.Once);
        stateAllChangeObserverMock.VerifyNoOtherCalls();
    }