Beispiel #1
0
        public void Build_ModelWithMultipleChildren_ComponentMappingsSorted()
        {
            // Arrange
            ArdoqModelMappingBuilder builder = Builder();

            // Act
            builder.AddComponentMapping <Role>("Role")
            .WithKey(s => s.Name);
            builder.AddComponentMapping <Department>("Department")
            .WithKey(s => s.Name);
            builder.AddComponentMapping <Office>("Office")
            .WithKey(s => s.Name);
            builder.AddComponentMapping <Employee>("Employee")
            .WithKey(s => s.Name)
            .WithModelledHierarchyReference(e => e.EmployedIn, ModelledReferenceDirection.Child)
            .WithModelledHierarchyReference(e => e.Roles, ModelledReferenceDirection.Parent)
            .WithModelledHierarchyReference(e => e.Office, ModelledReferenceDirection.Parent);
            builder.Build();

            // Assert
            var list = builder.ComponentMappings.ToList();

            Assert.Equal("Department", list[0].ArdoqComponentTypeName);
            Assert.Equal("Employee", list[1].ArdoqComponentTypeName);
            Assert.Equal(new HashSet <string> {
                "Role", "Office"
            }, new HashSet <string> {
                list[2].ArdoqComponentTypeName, list[3].ArdoqComponentTypeName
            });
        }
    public static void Main(string[] args)
    {
        var ardoqUrl          = "https://app.ardoq.com/";
        var ardoqToken        = "<secret-ardoq-token>";
        var ardoqOrganization = "<ardoq-org>";
        var workspace         = "<ardoq-workspace>";
        var folder            = "<ardoq-folder>";

        // Create a builder
        var builder =
            new ArdoqModelMappingBuilder(ardoqUrl, ardoqToken, ardoqOrganization)
            .WithWorkspaceNamed(workspace)
            .WithFolderNamed(folder);

        // Add your structured model. This must match the model in Ardoq.
        builder.AddComponentMapping <MyComponent>("MyComponent")
        .WithKey(s => s.MyKey);

        // Create the source model provider. This supplies the objects which will be documented in Ardoq.
        ISourceModelProvider sourceModelProvider = new MySourceModelProvider();

        // Build and run
        var session = builder.Build();

        session.Run(sourceModelProvider).Wait();
    }
Beispiel #3
0
        public void Run_WorkspaceDoesNotExistAndNoTemplateSet_ThrowsException()
        {
            // Arrange
            string folderName = "MyFolder";

            _readerMock.Setup(r => r.GetFolder(folderName))
            .Returns(Task.FromResult(new Folder(folderName, "My folder")
            {
                Workspaces = new List <string>()
            }));

            var builder = new ArdoqModelMappingBuilder(null, null, null)
                          .WithWorkspaceNamed("Test")
                          .WithFolderNamed(folderName)
                          .WithReader(_readerMock.Object)
                          .WithWriter(_writerMock.Object)
                          .WithSearcher(_searcherMock.Object);

            var session = builder.Build();

            // Act
            var ex = Assert.Throws <AggregateException>(() => session.Run(_modelProviderMock.Object).Wait());

            Assert.True(ex.InnerExceptions.First() is InvalidOperationException);
            var inner = ex.InnerExceptions.First();

            Assert.Equal("Template name must be set when creating workspace.", inner.Message);
        }
Beispiel #4
0
        public void Build_ProperModel_ParentsComputedCorrectly()
        {
            // Arrange
            ArdoqModelMappingBuilder builder = Builder();

            // Act
            builder.AddComponentMapping <Department>("Department")
            .WithKey(s => s.Name);
            builder.AddComponentMapping <Employee>("Employee")
            .WithKey(s => s.Name)
            .WithModelledHierarchyReference(e => e.EmployedIn, ModelledReferenceDirection.Child)
            .WithModelledHierarchyReference(e => e.Roles, ModelledReferenceDirection.Parent);
            builder.AddComponentMapping <Role>("Role")
            .WithKey(s => s.Name);
            builder.Build();

            // Assert
            var list = builder.ComponentMappings.ToList();

            Assert.Equal("Department", list[0].ArdoqComponentTypeName);
            Assert.Null(list[0].GetParent()?.ArdoqComponentTypeName);
            Assert.Equal("Employee", list[1].ArdoqComponentTypeName);
            Assert.Equal("Department", list[1].GetParent().ArdoqComponentTypeName);
            Assert.Equal("Role", list[2].ArdoqComponentTypeName);
            Assert.Equal("Employee", list[2].GetParent().ArdoqComponentTypeName);
        }
Beispiel #5
0
        public void Build_EmptyModel_ReturnsEmptyMap()
        {
            // Arrange
            ArdoqModelMappingBuilder builder = Builder();

            // Act
            builder.Build();

            // Assert
            Assert.Empty(builder.ComponentMappings);
        }
Beispiel #6
0
        public void WithSafeMode_NotSpecified_IsNotSafeMode()
        {
            // Arrange
            var builder = new ArdoqModelMappingBuilder(null, null, null);

            // Act
            builder
            .WithReader(_readerMock.Object)
            .WithWriter(_writerMock.Object)
            .WithSearcher(_searcherMock.Object);

            var session = builder.Build();

            // Assert
            Assert.False(session.IsSafeMode);
        }
Beispiel #7
0
        public void Build_ModelNotValid_ThrowsException()
        {
            // Arrange
            ArdoqModelMappingBuilder builder = Builder();

            // Act
            builder.AddComponentMapping <Role>("Role")
            .WithKey(s => s.Name);
            builder.AddComponentMapping <Employee>("Employee")
            .WithKey(s => s.Name)
            .WithModelledHierarchyReference(e => e.EmployedIn, ModelledReferenceDirection.Child)
            .WithModelledHierarchyReference(e => e.Roles, ModelledReferenceDirection.Parent);

            // Assert
            Assert.ThrowsAny <Exception>(() => builder.Build());
        }
Beispiel #8
0
        public void GetComponentType_TypeNotRegistered_ReturnsNull()
        {
            // Arrange
            var builder = new ArdoqModelMappingBuilder(null, null, null)
                          .WithReader(_readerMock.Object)
                          .WithWriter(_writerMock.Object)
                          .WithSearcher(_searcherMock.Object);

            var session = builder.Build();

            // Act
            var comType = session.GetComponentType(typeof(Employee));

            // Assert
            Assert.Null(comType);
        }
Beispiel #9
0
        public void GetComponentType_AfterRegistration_GetsExpectedComponentType()
        {
            // Arrange
            var componentTypeEmployee = "EmployeeCompType";
            var builder = new ArdoqModelMappingBuilder(null, null, null)
                          .WithReader(_readerMock.Object)
                          .WithWriter(_writerMock.Object)
                          .WithSearcher(_searcherMock.Object);

            builder.AddComponentMapping <Employee>(componentTypeEmployee);

            var session = builder.Build();

            // Act
            var comType = session.GetComponentType(typeof(Employee));

            // Assert
            Assert.Equal(componentTypeEmployee, comType);
        }
Beispiel #10
0
        public void GetKeyForInstance_NotRegistered_ReturnsNull()
        {
            var builder = new ArdoqModelMappingBuilder(null, null, null)
                          .WithReader(_readerMock.Object)
                          .WithWriter(_writerMock.Object)
                          .WithSearcher(_searcherMock.Object);

            var employeeNumber = "007";
            var employee       = new Employee {
                EmployeeNumber = employeeNumber
            };

            var session = builder.Build();

            // Act
            var key = session.GetKeyForInstance(employee);

            // Assert
            Assert.Null(key);
        }
Beispiel #11
0
        public void Run_WorkspaceDoesNotExistHasTemplate_CreatesNewWorkspace()
        {
            // Arrange
            string workspaceName  = "Test";
            string folderName     = "MyFolder";
            string componentModel = "5bab5cc8b3da08632a73ed2f";
            string folderId       = "folder-id";

            var folder = new Folder(folderName, "My folder")
            {
                Id = folderId, Workspaces = new List <string>()
            };

            _readerMock.Setup(r => r.GetFolder(folderName))
            .Returns(Task.FromResult(folder));

            _readerMock.Setup(r => r.GetTemplateByName(componentModel))
            .Returns(Task.FromResult((IArdoqModel) new ArdoqModel(new global::Ardoq.Models.Model()
            {
                Id = "666"
            })));

            _writerMock.Setup(w => w.CreateWorkspace(It.IsAny <Workspace>()))
            .Returns(Task.FromResult(new Workspace(workspaceName, "")));

            var builder = new ArdoqModelMappingBuilder(null, null, null)
                          .WithWorkspaceNamed(workspaceName)
                          .WithFolderNamed(folderName)
                          .WithTemplate(componentModel)
                          .WithReader(_readerMock.Object)
                          .WithWriter(_writerMock.Object)
                          .WithSearcher(_searcherMock.Object);

            var session = builder.Build();

            // Act
            session.Run(_modelProviderMock.Object).Wait();

            // Assert
            _writerMock.Verify(w => w.CreateWorkspace(It.IsAny <Workspace>()));
        }
Beispiel #12
0
        public static void Main(string[] args)
        {
            var config   = IoC.GetConfiguration();
            var provider = IoC.Resolve <ISourceModelProvider>();

            var builder =
                new ArdoqModelMappingBuilder(config["Ardoq:url"], config["Ardoq:token"], config["Ardoq:organization"])
                .WithWorkspaceNamed(config["Ardoq:workspaceName"])
                .WithFolderNamed(config["Ardoq:folderName"])
                .WithTemplate(config["Ardoq:templateName"]);

            var module = new AzureMaintenanceModule();

            module.Configure(builder);

            var session = builder.Build();

            session.Run(provider).Wait();

            Task.Delay(1000).Wait();
        }
Beispiel #13
0
        public void GetKeyForInstance_RegisteredType_ReturnsExpectedKey()
        {
            var componentTypeEmployee = "EmployeeCompType";
            var builder = new ArdoqModelMappingBuilder(null, null, null)
                          .WithReader(_readerMock.Object)
                          .WithSearcher(_searcherMock.Object)
                          .WithWriter(_writerMock.Object);

            builder.AddComponentMapping <Employee>(componentTypeEmployee)
            .WithKey(emp => emp.EmployeeNumber);

            var employeeNumber = "007";
            var employee       = new Employee {
                EmployeeNumber = employeeNumber
            };

            var session = builder.Build();

            // Act
            var key = session.GetKeyForInstance(employee);

            // Assert
            Assert.Equal(employeeNumber, key);
        }