コード例 #1
0
        public void SelectedWorkload_ShouldNotifyChanges()
        {
            //Arrange
            IWorkload workload = new WorkloadBuilder().Build();
            bool      selectedWorkloadChangeNotified     = false;
            bool      showSelectedWorkloadChangeNotified = false;

            _window.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == nameof(MainWindow.SelectedWorkload))
                {
                    selectedWorkloadChangeNotified = true;
                }

                if (args.PropertyName == nameof(MainWindow.ShowSelectedWorkload))
                {
                    showSelectedWorkloadChangeNotified = true;
                }
            };

            //Act
            _window.SelectedWorkload = workload;

            //Assert
            Assert.That(_window.SelectedWorkload, Is.SameAs(workload),
                        "The 'SelectedWorkload' property is not set correctly.");

            Assert.That(selectedWorkloadChangeNotified, Is.True,
                        "The 'PropertyChanged' event should be triggered for the property 'SelectedWorkload'.");

            Assert.That(showSelectedWorkloadChangeNotified, Is.True,
                        "The 'PropertyChanged' event should also be triggered for the property 'ShowSelectedWorkload' " +
                        "(This property might return a different value when the selected workload has changed).");
        }
コード例 #2
0
        public void GetAll_ShouldRetrieveAllAddedWorkloads()
        {
            //Arrange
            IWorkload workload1 = new WorkloadBuilder().Build();
            IWorkload workload2 = new WorkloadBuilder().Build();

            try
            {
                _repository.Add(workload1);
                _repository.Add(workload2);
            }
            catch (Exception)
            {
                Assert.Fail(
                    $"Make sure that the test '{nameof(Add_ShouldSaveAJsonVersionOfTheWorkloadInAFile)}' is green, before attempting to make this test green.");
            }

            //Act
            IReadOnlyList <IWorkload> allWorkloads = _repository.GetAll();

            //Assert
            Assert.That(allWorkloads.Count, Is.EqualTo(2), "2 workloads should be returned after adding 2 workloads.");

            var workloadMatch1 = allWorkloads.FirstOrDefault(wl => wl.Id == workload1.Id);

            AssertWorkloadEquality(workloadMatch1, workload1, "The first added workload is not the same than the matching retrieved workload.");

            var workloadMatch2 = allWorkloads.FirstOrDefault(wl => wl.Id == workload2.Id);

            AssertWorkloadEquality(workloadMatch2, workload2, "The second added workload is not the same than the matching retrieved workload.");
        }
コード例 #3
0
        public void Add_ShouldSaveAJsonVersionOfTheWorkloadInAFile()
        {
            //Arrange
            IWorkload workload = new WorkloadBuilder().Build();

            //Act
            _repository.Add(workload);

            //Assert
            AssertThatWorkloadFileExists(workload);
        }
コード例 #4
0
        public void SaveChanges_ShouldOverwriteTheMatchingWorkloadFile()
        {
            //Arrange
            TestWorkload workload = new WorkloadBuilder().Build() as TestWorkload;

            try
            {
                _repository.Add(workload);
            }
            catch (Exception)
            {
                Assert.Fail(
                    $"Make sure that the test '{nameof(Add_ShouldSaveAJsonVersionOfTheWorkloadInAFile)}' is green, before attempting to make this test green.");
            }

            string newName     = "EditedName";
            int    newCapacity = workload.Capacity + 1;

            //Act
            workload.Name     = newName;
            workload.Capacity = newCapacity;
            _repository.SaveChanges(workload);

            //Assert
            IReadOnlyList <IWorkload> allWorkloads = null;

            try
            {
                allWorkloads = _repository.GetAll();
            }
            catch (Exception)
            {
                Assert.Fail(
                    $"Make sure that the test '{nameof(GetAll_ShouldRetrieveAllAddedWorkloads)}' is green, before attempting to make this test green.");
            }

            Assert.That(allWorkloads.Count, Is.EqualTo(1), "Only one workload should be returned by 'GetAll' after adding 1 workload and updating it.");

            IWorkload updatedWorkload = allWorkloads.First();

            Assert.That(updatedWorkload.Name, Is.EqualTo(newName), "A change in the name is not saved correctly.");
            Assert.That(updatedWorkload.Capacity, Is.EqualTo(newCapacity), "A change in the capacity is not saved correctly.");
        }