コード例 #1
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);
        }
コード例 #2
0
        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));
        }
コード例 #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);
        }
コード例 #4
0
 public void AnimateToSquare()
 {
     _layer.StrokeEnd = 1f;
     _counterState    = CounterState.Square;
     // aka goto Draw()
     SetNeedsDisplay();
 }
コード例 #5
0
ファイル: AggregateTests.cs プロジェクト: zarmsen/NDomain
        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);
        }
コード例 #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);
        }
コード例 #7
0
ファイル: Counter.cs プロジェクト: PETITSloane/iCreate2018
 public void StopTimer()
 {
     currentState      = CounterState.STOP;
     _endTimerFunction = null;
     _endEverySeconds  = null;
     //      Debug.Log ("stop timer ");
 }
コード例 #8
0
 public static CounterState OnSetCounter(CounterState state, SetCount action)
 {
     return(state with
     {
         Count = action.Count
     });
 }
コード例 #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;
        }
コード例 #10
0
        public CounterStateCloneTests(TestFixture aTestFixture)
        {
            IServiceProvider serviceProvider = aTestFixture.ServiceProvider;
            IStore           store           = serviceProvider.GetService <IStore>();

            CounterState = store.GetState <CounterState>();
        }
コード例 #11
0
        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));
            }
        }
コード例 #12
0
 public static CounterState OnAddCounter(CounterState state, AddCounter action)
 {
     return(state with
     {
         Count = state.Count + 1
     });
 }
コード例 #13
0
        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);
        }
コード例 #14
0
        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);
        }
コード例 #15
0
ファイル: App.cs プロジェクト: vipwan/Fluxor
 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("");
 }
コード例 #16
0
 public void PauseTimer()
 {
     if (currentState == CounterState.RUN)
     {
         currentState = CounterState.PAUSE;
         //  Debug.Log("Pause");
     }
 }
コード例 #17
0
 public void ContinueTimer()
 {
     if (currentState == CounterState.PAUSE)
     {
         currentState = CounterState.RUN;
         //  Debug.Log("Cont");
     }
 }
コード例 #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;
 }
コード例 #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;
 }
コード例 #20
0
ファイル: Counter.cs プロジェクト: PETITSloane/iCreate2018
 public void StartTimer(float _maxTimer, EndTimer endFunc)
 {
     step              = 1;
     timer             = maxTimer = _maxTimer;
     _endTimerFunction = endFunc;
     _endEverySeconds  = null;
     _updating         = null;
     currentState      = CounterState.RUN;
 }
コード例 #21
0
    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> ();
    }
コード例 #22
0
        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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #25
0
        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);
        }
コード例 #26
0
        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;
            }
        }
コード例 #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);
        }
コード例 #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());
        }
コード例 #29
0
        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);
        }
コード例 #30
0
ファイル: Counter.cs プロジェクト: jaycausing/PillarOfEden-VR
        // 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;
            }
        }
コード例 #31
0
        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);
        }
コード例 #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);
        }