public void GameState_DeletingATarget_Should_RemoveCorrectly()
        {
            var mockState           = TerraformMockHelpers.Setup_MockGameStateData_Targets();
            var mockStateCurrent    = TerraformMockHelpers.Setup_MockGameStateData_Elements();
            var mockProcessedResult = new ProcessedTerraformingListResult()
            {
                newTargets = mockState,
                newValues  = mockStateCurrent
            };

            var gameDataHandlerMock = TerraformMockHelpers.SetupMock_IOrbitBodyTerraformDataHandler(mockState);
            var managerMock         = TerraformMockHelpers.SetupMock_ITerraformingManager(mockProcessedResult);
            var gameState           = new TerraformGameState(gameDataHandlerMock.Object, managerMock.Object);

            gameState.SetTargetFor(orbitBodyId: 9999, populationId: 8888, elementId: 1, targetAmount: 1.1);
            gameState.SetTargetFor(orbitBodyId: 9999, populationId: 8888, elementId: 2, targetAmount: 2.2);
            gameState.SetTargetFor(orbitBodyId: 9999, populationId: 8888, elementId: 3, targetAmount: 3.3);

            gameState.DeleteTargetFor(orbitBodyId: 9999, populationId: 8888, elementId: 2);

            var fetchTarget = gameState.GetTargetsFor(orbitBodyId: 9999, populationId: 8888);

            Assert.AreEqual(1.1, fetchTarget.DesiredTargets.GetAmount(1));
            Assert.IsFalse(fetchTarget.DesiredTargets.IsPresent(2));
            Assert.AreEqual(3.3, fetchTarget.DesiredTargets.GetAmount(3));
        }
        public void GameState_IfAllTargetsAreDeleted_Should_RemoveEntryEntirely()
        {
            var mockState           = TerraformMockHelpers.Setup_MockGameStateData_Targets();
            var mockStateCurrent    = TerraformMockHelpers.Setup_MockGameStateData_Elements();
            var mockProcessedResult = new ProcessedTerraformingListResult()
            {
                newTargets = mockState,
                newValues  = mockStateCurrent
            };

            var gameDataHandlerMock = TerraformMockHelpers.SetupMock_IOrbitBodyTerraformDataHandler(mockState);
            var managerMock         = TerraformMockHelpers.SetupMock_ITerraformingManager(mockProcessedResult);
            var gameState           = new TerraformGameState(gameDataHandlerMock.Object, managerMock.Object);

            gameState.SetTargetFor(orbitBodyId: 9999, populationId: 8888, elementId: 1, targetAmount: 1.1);

            var fetchTarget = gameState.GetTargetsFor(orbitBodyId: 9999, populationId: 8888);

            Assert.AreEqual(1.1, fetchTarget.DesiredTargets.GetAmount(1));

            gameState.DeleteTargetFor(orbitBodyId: 9999, populationId: 8888, elementId: 1);
            fetchTarget = gameState.GetTargetsFor(orbitBodyId: 9999, populationId: 8888);

            Assert.IsNull(fetchTarget);
        }
        public void GameState_SettingTheSameElementTargetMultipleTimes_Should_EndWithTheFinalSet()
        {
            var mockState           = TerraformMockHelpers.Setup_MockGameStateData_Targets();
            var mockStateCurrent    = TerraformMockHelpers.Setup_MockGameStateData_Elements();
            var mockProcessedResult = new ProcessedTerraformingListResult()
            {
                newTargets = mockState,
                newValues  = mockStateCurrent
            };

            var gameDataHandlerMock = TerraformMockHelpers.SetupMock_IOrbitBodyTerraformDataHandler(mockState);
            var managerMock         = TerraformMockHelpers.SetupMock_ITerraformingManager(mockProcessedResult);
            var gameState           = new TerraformGameState(gameDataHandlerMock.Object, managerMock.Object);

            gameState.SetTargetFor(orbitBodyId: 9999, populationId: 8888, elementId: 777, targetAmount: 100.0);
            gameState.SetTargetFor(orbitBodyId: 9999, populationId: 8888, elementId: 777, targetAmount: 734.0);
            gameState.SetTargetFor(orbitBodyId: 9999, populationId: 8888, elementId: 777, targetAmount: 123.0);
            gameState.SetTargetFor(orbitBodyId: 9999, populationId: 8888, elementId: 777, targetAmount: 45.0);

            var fetchTarget = gameState.GetTargetsFor(orbitBodyId: 9999, populationId: 8888);

            Assert.AreEqual(45.0, fetchTarget.DesiredTargets.GetAmount(777));
        }
예제 #4
0
        private void button_SetTarget_Click(object sender, EventArgs e)
        {
            try
            {
                var targetAmount = TextConversionsHelper.ConvertTextToDouble(textBox_TargetAmount.Text);
                var targetId     = GetSelectedTargetElementFromComboBox();
                if (targetId.HasValue == false)
                {
                    return;
                }

                _terraformGameState.SetTargetFor(_systemBodyId, _populationId, targetId.Value, targetAmount);
                _systemBodyData.CurrentPopulationTerraformTargets = _terraformGameState.GetTargetsForAll();
                UpdateTargetList();
            }
            catch (FormatException)
            {
                textBox_TargetAmount.Text = "0.0";
            }
        }