public void AddForce_ForceWithSameNodeAlreadyExists_ExpectInvalidOperationException() { //Arrange var modelProblem = new ModelProblem("problem"); var node = modelProblem.AddNode(); modelProblem.AddForce(node); //Act //Assert Assert.Throws <InvalidOperationException>(() => modelProblem.AddForce(node)); }
public void ValidateForces_MakeTwoForcesBeAppliedOnSameNode_ExpectInvalidOperationException() { //Arrange ModelProblem problem = new ModelProblem("problem"); var node1 = problem.AddNode(); var node2 = problem.AddNode(); var force1 = problem.AddForce(node1); var force2 = problem.AddForce(node2); //Act //Assert Assert.Throws <InvalidOperationException>(() => force2.Node = node1); }
public void Node_NodeChangedAndRelevantPropertyOfNewNodeChanged_ExpectPropertiesChangedEventRaised() { //Arrange var modelProblem = new ModelProblem("test"); var node1 = modelProblem.AddNode(); var node2 = modelProblem.AddNode(); var modelForce = modelProblem.AddForce(node1); var nodeViewModel1 = new NodeViewModel(node1); var nodeViewModel2 = new NodeViewModel(node2); var forceViewModel = new ForceViewModel(modelForce, nodeViewModel1); forceViewModel.Node = nodeViewModel2; var eventChecker = new PropertyChangedEventChecker(forceViewModel); //Act nodeViewModel2.X = 123; //Assert Assert.That(eventChecker.PropertiesRaised, Is.EqualTo(new[] { "Node", "ResultGeometry" })); }
public void AddForce_ProblemWithForces_ExpectElementIdCorrectlyInitialized() { //Arrange var modelProblem = new ModelProblem("problem"); var node = modelProblem.AddNode(); var node2 = modelProblem.AddNode(); var node3 = modelProblem.AddNode(); modelProblem.AddForce(node); modelProblem.AddForce(node2); //Act var force = modelProblem.AddForce(node3); //Assert Assert.That(force.Id, Is.EqualTo(3)); }
public void AddForce_NullNode_ExpectArgumentNullException() { //Arrange var modelProblem = new ModelProblem("problem"); //Act //Assert Assert.Throws <ArgumentNullException>(() => modelProblem.AddForce(null)); }
public void DeleteForce_ProblemWithSeveralForces_ExpectForceIdsAreCorrect() { //Arrange var modelProblem = new ModelProblem("problem"); var force1 = modelProblem.AddForce(modelProblem.AddNode()); var force2 = modelProblem.AddForce(modelProblem.AddNode()); var force3 = modelProblem.AddForce(modelProblem.AddNode()); var force4 = modelProblem.AddForce(modelProblem.AddNode()); var force5 = modelProblem.AddForce(modelProblem.AddNode()); //Act modelProblem.DeleteForce(force1); //Assert Assert.AreEqual(force2.Id, 1); Assert.AreEqual(force3.Id, 2); Assert.AreEqual(force4.Id, 3); Assert.AreEqual(force5.Id, 4); }
public void AddForce_InvalidOriginNode_ExpectInvalidOperationException() { //Arrange var modelProblem = new ModelProblem("problem"); var node = new ModelNode(new ModelProblem("otherProblem"), 123); //Act //Assert Assert.Throws <InvalidOperationException>(() => modelProblem.AddForce(node)); }
private static IModelProblem BuildProblem(ProblemMemento problemMemento) { var modelProblem = new ModelProblem(problemMemento.Name); Dictionary <int, IModelNode> nodesDictionary = new Dictionary <int, IModelNode>(); Dictionary <int, IModelMaterial> materialsDictionary = new Dictionary <int, IModelMaterial>(); foreach (var nodeMemento in problemMemento.Nodes.OrderBy(x => x.Id)) { var modelNode = modelProblem.AddNode(); modelNode.IsXFixed = nodeMemento.IsXFixed; modelNode.IsYFixed = nodeMemento.IsYFixed; modelNode.IsZFixed = nodeMemento.IsZFixed; modelNode.Coordinates.X = nodeMemento.X; modelNode.Coordinates.Y = nodeMemento.Y; modelNode.Coordinates.Z = nodeMemento.Z; nodesDictionary.Add(nodeMemento.Id, modelNode); } foreach (var forceMemento in problemMemento.Forces.OrderBy(x => x.Id)) { var applicationNode = nodesDictionary[forceMemento.NodeId]; var modelForce = modelProblem.AddForce(applicationNode); modelForce.ApplicationVector.X = forceMemento.ApplicationVectorX; modelForce.ApplicationVector.Y = forceMemento.ApplicationVectorY; modelForce.ApplicationVector.Z = forceMemento.ApplicationVectorZ; } foreach (var mementoMaterial in problemMemento.Materials.OrderBy(x => x.Id)) { var modelMaterial = modelProblem.AddMaterial(); modelMaterial.Name = mementoMaterial.Name; modelMaterial.YoungsModulus = mementoMaterial.YoungsModulus; materialsDictionary.Add(mementoMaterial.Id, modelMaterial); } foreach (var elementMemento in problemMemento.Elements.OrderBy(x => x.Id)) { var modelMaterial = materialsDictionary[elementMemento.MaterialId]; var originModelNode = nodesDictionary[elementMemento.OriginNodeId]; var destinationModelNode = nodesDictionary[elementMemento.DestinationNodeId]; var modelElement = modelProblem.AddElement(originModelNode, destinationModelNode); modelElement.Material = modelMaterial; modelElement.CrossSectionArea = elementMemento.CrossSectionArea; } return(modelProblem); }
public void DeleteNode_NodeIsUsedByElementInForce_ExpectInvalidOperationException() { //Arrange var modelProblem = new ModelProblem("problem"); var node = modelProblem.AddNode(); var force = modelProblem.AddForce(node); //Act //Assert Assert.Throws <InvalidOperationException>(() => modelProblem.DeleteNode(node)); }
private static (NodeViewModel, IModelForce) BuildTestForce() { var modelProblem = new ModelProblem("test"); var node = modelProblem.AddNode(); var force = modelProblem.AddForce(node); var nodeViewModel = new NodeViewModel(node); return(nodeViewModel, force); }
public void DeleteForce_ForceDoesExistInProblem_ExpectForceRemovedFromCollection() { //Arrange var modelProblem = new ModelProblem("problem"); var force = modelProblem.AddForce(modelProblem.AddNode()); //Act modelProblem.DeleteForce(force); //Assert Assert.That(modelProblem.Forces, Is.Empty); }
public void AddForce_EmptyProblem_ExpectForceAddedToCollection() { //Arrange var modelProblem = new ModelProblem("problem"); var node = modelProblem.AddNode(); //Act var force = modelProblem.AddForce(node); //Assert Assert.That(modelProblem.Forces.Contains(force), Is.True); }
public void ValidateForces_SetStrayNodeAsApplicationNode_ExpectInvalidOperationException() { //Arrange ModelProblem problem = new ModelProblem("problem"); var node1 = problem.AddNode(); var force = problem.AddForce(node1); var otherProblem = new ModelProblem("otherProblem"); var strayNode = otherProblem.AddNode(); //Act //Assert Assert.Throws <InvalidOperationException>(() => force.Node = strayNode); }
public void Node_NodeChanged_ExpectModelUpdated() { //Arrange var modelProblem = new ModelProblem("test"); var node1 = modelProblem.AddNode(); var node2 = modelProblem.AddNode(); var modelForce = modelProblem.AddForce(node1); var nodeViewModel1 = new NodeViewModel(node1); var nodeViewModel2 = new NodeViewModel(node2); var forceViewModel = new ForceViewModel(modelForce, nodeViewModel1); //Act forceViewModel.Node = nodeViewModel2; //Assert Assert.That(modelForce.Node, Is.EqualTo(node2)); }