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));
        }
示例#3
0
        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));
        }
示例#4
0
        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));
        }
示例#5
0
        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));
        }
示例#6
0
        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);
        }
示例#7
0
        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));
        }
示例#8
0
        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);
        }
示例#9
0
        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);
        }
示例#10
0
        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));
        }
示例#11
0
        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);
        }
示例#12
0
        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);
        }
示例#13
0
        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);
        }
示例#14
0
        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));
        }
示例#15
0
        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);
        }
示例#16
0
        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);
        }
示例#17
0
        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));
        }
示例#18
0
        private static IModelNode BuildTestNode()
        {
            var modelProblem = new ModelProblem("test");

            var node = modelProblem.AddNode();

            return(node);
        }
示例#19
0
        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));
        }
示例#20
0
        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);
        }
示例#21
0
        public void AddElement_BothNodesAreTheSame_ExpectInvalidOperationException()
        {
            //Arrange
            var modelProblem = new ModelProblem("problem");

            var origin = modelProblem.AddNode();

            //Act
            //Assert
            Assert.Throws <InvalidOperationException>(() => modelProblem.AddElement(origin, origin));
        }
示例#22
0
        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);
        }
示例#23
0
        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);
        }
示例#24
0
        public void AddElement_NullDestinationNode_ExpectArgumentNullException()
        {
            //Arrange
            var modelProblem = new ModelProblem("problem");

            var node = modelProblem.AddNode();

            //Act
            //Assert
            Assert.Throws <ArgumentNullException>(() => modelProblem.AddElement(node, null));
        }
示例#25
0
        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);
        }
示例#28
0
        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));
        }
示例#29
0
        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);
        }
示例#30
0
        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);
        }