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" })); }
private static IModelElement BuildElement() { var modelProblem = new ModelProblem("test"); var node1 = modelProblem.AddNode(); var node2 = modelProblem.AddNode(); return(modelProblem.AddElement(node1, node2)); }
public void DeleteMaterial_MaterialIsUsedByElement_ExpectInvalidOperationException() { //Arrange var modelProblem = new ModelProblem("problem"); var element = modelProblem.AddElement(modelProblem.AddNode(), modelProblem.AddNode()); //Act //Assert Assert.Throws <InvalidOperationException>(() => modelProblem.DeleteMaterial(element.Material)); }
public void DeleteNode_NodeIsUsedByElementInDestinationNode_ExpectInvalidOperationException() { //Arrange var modelProblem = new ModelProblem("problem"); var node = modelProblem.AddNode(); var element = modelProblem.AddElement(modelProblem.AddNode(), node); //Act //Assert Assert.Throws <InvalidOperationException>(() => modelProblem.DeleteNode(node)); }
public void AddElement_EmptyProblem_ExpectElementIdCorrectlyInitialized() { //Arrange var modelProblem = new ModelProblem("problem"); var origin = modelProblem.AddNode(); var destination = modelProblem.AddNode(); //Act var element = modelProblem.AddElement(origin, destination); //Assert Assert.That(element.Id, Is.EqualTo(1)); }
public void AddElement_EmptyProblem_ExpectElementMaterialAddedToCollection() { //Arrange var modelProblem = new ModelProblem("problem"); var origin = modelProblem.AddNode(); var destination = modelProblem.AddNode(); //Act var element = modelProblem.AddElement(origin, destination); //Assert Assert.That(modelProblem.Materials.Contains(element.Material), Is.True); }
public void AddElement_ElementWithSameNodesAlreadyExists_ExpectInvalidOperationException() { //Arrange var modelProblem = new ModelProblem("problem"); var origin = modelProblem.AddNode(); var destination = modelProblem.AddNode(); modelProblem.AddElement(origin, destination); //Act //Assert Assert.Throws <InvalidOperationException>(() => modelProblem.AddElement(origin, destination)); }
public void ValidateElements_MakeElementHaveSameNodeAsDestinationAndOrigin_ExpectInvalidOperationException() { //Arrange ModelProblem problem = new ModelProblem("problem"); var node1 = problem.AddNode(); var node2 = problem.AddNode(); var element = problem.AddElement(node1, node2); //Act //Assert Assert.Throws <InvalidOperationException>(() => element.OriginNode = node2); }
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 AddNode_ProblemWithNodes_ExpectNodeIdCorrectlyInitialized() { //Arrange var modelProblem = new ModelProblem("problem"); modelProblem.AddNode(); modelProblem.AddNode(); modelProblem.AddNode(); //Act var node = modelProblem.AddNode(); //Assert Assert.That(node.Id, Is.EqualTo(4)); }
public (NodeViewModel, NodeViewModel, MaterialViewModel, IModelElement) BuildTestElement() { var modelProblem = new ModelProblem("test"); var node1 = modelProblem.AddNode(); var node2 = modelProblem.AddNode(); var element = modelProblem.AddElement(node1, node2); var nodeViewModel1 = new NodeViewModel(node1); var nodeViewModel2 = new NodeViewModel(node2); var materialViewModel = new MaterialViewModel(element.Material); return(nodeViewModel1, nodeViewModel2, materialViewModel, element); }
public void ValidateElement_SetStrayNodeAsDestinationNode_ExpectInvalidOperationException() { //Arrange ModelProblem problem = new ModelProblem("problem"); var node1 = problem.AddNode(); var node2 = problem.AddNode(); var element = problem.AddElement(node1, node2); var otherProblem = new ModelProblem("otherProblem"); var strayNode = otherProblem.AddNode(); //Act //Assert Assert.Throws <InvalidOperationException>(() => element.DestinationNode = strayNode); }
public void ValidateElement_SetStraMaterial_ExpectInvalidOperationException() { //Arrange ModelProblem problem = new ModelProblem("problem"); var node1 = problem.AddNode(); var node2 = problem.AddNode(); var element = problem.AddElement(node1, node2); var otherProblem = new ModelProblem("otherProblem"); var material = otherProblem.AddMaterial(); //Act //Assert Assert.Throws <InvalidOperationException>(() => element.Material = material); }
public void AddElement_ProblemWithMaterials_ExpectNoNewMaterialWasCreated() { //Arrange var modelProblem = new ModelProblem("problem"); var origin = modelProblem.AddNode(); var destination = modelProblem.AddNode(); modelProblem.AddElement(modelProblem.AddNode(), modelProblem.AddNode()); //Act var element = modelProblem.AddElement(origin, destination); //Assert Assert.That(modelProblem.Materials.Count(), Is.EqualTo(1)); }
public void ValidateElements_MakeElementHaveSameNodesAsOtherElementBySettingDestinationNode_ExpectInvalidOperationException() { //Arrange ModelProblem problem = new ModelProblem("problem"); var node1 = problem.AddNode(); var node2 = problem.AddNode(); var node3 = problem.AddNode(); var element1 = problem.AddElement(node2, node1); var element2 = problem.AddElement(node2, node3); //Act //Assert Assert.Throws <InvalidOperationException>(() => element2.DestinationNode = node1); }
public void DeleteElement_ElementDoesExistInProblem_ExpectElementMaterialRemovedFromCollection() { //Arrange var modelProblem = new ModelProblem("problem"); var origin = modelProblem.AddNode(); var destination = modelProblem.AddNode(); var element = modelProblem.AddElement(origin, destination); //Act modelProblem.DeleteElement(element); //Assert Assert.That(modelProblem.Elements, Is.Empty); }
public void AddElement_ProblemWithMaterials_ExpectElementMaterialIsExistingMaterial() { //Arrange var modelProblem = new ModelProblem("problem"); var origin = modelProblem.AddNode(); var destination = modelProblem.AddNode(); var otherElement = modelProblem.AddElement(modelProblem.AddNode(), modelProblem.AddNode()); //Act var element = modelProblem.AddElement(origin, destination); //Assert Assert.That(element.Material, Is.EqualTo(otherElement.Material)); }
private static IModelNode BuildTestNode() { var modelProblem = new ModelProblem("test"); var node = modelProblem.AddNode(); return(node); }
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)); }
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 AddElement_BothNodesAreTheSame_ExpectInvalidOperationException() { //Arrange var modelProblem = new ModelProblem("problem"); var origin = modelProblem.AddNode(); //Act //Assert Assert.Throws <InvalidOperationException>(() => modelProblem.AddElement(origin, origin)); }
public void AddNode_EmptyProblem_ExpectNodeAddedToCollection() { //Arrange var modelProblem = new ModelProblem("problem"); //Act var node = modelProblem.AddNode(); //Assert Assert.That(modelProblem.Nodes.Contains(node), Is.True); }
public void DeleteNode_ProblemWithSeveralNodes_ExpectNodeIdsAreCorrect() { //Arrange var modelProblem = new ModelProblem("problem"); var node1 = modelProblem.AddNode(); var node2 = modelProblem.AddNode(); var node3 = modelProblem.AddNode(); var node4 = modelProblem.AddNode(); var node5 = modelProblem.AddNode(); //Act modelProblem.DeleteNode(node1); //Assert Assert.AreEqual(node2.Id, 1); Assert.AreEqual(node3.Id, 2); Assert.AreEqual(node4.Id, 3); Assert.AreEqual(node5.Id, 4); }
public void AddElement_NullDestinationNode_ExpectArgumentNullException() { //Arrange var modelProblem = new ModelProblem("problem"); var node = modelProblem.AddNode(); //Act //Assert Assert.Throws <ArgumentNullException>(() => modelProblem.AddElement(node, 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 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)); }
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 AddElement_InvalidOriginNode_ExpectInvalidOperationException() { //Arrange var modelProblem = new ModelProblem("problem"); var origin = new ModelNode(new ModelProblem("otherProblem"), 123); var destination = modelProblem.AddNode(); //Act //Assert Assert.Throws <InvalidOperationException>(() => modelProblem.AddElement(origin, destination)); }
public void DeleteNode_NodeDoesExistInProblem_ExpectNodeRemovedFromCollection() { //Arrange var modelProblem = new ModelProblem("problem"); var node = modelProblem.AddNode(); //Act modelProblem.DeleteNode(node); //Assert Assert.That(modelProblem.Nodes, Is.Empty); }
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); }