Ejemplo n.º 1
0
        public void Can_LIFO_When_History_N_Plus2()
        {
            var careTaker = new HastingsCareTaker();

            var subbedMemento1 = Substitute.For <IHastingsMemento>();

            subbedMemento1.Peer.Returns(PeerIdHelper.GetPeerId("step1"));
            careTaker.Add(subbedMemento1);

            var subbedMemento2 = Substitute.For <IHastingsMemento>();

            subbedMemento2.Peer.Returns(PeerIdHelper.GetPeerId("step2"));
            careTaker.Add(subbedMemento2);

            var subbedMemento3 = Substitute.For <IHastingsMemento>();

            subbedMemento3.Peer.Returns(PeerIdHelper.GetPeerId("step3"));
            careTaker.Add(subbedMemento3);

            var lastState1 = careTaker.Get();

            lastState1.Should().Be(subbedMemento3);
            careTaker.HastingMementoList.Count.Should().Be(2);
            careTaker.HastingMementoList.First().Should().Be(subbedMemento2);

            var lastState2 = careTaker.Get();

            lastState2.Should().Be(subbedMemento2);
            careTaker.HastingMementoList.Count.Should().Be(1);
            careTaker.HastingMementoList.First().Should().Be(subbedMemento1);
        }
Ejemplo n.º 2
0
        public void Can_Never_Take_Last_State_From_CareTaker()
        {
            var careTaker = new HastingsCareTaker();

            var subbedMemento = Substitute.For <IHastingsMemento>();

            careTaker.Add(subbedMemento);

            careTaker.Get();

            careTaker.HastingMementoList.Count.Should().Be(1);
        }
Ejemplo n.º 3
0
        public void Care_Taker_Can_Get_Last_State()
        {
            var careTaker = new HastingsCareTaker();

            var subbedMemento = Substitute.For <IHastingsMemento>();

            careTaker.Add(subbedMemento);
            careTaker.Add(subbedMemento);
            careTaker.HastingMementoList.Should().HaveCount(2);
            var previousState = careTaker.Get();

            previousState.Should().BeSameAs(subbedMemento);
            careTaker.HastingMementoList.Should().HaveCount(1);
        }
Ejemplo n.º 4
0
        public void Taking_From_Memento_List_Takes_LIFO()
        {
            var careTaker = new HastingsCareTaker();

            var stack = new Stack <IHastingsMemento>();

            stack.Push(DiscoveryHelper.SubMemento(_ownNode));

            var history = DiscoveryHelper.MockMementoHistory(stack);

            history.ToList().ForEach(m => careTaker.Add(m));

            careTaker.Get().Should().Be(history.Last());
            careTaker.HastingMementoList.First().Should().Be(history.First());
            careTaker.HastingMementoList.Count.Should().Be(history.Count - 1);
        }
Ejemplo n.º 5
0
        public void Care_Taker_Should_Throw_Exception_Trying_To_Take_Last_State_From_Empty_CareTaker()
        {
            var careTaker = new HastingsCareTaker();

            Assert.Throws <InvalidOperationException>(() => { careTaker.Get(); });
        }