public void Adding_More_Than_Once_Throws_ArgumentException() { // arrange var pattern = new Regex("Container with ID: [0-9a-z-]+ already in yard: Cannot add container\\."); var yard = new HoldingYard(); var container = CreateContainer(); yard.Add(container); // act var ex = Assert.Throws <ArgumentException>(() => yard.Add(container)); // assert Assert.Matches(pattern, ex.Message); }
public void Adding_Beyond_Capacity_Throws_InvalidOperation_Exception() { // arrange var pattern = new Regex("Holdingyard is filled to capacity: cannot add container with ID: [0-9a-z-]+\\."); var capacity = 5; var yard = new HoldingYard(capacity); // fill up the yard for (var i = 0; i < capacity; i++) { yard.Add(CreateContainer()); } // assert var ex = Assert.Throws <InvalidOperationException>(() => yard.Add(CreateContainer())); Assert.Matches(pattern, ex.Message); }
public void IsFilled_True_When_Capacity_Reached() { // arrange var yard = new HoldingYard(); var capacity = yard.Capacity; for (var i = 0; i < capacity - 3; i++) { yard.Add(CreateContainer()); } var expectedResults = new [] { false, false, true }; // act, assert foreach (var expected in expectedResults) { yard.Add(CreateContainer()); Assert.Equal(expected, yard.IsFilled); } }
public void IsEmpty_Reflects_Contents_When_Adding(int addContainers, bool expected) { // arrange var yard = new HoldingYard(); // act for (var cnt = 0; cnt < addContainers; ++cnt) { yard.Add(new Container(Guid.NewGuid(), "Name", "Description")); } // assert Assert.Equal(expected, yard.IsEmpty); }
public void FindByInfo_Retrieves_Container_Using_ID() { // arrange var yard = new HoldingYard(); var container = CreateContainer(); ContainerInformation ci = container.Information(); yard.Add(container); // act var ctr = yard.FindByInfo(ci); // assert Assert.Equal(container.Id, ctr.Id); }
public void IsEmpty_Reflects_Contents_When_Removing(int addContainers, int removeContainers, bool expected) { // arrange var yard = new HoldingYard(); var containers = new List <Container>(addContainers); // act for (var cnt = 0; cnt < addContainers; ++cnt) { containers.Add(CreateContainer()); yard.Add(containers.Last()); } for (var cnt = 0; cnt < removeContainers; cnt++) { yard.Remove(containers[cnt]); } // assert Assert.Equal(expected, yard.IsEmpty); }