public void Test_CopyLayoutInformationFrom() { Workspace workspace1 = new Workspace("", ""); Model model1 = workspace1.Model; SoftwareSystem softwareSystem1A = model1.AddSoftwareSystem("System A", "Description"); SoftwareSystem softwareSystem1B = model1.AddSoftwareSystem("System B", "Description"); Person person1 = model1.AddPerson("Person", "Description"); Relationship personUsesSoftwareSystem1 = person1.Uses(softwareSystem1A, "Uses"); // create a view with SystemA and Person (locations are set for both, relationship has vertices) StaticView staticView1 = new SystemContextView(softwareSystem1A, "context", "Description"); staticView1.Add(softwareSystem1B); staticView1.GetElementView(softwareSystem1B).X = 123; staticView1.GetElementView(softwareSystem1B).Y = 321; staticView1.Add(person1); staticView1.GetElementView(person1).X = 456; staticView1.GetElementView(person1).Y = 654; staticView1.GetRelationshipView(personUsesSoftwareSystem1).Vertices = new List <Vertex>() { new Vertex(123, 456) }; staticView1.GetRelationshipView(personUsesSoftwareSystem1).Position = 70; staticView1.GetRelationshipView(personUsesSoftwareSystem1).Routing = Routing.Orthogonal; // and create a dynamic view, as they are treated slightly differently DynamicView dynamicView1 = new DynamicView(model1, "dynamic", "Description"); dynamicView1.Add(person1, "Overridden description", softwareSystem1A); dynamicView1.GetElementView(person1).X = 111; dynamicView1.GetElementView(person1).Y = 222; dynamicView1.GetElementView(softwareSystem1A).X = 333; dynamicView1.GetElementView(softwareSystem1A).Y = 444; dynamicView1.GetRelationshipView(personUsesSoftwareSystem1).Vertices = new List <Vertex>() { new Vertex(555, 666) }; dynamicView1.GetRelationshipView(personUsesSoftwareSystem1).Position = 30; dynamicView1.GetRelationshipView(personUsesSoftwareSystem1).Routing = Routing.Direct; Workspace workspace2 = new Workspace("", ""); Model model2 = workspace2.Model; // creating these in the opposite order will cause them to get different internal IDs SoftwareSystem softwareSystem2B = model2.AddSoftwareSystem("System B", "Description"); SoftwareSystem softwareSystem2A = model2.AddSoftwareSystem("System A", "Description"); Person person2 = model2.AddPerson("Person", "Description"); Relationship personUsesSoftwareSystem2 = person2.Uses(softwareSystem2A, "Uses"); // create a view with SystemB and Person (locations are 0,0 for both) StaticView staticView2 = new SystemContextView(softwareSystem2A, "context", "Description"); staticView2.Add(softwareSystem2B); staticView2.Add(person2); Assert.Equal(0, staticView2.GetElementView(softwareSystem2B).X); Assert.Equal(0, staticView2.GetElementView(softwareSystem2B).Y); Assert.Equal(0, staticView2.GetElementView(softwareSystem2B).X); Assert.Equal(0, staticView2.GetElementView(softwareSystem2B).Y); Assert.Equal(0, staticView2.GetElementView(person2).X); Assert.Equal(0, staticView2.GetElementView(person2).Y); Assert.True(staticView2.GetRelationshipView(personUsesSoftwareSystem2).Vertices.Count == 0); // and create a dynamic view (locations are 0,0) DynamicView dynamicView2 = new DynamicView(model2, "dynamic", "Description"); dynamicView2.Add(person2, "Overridden description", softwareSystem2A); staticView2.CopyLayoutInformationFrom(staticView1); Assert.Equal(0, staticView2.GetElementView(softwareSystem2A).X); Assert.Equal(0, staticView2.GetElementView(softwareSystem2A).Y); Assert.Equal(123, staticView2.GetElementView(softwareSystem2B).X); Assert.Equal(321, staticView2.GetElementView(softwareSystem2B).Y); Assert.Equal(456, staticView2.GetElementView(person2).X); Assert.Equal(654, staticView2.GetElementView(person2).Y); Vertex vertex1 = staticView2.GetRelationshipView(personUsesSoftwareSystem2).Vertices[0]; Assert.Equal(123, vertex1.X); Assert.Equal(456, vertex1.Y); Assert.Equal(70, staticView2.GetRelationshipView(personUsesSoftwareSystem2).Position); Assert.Equal(Routing.Orthogonal, staticView2.GetRelationshipView(personUsesSoftwareSystem2).Routing); dynamicView2.CopyLayoutInformationFrom(dynamicView1); Assert.Equal(111, dynamicView2.GetElementView(person2).X); Assert.Equal(222, dynamicView2.GetElementView(person2).Y); Assert.Equal(333, dynamicView2.GetElementView(softwareSystem2A).X); Assert.Equal(444, dynamicView2.GetElementView(softwareSystem2A).Y); Vertex vertex2 = dynamicView2.GetRelationshipView(personUsesSoftwareSystem2).Vertices[0]; Assert.Equal(555, vertex2.X); Assert.Equal(666, vertex2.Y); Assert.Equal(30, dynamicView2.GetRelationshipView(personUsesSoftwareSystem2).Position); Assert.Equal(Routing.Direct, dynamicView2.GetRelationshipView(personUsesSoftwareSystem2).Routing); }
static void Main(string[] args) { Workspace workspace = new Workspace("Architectural Kata: Make the Grade", "This is a model of the solution to the architectural kata \"Make the Grade\", found at http://nealford.com/katas/list.html."); #region Models Model model = workspace.Model; Person student = model.AddPerson("Student", "A student undertaking a test."); Person grader = model.AddPerson("Grader", "A grader assessing the sudents' test answers."); Person admin = model.AddPerson("Administrator", "A representative of the state authority in education."); SoftwareSystem resultsRepoSubSystem = model.AddSoftwareSystem("Results Repository", "Single location representing all of the test scores across the state."); admin.Uses(resultsRepoSubSystem, "Extracts grading reports."); SoftwareSystem testsCatalogueSubSystem = model.AddSoftwareSystem("Tests Catalogue", "Authoritative source for tests and grading rules."); admin.Uses(testsCatalogueSubSystem, "Administers tests."); SoftwareSystem localTestUnitSubSystem = model.AddSoftwareSystem("Local Testing Unit", "On-premises testing subsystem deployed in each testing center."); student.Uses(localTestUnitSubSystem, "Undertakes tests"); grader.Uses(localTestUnitSubSystem, "Grades students"); localTestUnitSubSystem.Uses(resultsRepoSubSystem, "Push results (batch)"); localTestUnitSubSystem.Uses(testsCatalogueSubSystem, "Pull tests"); Container resultsRepo = resultsRepoSubSystem.AddContainer("Results Database", "Single location representing all of the test scores across the state.", "Microsoft Azure SQL Database"); resultsRepo.AddTags("Database"); Container reportingService = resultsRepoSubSystem.AddContainer("Reporting Service", "A reporting system to know which students have taken the tests and what score they received.", "ASP.NET single page app"); reportingService.Uses(resultsRepo, "Reads from"); Container testsCatalogueService = testsCatalogueSubSystem.AddContainer("Catalogue Service", "Web API provider of latest test and grading rules.", "ASP.NET Web API microservice"); Container testsCatalogueFrontEnd = testsCatalogueSubSystem.AddContainer("Catalogue Front End", "Front end application for administrators managing tests.", "ASP.NET MVC web app"); Container testsRepo = testsCatalogueSubSystem.AddContainer("Tests Repository", "Stores test questions, answers and grading rules.", "NoSQL DBMS"); testsRepo.AddTags("Database"); testsCatalogueFrontEnd.Uses(testsRepo, "Reads from and writes to"); testsCatalogueService.Uses(testsRepo, "Reads from"); Container locatTestResultsStorage = localTestUnitSubSystem.AddContainer("Local Tests Storage", "Stores test answers and grades for students from local testing unit.", "MySQL database"); locatTestResultsStorage.AddTags("Database"); Container testingApp = localTestUnitSubSystem.AddContainer("Testing application", "Allows students to undertake tests and graders to assess them.", "AngularJS web app"); Container testResultQueue = localTestUnitSubSystem.AddContainer("Test results queue", "Asynchronous queue on which an event is placed when a student finishes a test, so that a grader can be notified.", "RabbitMQ"); testResultQueue.AddTags("Queue"); Container evaluator = localTestUnitSubSystem.AddContainer("Evaluator", "Retrieves a finished test, grades the multiple choice answers and gives manual control to graders", ""); Container synchronizer = localTestUnitSubSystem.AddContainer("Synchronizer", "Uploads local test results to central repository", "WCF service"); synchronizer.Uses(resultsRepoSubSystem, "Push results (batch)"); synchronizer.Uses(locatTestResultsStorage, "Read from"); testingApp.Uses(testResultQueue, "Undertake test"); testingApp.Uses(testsCatalogueSubSystem, "Pull tests"); testResultQueue.Uses(evaluator, "Notify grader"); evaluator.Uses(locatTestResultsStorage, "Store and read results"); evaluator.Uses(testsCatalogueSubSystem, "Pull tests"); #endregion #region Views var layoutWorkspace = WorkspaceUtils.LoadWorkspaceFromJson(new FileInfo("layout.json")); ViewSet viewSet = workspace.Views; SystemContextView contextView = viewSet.CreateSystemContextView(testsCatalogueSubSystem, "SystemContext", "A system used for standardized testing across all public school systems grades 3-12."); contextView.AddAllSoftwareSystems(); contextView.AddAllPeople(); contextView.AddNearestNeighbours(testsCatalogueSubSystem); contextView.CopyLayoutInformationFrom(layoutWorkspace.Views.SystemContextViews.FirstOrDefault(x => x.Key == "SystemContext")); ContainerView resultsContainerView = viewSet.CreateContainerView(resultsRepoSubSystem, "ResultsContainer", "The container diagram for the Results Repository Subsystem."); admin.Uses(reportingService, "Extracts reports"); resultsContainerView.Add(admin); resultsContainerView.AddAllContainers(); resultsContainerView.CopyLayoutInformationFrom(layoutWorkspace.Views.ContainerViews.FirstOrDefault(x => x.Key == "ResultsContainer")); ContainerView testsContainerView = viewSet.CreateContainerView(testsCatalogueSubSystem, "TestsContainers", "The container diagram for the Tests Catalogue Subsystem."); admin.Uses(testsCatalogueFrontEnd, "Administers tests"); testsContainerView.Add(admin); testsContainerView.AddAllContainers(); testsContainerView.CopyLayoutInformationFrom(layoutWorkspace.Views.ContainerViews.FirstOrDefault(x => x.Key == "TestsContainers")); ContainerView testUnitContainerView = viewSet.CreateContainerView(localTestUnitSubSystem, "TestUnitsContainers", "The container diagram for the Local Testing Unit Subsystem."); student.Uses(testingApp, "Undertake test"); grader.Uses(evaluator, "Grade test answers"); testUnitContainerView.Add(student); testUnitContainerView.Add(grader); testUnitContainerView.AddAllContainers(); testUnitContainerView.Add(resultsRepoSubSystem); testUnitContainerView.Add(testsCatalogueSubSystem); testUnitContainerView.CopyLayoutInformationFrom(layoutWorkspace.Views.ContainerViews.FirstOrDefault(x => x.Key == "TestUnitsContainers")); Styles styles = viewSet.Configuration.Styles; styles.Add(new ElementStyle(Tags.SoftwareSystem) { Background = "#1168bd", Color = "#ffffff" }); styles.Add(new ElementStyle(Tags.Person) { Background = "#08427b", Color = "#ffffff", Shape = Shape.Person }); styles.Add(new ElementStyle("Database") { Shape = Shape.Cylinder }); styles.Add(new ElementStyle("Queue") { Shape = Shape.Ellipse }); #endregion PushWorkspace(workspace); }