public void DeleteElement_ElementDoesNotExistInProblem_ExpectNothingHappens() { //Arrange var modelProblem = new ModelProblem("problem"); var otherProblem = new ModelProblem("otherProblem"); var strayElement = new ModelBarElement(otherProblem, 1234, new ModelNode(otherProblem, 123), new ModelNode(otherProblem, 1234)); //Act modelProblem.DeleteElement(strayElement); //Assert Assert.That(modelProblem.Elements, Is.Empty); }
public IModelElement AddElement(IModelNode origin, IModelNode destination) { if (origin is null) { throw new ArgumentNullException(nameof(origin)); } if (destination is null) { throw new ArgumentNullException(nameof(destination)); } if (!Nodes.Contains(origin)) { throw new InvalidOperationException($"Node {nameof(origin)} does not exist in current problem"); } if (!Nodes.Contains(destination)) { throw new InvalidOperationException($"Node {nameof(destination)} does not exist in current problem"); } if (origin == destination) { throw new InvalidOperationException($"Nodes {nameof(origin)} and {nameof(destination)} are the same node"); } if (Elements.Any(other => other.OriginNode == origin && other.DestinationNode == destination || other.OriginNode == destination && other.DestinationNode == origin)) { throw new InvalidOperationException($"An element with nodes {origin.Id} and {destination.Id} already exists in current problem"); } var id = GetNextId(_elements); var element = new ModelBarElement(this, id, origin, destination) { Material = GetOrCreateDefaultMaterial() }; _elements.Add(element); return(element); }