public void CanCreateFromState()
        {
            // arrange
            var factory = AggregateFactory.For<Counter>();
            var aggregateId = "some id";
            var state = new CounterState();
            for (var i = 0; i < 10; ++i)
            {
                state.Mutate(new AggregateEvent<CounterIncremented>(
                                    aggregateId, i, DateTime.UtcNow, new CounterIncremented()));
            }

            // act
            var aggregate = factory.CreateFromState(aggregateId, state);

            // assert
            Assert.NotNull(aggregate);
            Assert.AreEqual(aggregateId, aggregate.Id);
            Assert.AreEqual(state.Version, aggregate.OriginalVersion);
            Assert.AreEqual(0, aggregate.Changes.Count());

            Assert.NotNull(aggregate.State);
            // no changes, so state version is the same
            Assert.AreEqual(state.Version, aggregate.State.Version);
        }
        public Task <List <CounterState> > ReadDeltasAsync(int start, int pageSize, CancellationToken cancellationToken)
        {
            var results = new List <CounterState>();

            while (_reader.Read() && _reader.TokenType != JsonToken.EndArray)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var snapshot = RavenJToken.ReadFrom(_reader);

                var name  = snapshot.Value <string>("CounterName");
                var group = snapshot.Value <string>("GroupName");
                var sign  = snapshot.Value <char>("Sign");
                var value = snapshot.Value <long>("Value");

                var delta = new CounterState
                {
                    CounterName = name,
                    GroupName   = group,
                    Value       = value,
                    Sign        = sign
                };

                results.Add(delta);
            }

            return(new CompletedTask <List <CounterState> >(results));
        }
Exemple #3
0
        public void TestTransitionAction()
        {
            var machine = new StateMachine();

            int a = 0, b = 0;

            var state1 = new CounterState();
            var state2 = new DefaultState("S2");
            var state3 = new DefaultState("S3");

            machine.AddTransition(DefaultState.Enter, state1);

            machine.AddTransition(state1, state2)
            .When(s => s.Entered == 1)
            .OnTransition((s, t) => a = s.Updated);

            machine.AddTransition(state1, state3)
            .When(s => s.Entered == 2)
            .OnTransition((s, t) => b = s.Updated);

            machine.Update(0);

            Assert.AreEqual(1, a, double.Epsilon);
            Assert.AreEqual(0, b, double.Epsilon);

            machine.Update(0);

            Assert.AreEqual(1, a, double.Epsilon);
            Assert.AreEqual(2, b, double.Epsilon);
        }
Exemple #4
0
 public void AnimateToSquare()
 {
     _layer.StrokeEnd = 1f;
     _counterState    = CounterState.Square;
     // aka goto Draw()
     SetNeedsDisplay();
 }
Exemple #5
0
        public void CanCreateFromState()
        {
            // arrange
            var factory     = AggregateFactory.For <Counter>();
            var aggregateId = "some id";
            var state       = new CounterState();

            for (var i = 0; i < 10; ++i)
            {
                state.Mutate(new AggregateEvent <CounterIncremented>(
                                 aggregateId, i, DateTime.UtcNow, new CounterIncremented()));
            }

            // act
            var aggregate = factory.CreateFromState(aggregateId, state);

            // assert
            Assert.NotNull(aggregate);
            Assert.AreEqual(aggregateId, aggregate.Id);
            Assert.AreEqual(state.Version, aggregate.OriginalVersion);
            Assert.AreEqual(0, aggregate.Changes.Count());

            Assert.NotNull(aggregate.State);
            // no changes, so state version is the same
            Assert.AreEqual(state.Version, aggregate.State.Version);
        }
Exemple #6
0
        public void ShouldLoadStatesFromJson()
        {
            //Arrange
            string jsonString = File.ReadAllText("./Store/Store.json");

            //Act
            ReduxDevToolsStore.LoadStatesFromJson(jsonString);
            // Assert
            ApplicationState applicationState = Store.GetState <ApplicationState>();

            applicationState.Name.ShouldBe("Blazor State Demo Application");
            applicationState.Guid.ToString().ShouldBe("5a2efcec-6297-4254-a2dc-30e4e567e549");

            CounterState counterState = Store.GetState <CounterState>();

            counterState.Count.ShouldBe(18);
            counterState.Guid.ToString().ShouldBe("a0d74c63-13f4-4a2f-b18b-9a1fdaa397b2");

            WeatherForecastsState weatherForecastsState = Store.GetState <WeatherForecastsState>();

            weatherForecastsState.WeatherForecasts.Count.ShouldBe(5);
            weatherForecastsState.WeatherForecasts[0].Summary.ShouldBe("Freezing");
            weatherForecastsState.WeatherForecasts[0].TemperatureC.ShouldBe(16);
            weatherForecastsState.WeatherForecasts[0].TemperatureF.ShouldBe(60);
            weatherForecastsState.WeatherForecasts[0].Date.Year.ShouldBe(2018);
            weatherForecastsState.WeatherForecasts[0].Date.Month.ShouldBe(8);
            weatherForecastsState.WeatherForecasts[0].Date.Day.ShouldBe(26);
            weatherForecastsState.WeatherForecasts[0].Date.Hour.ShouldBe(9);
            weatherForecastsState.WeatherForecasts[0].Date.Minute.ShouldBe(29);
            weatherForecastsState.WeatherForecasts[0].Date.Second.ShouldBe(54);
        }
Exemple #7
0
 public void StopTimer()
 {
     currentState      = CounterState.STOP;
     _endTimerFunction = null;
     _endEverySeconds  = null;
     //      Debug.Log ("stop timer ");
 }
Exemple #8
0
 public static CounterState OnSetCounter(CounterState state, SetCount action)
 {
     return(state with
     {
         Count = action.Count
     });
 }
Exemple #9
0
        private void CounterFinish(Unit hero, CounterState state, IEnumerable <Unit> units)
        {
            if (hero.Health <= 0)
            {
                return;
            }

            Unit nearestEnemy =
                units.Where(u => u.Team == World.Enemy(hero.Team))
                .MinByOrDefault(u => u.Pos.DistanceTo(hero.Pos));

            if (nearestEnemy == null || nearestEnemy.Pos.DistanceTo(hero.Pos) > World.CounterRange)
            {
                return;
            }

            double counterDamage = World.CounterDamage(state.InitialHealth - hero.Health);

            if (counterDamage <= 0)
            {
                return;
            }

            Damage(nearestEnemy, counterDamage, hero.UnitId);
            hero.Health = state.InitialHealth;
        }
        public CounterStateCloneTests(TestFixture aTestFixture)
        {
            IServiceProvider serviceProvider = aTestFixture.ServiceProvider;
            IStore           store           = serviceProvider.GetService <IStore>();

            CounterState = store.GetState <CounterState>();
        }
        private async Task <DialogTurnResult> ProcessRootAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var userInfo = await _accessors.UserInfo.GetAsync(
                stepContext.Context, () => new Model.UserInfo());

            if (string.IsNullOrEmpty(userInfo.Name))
            {
                return(await stepContext.BeginDialogAsync(
                           askNameWaterfall, null, cancellationToken));
            }
            else if (stepContext.Result.ToString() == "訂房")
            {
                return(await stepContext.BeginDialogAsync(
                           "bookRoom", null, cancellationToken));
            }
            else
            {
                CounterState state = await GetCounterState(stepContext.Context);

                state.TurnCount++;

                // Set the property using the accessor.
                await _accessors.CounterState.SetAsync(stepContext.Context, state);

                // Save the new turn count into the conversation state.

                // Echo back to the user whatever they typed.
                var responseMessage = $"Name: {userInfo.Name} Turn {state.TurnCount}: You sent '{stepContext.Result}'\n";
                await stepContext.Context.SendActivityAsync(responseMessage);

                return(await stepContext.ContinueDialogAsync(cancellationToken));
            }
        }
Exemple #12
0
 public static CounterState OnAddCounter(CounterState state, AddCounter action)
 {
     return(state with
     {
         Count = state.Count + 1
     });
 }
        public void TestDelayState()
        {
            var machine = new StateMachine();
            var state1  = new CounterState();
            var state2  = new DelayState(3);
            var state3  = new CounterState();

            machine.AddTransition(DefaultState.Enter, state1);
            machine.AddTransition(state1, state2);
            machine.AddTransition(state2, state3);

            for (var i = 0; i < 2; i++)
            {
                machine.Update(1);
            }

            Assert.AreEqual(1, state1.Entered, double.Epsilon);
            Assert.IsFalse(state2.Completed);
            Assert.AreEqual(0, state3.Entered, double.Epsilon);

            machine.Update(1);

            Assert.AreEqual(1, state1.Entered, double.Epsilon);
            Assert.IsTrue(state2.Completed);
            Assert.AreEqual(1, state3.Entered, double.Epsilon);

            machine.Update(1);
            Assert.IsFalse(state2.Completed);
        }
        public void TestNestedMachineWithNonEmptyState()
        {
            var parent = new StateMachine();
            var child  = new StateMachine();

            parent.AddTransition(DefaultState.Enter, child);

            var state = new CounterState();

            child.AddTransition(DefaultState.Enter, state);

            child.AddTransition(state, DefaultState.Exit)
            .When(s => s.Updated > 1);

            parent.Update(0);

            Assert.AreEqual(1, state.Entered, double.Epsilon);
            Assert.AreEqual(1, state.Updated, double.Epsilon);
            Assert.AreEqual(0, state.Exited, double.Epsilon);

            parent.Update(0);

            Assert.AreEqual(2, state.Updated, double.Epsilon);
            Assert.AreEqual(1, state.Exited, double.Epsilon);
        }
Exemple #15
0
 private void CounterState_StateChanged(object sender, CounterState e)
 {
     Console.WriteLine("");
     Console.WriteLine("==========================> CounterState");
     Console.WriteLine("ClickCount is " + CounterState.Value.ClickCount);
     Console.WriteLine("<========================== CounterState");
     Console.WriteLine("");
 }
Exemple #16
0
 public void PauseTimer()
 {
     if (currentState == CounterState.RUN)
     {
         currentState = CounterState.PAUSE;
         //  Debug.Log("Pause");
     }
 }
Exemple #17
0
 public void ContinueTimer()
 {
     if (currentState == CounterState.PAUSE)
     {
         currentState = CounterState.RUN;
         //  Debug.Log("Cont");
     }
 }
Exemple #18
0
 public void StartTimerUpdatePercentage(float _maxTimer, EndTimer endFunc, UpdatingPercentage updatingFunc = null)
 {
     step             = 1;
     timer            = maxTimer = _maxTimer;
     endTimerFunction = endFunc;
     endEverySeconds  = null;
     updating         = updatingFunc;
     currentState     = CounterState.RUN;
 }
Exemple #19
0
 public void StartTimerUpdateSeconds(float _maxTimer, EndTimer endFunc, EndEverySeconds endSecs = null)
 {
     step             = 1;
     timer            = maxTimer = _maxTimer;
     endTimerFunction = endFunc;
     endEverySeconds  = endSecs;
     updating         = null;
     currentState     = CounterState.RUN;
 }
Exemple #20
0
 public void StartTimer(float _maxTimer, EndTimer endFunc)
 {
     step              = 1;
     timer             = maxTimer = _maxTimer;
     _endTimerFunction = endFunc;
     _endEverySeconds  = null;
     _updating         = null;
     currentState      = CounterState.RUN;
 }
    protected void Awake()
    {
        idleState = new IdleState(this);
        huntState = new HuntState(this);
        fearState = new FearState(this);
        engageState = new EngageState(this);
        counterState = new CounterState(this);

        nav = GetComponent<NavMeshAgent> ();
    }
        public void TestUpdateCount()
        {
            var machine = new StateMachine();
            var state   = new CounterState();

            machine.AddTransition(DefaultState.Enter, state);

            machine.Update(0);

            Assert.AreEqual(1, state.Updated, double.Epsilon);
        }
Exemple #23
0
        public async Task Should_Increment_Counter()
        {
            CounterState.Initialize(aCount: 22);

            var incrementCounterRequest = new IncrementCounterAction
            {
                Amount = 5
            };

            CounterState = await Mediator.Send(incrementCounterRequest);

            CounterState.Count.ShouldBe(27);
        }
Exemple #24
0
        public async Task Decrement_PageIndex_Given_NegativeAmount()
        {
            //Arrange
            CounterState.Initialize(aPageIndex: 15);

            var incrementPageIndexRequest = new __ActionName__Action
            {
                PageIndex = -2
            };

            //Act
            await Send(incrementPageIndexRequest);

            //Assert
            __FeatureName__State.PageIndex.ShouldBe(13);
        }
        public async Task Should_Decrement_Counter()
        {
            //Arrange
            CounterState.Initialize(aCount: 15);

            var incrementCounterRequest = new IncrementCounterAction
            {
                Amount = -2
            };

            //Act
            CounterState = await Mediator.Send(incrementCounterRequest);

            //Assert
            CounterState.Count.ShouldBe(13);
        }
        public void TestCounterStateWithCountValueGreaterThanMaxCountValue()
        {
            try
            {
                target.CounterState = new CounterState(999, 10, "MyTestCounterNew");
                Assert.Fail();
            }
            catch (FaultException <CounterFaultContract> )
            {
                CounterState state = target.CounterState;

                Assert.AreEqual(0, state.CountValue);
                Assert.AreEqual(10, state.MaxCountValue);
                Assert.AreEqual("MyTestCounter", state.CounterId);

                throw;
            }
        }
Exemple #27
0
        public async Task ShouldCloneState()
        {
            //Arrange
            CounterState.Initialize(aCount: 15);
            Guid preActionGuid = CounterState.Guid;

            // Create request
            var incrementCounterRequest = new IncrementCounterAction
            {
                Amount = -2
            };

            //Act
            CounterState = await Mediator.Send(incrementCounterRequest);

            //Assert
            CounterState.Guid.ShouldNotBe(preActionGuid);
        }
Exemple #28
0
        public Task WriteDeltaAsync(CounterState delta, CancellationToken cancellationToken)
        {
            Writer.WriteStartObject();
            Writer.WritePropertyName("CounterName");
            Writer.WriteValue(delta.CounterName);

            Writer.WritePropertyName("GroupName");
            Writer.WriteValue(delta.GroupName);

            Writer.WritePropertyName("Sign");
            Writer.WriteValue(delta.Sign);

            Writer.WritePropertyName("Value");
            Writer.WriteValue(delta.Value);
            Writer.WriteEndObject();

            return(new CompletedTask());
        }
        public void TestCounterState()
        {
            CounterState state = target.CounterState;

            Assert.AreEqual(0, state.CountValue);
            Assert.AreEqual(10, state.MaxCountValue);
            Assert.AreEqual("MyTestCounter", state.CounterId);

            state.CountValue    = 5;
            state.MaxCountValue = 5;
            state.CounterId     = "MyTestCounterNew";

            target.CounterState = state;

            Assert.AreEqual(5, state.CountValue);
            Assert.AreEqual(5, state.MaxCountValue);
            Assert.AreEqual("MyTestCounterNew", state.CounterId);
        }
Exemple #30
0
        // Update is called once per frame
        void FixedUpdate()
        {
            switch (CurrentState)
            {
            case CounterState.RUN:

                timer -= Time.fixedDeltaTime * step;

                if (_updating != null)
                {
                    _updating(1 - timer * 1.0f / maxTimer);
                }

                if (Mathf.Abs(timer - preTimer) >= 1)
                {
                    preTimer = timer;
                    if (_endEverySeconds != null)
                    {
                        _endEverySeconds(Mathf.RoundToInt(preTimer));
                    }
                }

                if (timer < 0)
                {
                    if (!DelayReset)
                    {
                        timer        = maxTimer;
                        currentState = CounterState.STOP;
                    }
                    if (_endTimerFunction != null)
                    {
                        _endTimerFunction();
                    }
                }
                break;

            case CounterState.PAUSE:
                break;

            case CounterState.STOP:
                preTimer = timer = maxTimer;
                break;
            }
        }
        public async Task Should_Increment_Counter()
        {
            //Arrange

            // Setup know state.
            CounterState.Initialize(aCount: 22);

            // Create request
            var incrementCounterRequest = new Client.Features.Counter.IncrementCount.IncrementCounterAction
            {
                Amount = 5
            };

            //Act
            CounterState = await Mediator.Send(incrementCounterRequest);

            //Assert
            CounterState.Count.ShouldBe(27);
        }
Exemple #32
0
        public async Task ShouldRollBackStateAndThrow()
        {
            // Arrange
            CounterState.Initialize(aCount: 22);
            Guid preActionGuid = CounterState.Guid;

            // Act
            var throwExceptionAction = new ThrowExceptionAction
            {
                Message = "Test Rollback of State"
            };

            Exception exception = await Should.ThrowAsync <Exception>(async() =>
                                                                      CounterState = await Mediator.Send(throwExceptionAction));

            // Assert
            exception.Message.ShouldBe(throwExceptionAction.Message);
            CounterState = Store.GetState <CounterState>();
            CounterState.Guid.Equals(preActionGuid);
        }