Пример #1
0
        public void GivenViewModelWithNrOfEnginesAndThrustPerEngineNotZero_WhenSettingThrustPerEngineNaN_ThenEventsFired()
        {
            // Given
            const int nrOfEngines = 4;

            var    random          = new Random(21);
            double thrustPerEngine = random.NextDouble();
            var    engineData      = new EngineData
            {
                NrOfEngines     = nrOfEngines,
                ThrustPerEngine = thrustPerEngine
            };
            var viewModel = new EngineSettingsTabViewModel(engineData);

            var eventArgsCollection = new List <PropertyChangedEventArgs>();

            viewModel.PropertyChanged += (o, e) =>
            {
                eventArgsCollection.Add(e);
            };

            // When
            viewModel.ThrustPerEngine = double.NaN;
            double totalThrust = viewModel.TotalThrust;

            // Then
            Assert.That(totalThrust, Is.NaN);
            CollectionAssert.AreEquivalent(new[]
            {
                "ThrustPerEngine",
                "TotalThrust"
            }, eventArgsCollection.Select(e => e.PropertyName));
        }
Пример #2
0
        public void NrOfFailedEngines_SettingNewValue_RaisesOnPropertyChangedEventAndSetsEngineDat()
        {
            // Setup
            var engineData = new EngineData();
            var viewModel  = new EngineSettingsTabViewModel(engineData);

            bool propertyChangedTriggered      = false;
            PropertyChangedEventArgs eventArgs = null;

            viewModel.PropertyChanged += (o, e) =>
            {
                propertyChangedTriggered = true;
                eventArgs = e;
            };

            var random   = new Random(21);
            int newValue = random.Next();

            // Call
            viewModel.NrOfFailedEngines = newValue;

            // Assert
            Assert.That(engineData.NrOfFailedEngines, Is.EqualTo(newValue));
            Assert.That(propertyChangedTriggered, Is.True);
            Assert.That(eventArgs.PropertyName, Is.EqualTo(nameof(EngineSettingsTabViewModel.NrOfFailedEngines)));
        }
Пример #3
0
        public void GivenViewModelWithNrOfEnginesAndThrustPerEngineNotZero_WhenSettingSameThrustPerEngine_ThenNoEventsFired(double tolerance)
        {
            // Given
            const int nrOfEngines = 4;

            var    random          = new Random(21);
            double thrustPerEngine = random.NextDouble();
            var    engineData      = new EngineData
            {
                NrOfEngines     = nrOfEngines,
                ThrustPerEngine = thrustPerEngine
            };
            var viewModel = new EngineSettingsTabViewModel(engineData);

            var eventArgsCollection = new List <PropertyChangedEventArgs>();

            viewModel.PropertyChanged += (o, e) =>
            {
                eventArgsCollection.Add(e);
            };

            // When
            viewModel.ThrustPerEngine = thrustPerEngine + tolerance;

            // Then
            Assert.That(engineData.ThrustPerEngine, Is.EqualTo(thrustPerEngine));
            Assert.That(eventArgsCollection, Is.Empty);
        }
Пример #4
0
        public void GivenViewModelWithThrustPerEngineNotZero_WhenNrOfEnginesSet_ThenNotifyPropertyChangedEventsFiredAndTotalThrustUpdated()
        {
            // Given
            var    random          = new Random(21);
            double thrustPerEngine = random.NextDouble();
            var    engineData      = new EngineData
            {
                ThrustPerEngine = thrustPerEngine
            };
            var viewModel = new EngineSettingsTabViewModel(engineData);

            var eventArgsCollection = new List <PropertyChangedEventArgs>();

            viewModel.PropertyChanged += (o, e) =>
            {
                eventArgsCollection.Add(e);
            };

            const int nrOfEngines = 4;

            // When
            viewModel.NrOfEngines = nrOfEngines;
            double totalThrust = viewModel.TotalThrust;
            int    maximumNrOfFailedEngines = viewModel.MaximumNrOfFailedEngines;

            // Then
            Assert.That(maximumNrOfFailedEngines, Is.EqualTo(nrOfEngines - 1));
            Assert.That(totalThrust, Is.EqualTo(nrOfEngines * thrustPerEngine).Within(1e-5));
            CollectionAssert.AreEquivalent(new[]
            {
                "NrOfEngines",
                "TotalThrust",
                "MaximumNrOfFailedEngines"
            }, eventArgsCollection.Select(e => e.PropertyName));
        }
Пример #5
0
        public void GivenViewModelWithNrOfEnginesNotZero_WhenThrustPerEngineSet_ThenNotifyPropertyChangedEventsFiredAndTotalThrustUpdated()
        {
            // Given
            const int nrOfEngines = 4;
            var       engineData  = new EngineData
            {
                NrOfEngines = nrOfEngines
            };
            var viewModel = new EngineSettingsTabViewModel(engineData);

            var eventArgsCollection = new List <PropertyChangedEventArgs>();

            viewModel.PropertyChanged += (o, e) =>
            {
                eventArgsCollection.Add(e);
            };

            var    random          = new Random(21);
            double thrustPerEngine = random.NextDouble();

            // When
            viewModel.ThrustPerEngine = thrustPerEngine;
            double totalThrust = viewModel.TotalThrust;

            // Then
            double expectedTotalThrust = nrOfEngines * thrustPerEngine;

            Assert.That(totalThrust, Is.EqualTo(expectedTotalThrust).Within(1e-5));
            CollectionAssert.AreEquivalent(new[]
            {
                "ThrustPerEngine",
                "TotalThrust"
            }, eventArgsCollection.Select(e => e.PropertyName));
        }
Пример #6
0
 private static void AssertEngineData(EngineSettingsTabViewModel expected,
                                      EngineData actual)
 {
     Assert.That(actual.ThrustPerEngine, Is.EqualTo(expected.ThrustPerEngine));
     Assert.That(actual.NrOfEngines, Is.EqualTo(expected.NrOfEngines));
     Assert.That(actual.NrOfFailedEngines, Is.EqualTo(expected.NrOfFailedEngines));
 }
Пример #7
0
        private static void SetEngineData(EngineSettingsTabViewModel viewModel, int seed)
        {
            var random = new Random(seed);

            viewModel.ThrustPerEngine   = random.Next();
            viewModel.NrOfEngines       = random.Next();
            viewModel.NrOfFailedEngines = viewModel.NrOfEngines - 1;

            // Precondition
            var defaultSettings = new EngineData();

            Assert.That(viewModel.NrOfEngines, Is.Not.EqualTo(defaultSettings.NrOfEngines));
            Assert.That(viewModel.NrOfFailedEngines, Is.Not.EqualTo(defaultSettings.NrOfFailedEngines));
        }
Пример #8
0
        public void ThrustPerEngine_SettingNewValue_SetsEngineData()
        {
            // Setup
            var engineData = new EngineData();
            var viewModel  = new EngineSettingsTabViewModel(engineData);

            var    random   = new Random(21);
            double newValue = random.NextDouble();

            // Call
            viewModel.ThrustPerEngine = newValue;

            // Assert
            Assert.That(engineData.ThrustPerEngine, Is.EqualTo(newValue));
        }
Пример #9
0
        public void NrOfEngines_SettingNewValue_SetsEngineData()
        {
            // Setup
            var engineData = new EngineData();
            var viewModel  = new EngineSettingsTabViewModel(engineData);

            var random   = new Random(21);
            int newValue = random.Next();

            // Call
            viewModel.NrOfEngines = newValue;

            // Assert
            Assert.That(engineData.NrOfEngines, Is.EqualTo(newValue));
        }
Пример #10
0
        public static void Constructor_ExpectedValues()
        {
            // Setup
            var engineData = new EngineData();

            // Call
            var viewModel = new EngineSettingsTabViewModel(engineData);

            // Assert
            Assert.That(viewModel, Is.InstanceOf <ViewModelBase>());
            Assert.That(viewModel, Is.InstanceOf <ITabViewModel>());
            Assert.That(viewModel.TabName, Is.EqualTo("Engine data"));

            Assert.That(viewModel.ThrustPerEngine, Is.EqualTo(engineData.ThrustPerEngine));
            Assert.That(viewModel.NrOfEngines, Is.EqualTo(engineData.NrOfEngines));
            Assert.That(viewModel.NrOfFailedEngines, Is.EqualTo(engineData.NrOfFailedEngines));
        }
Пример #11
0
        public void GivenViewModelWithMaximumNrOfFailedEngines_WhenNrOfEnginesDecreasesBelowMaximumAllowed_ThenMaximumNrOfEnginesCappedAndEventsFired()
        {
            // Given
            const int nrOfEngines = 4;

            var engineData = new EngineData
            {
                NrOfEngines       = nrOfEngines,
                NrOfFailedEngines = nrOfEngines - 1
            };
            var viewModel = new EngineSettingsTabViewModel(engineData);

            var eventArgsCollection = new List <PropertyChangedEventArgs>();

            viewModel.PropertyChanged += (o, e) =>
            {
                eventArgsCollection.Add(e);
            };

            // When
            const int updatedNrOfEngines = 3;

            viewModel.NrOfEngines = updatedNrOfEngines;
            int updatedNrOfFailedEngines = viewModel.NrOfFailedEngines;

            // Then
            Assert.That(engineData.NrOfEngines, Is.EqualTo(updatedNrOfEngines));

            const int expectedNrOfFailedEngines = updatedNrOfEngines - 1;

            Assert.That(engineData.NrOfFailedEngines, Is.EqualTo(expectedNrOfFailedEngines));
            Assert.That(updatedNrOfFailedEngines, Is.EqualTo(expectedNrOfFailedEngines));

            CollectionAssert.AreEquivalent(new[]
            {
                "NrOfEngines",
                "TotalThrust",
                "MaximumNrOfFailedEngines",
                "NrOfFailedEngines"
            }, eventArgsCollection.Select(e => e.PropertyName));
        }