public void AddJob_MaximumCapacityReached_ShouldThrowAnInvalidOperationException() { //Arrange string name = Guid.NewGuid().ToString(); int capacity = 1; IWorkload workload = CreateWorkload(name, capacity); workload.AddJob(Guid.NewGuid().ToString()); //Act + Assert Assert.That(() => workload.AddJob(Guid.NewGuid().ToString()), Throws.InvalidOperationException, "When a second job is added to a workload of capacity '1', an InvalidOperationException should be thrown."); }
public void AddJob_ShouldCreateAndAddTheJob() { //Arrange string name = Guid.NewGuid().ToString(); int capacity = 10; IWorkload workload = CreateWorkload(name, capacity); string jobDescription = Guid.NewGuid().ToString(); var originalJobCollection = workload.Jobs; //Act workload.AddJob(jobDescription); //Assert Assert.That(workload.Jobs.Count, Is.EqualTo(1), "The 'Jobs' property should contain 1 job."); IJob addedJob = workload.Jobs.First(); Assert.That(addedJob, Is.Not.Null, "The added job should not be null."); Assert.That(addedJob.Description, Is.EqualTo(jobDescription), "The description of the added job is not correct."); Assert.That(addedJob.WorkloadId, Is.EqualTo(workload.Id), "The 'workloadId' of the added job is not correct."); Assert.That(workload.Jobs, Is.SameAs(originalJobCollection), "The collection that is returned by the 'Jobs' property should be the same object in memory than the collection that is returned by the 'Jobs' property after the construction of the workload. " + "Tip1: The 'Jobs' property should not have a setter. Use a backing field. " + "Tip2: List<IJob> implements the IReadOnlyCollection<IJob> interface."); }