Ejemplo n.º 1
0
        public async Task CreateTwoRoleAssignments()
        {
            var roleAssignmentGuids = new[] { roleAssignment1Guid, roleAssignment2Guid };

            (var httpClient, var httpHandler) = FakeDigitalTwinsHttpClient.Create(
                postResponseGuids: roleAssignmentGuids
                );

            var descriptions = new [] {
                new RoleAssignmentDescription()
                {
                    objectId     = "10000000-0000-0000-0000-000000000001",
                    objectIdType = "UserId",
                    path         = "/",
                    roleId       = "10000000-0000-0000-0000-000000000002",
                    tenantId     = "10000000-0000-0000-0000-000000000003",
                },
                new RoleAssignmentDescription()
                {
                    objectId     = "20000000-0000-0000-0000-000000000001",
                    objectIdType = "UserId",
                    path         = "/",
                    roleId       = "20000000-0000-0000-0000-000000000002",
                    tenantId     = "20000000-0000-0000-0000-000000000003",
                },
            };

            Assert.Equal(roleAssignmentGuids,
                         await Actions.CreateRoleAssignments(httpClient, Loggers.SilentLogger, descriptions));
            Assert.Equal(2, httpHandler.PostRequests["roleassignments"].Count);
            Assert.False(httpHandler.GetRequests.ContainsKey("roleassignments"));
        }
        public async Task CreateTwoEndpoints()
        {
            var endpointGuids = new[] { endpoint1Guid, endpoint2Guid };

            (var httpClient, var httpHandler) = FakeDigitalTwinsHttpClient.Create(
                postResponseGuids: endpointGuids
                );

            var descriptions = new [] {
                new EndpointDescription()
                {
                    type                      = "Type1",
                    eventTypes                = new [] { "EventType1", "EventType2" },
                    connectionString          = "connectionString1",
                    secondaryConnectionString = "connectionString2",
                    path                      = "path1",
                },
                new EndpointDescription()
                {
                    type                      = "TypeA",
                    eventTypes                = new [] { "EventTypeA", "EventTypeB" },
                    connectionString          = "connectionStringA",
                    secondaryConnectionString = "connectionStringB",
                    path                      = "pathA",
                },
            };

            Assert.Equal(endpointGuids,
                         await Actions.CreateEndpoints(httpClient, Loggers.SilentLogger, descriptions));
            Assert.Equal(2, httpHandler.PostRequests["endpoints"].Count);
            Assert.False(httpHandler.GetRequests.ContainsKey("endpoints"));
        }
Ejemplo n.º 3
0
        public async Task CreateSpacesWithSingleRootAndChildrenMakesRequestsAndReturnsRootId()
        {
            (var httpClient, var httpHandler) = FakeDigitalTwinsHttpClient.Create(
                postResponseGuids: new [] { guid1, guid2, guid3 },
                getResponses: Enumerable.Repeat(Responses.NotFound, 1000));

            var descriptions = new [] { new SpaceDescription()
                                        {
                                            name   = "Test1",
                                            spaces = new [] {
                                                new SpaceDescription()
                                                {
                                                    name = "Child1",
                                                },
                                                new SpaceDescription()
                                                {
                                                    name = "Child2",
                                                }
                                            },
                                        } };

            var results = await Actions.CreateSpaces(httpClient, Loggers.SilentLogger, descriptions, Guid.Empty);

            Assert.Equal(guid1, results.Single().Id);
            Assert.Equal(3, httpHandler.PostRequests["spaces"].Count);
            Assert.Equal(3, httpHandler.GetRequests["spaces"].Count);
        }
Ejemplo n.º 4
0
        public async Task CreateSpacesWithNoDescriptionsReturnsEmptyAndMakesNoRequests()
        {
            (var httpClient, var httpHandler) = FakeDigitalTwinsHttpClient.Create();

            var results = await Actions.CreateSpaces(httpClient, Loggers.SilentLogger, Array.Empty <SpaceDescription>(), Guid.Empty);

            Assert.Equal(0, results.Count());
            Assert.False(httpHandler.PostRequests.ContainsKey("spaces"));
            Assert.False(httpHandler.GetRequests.ContainsKey("spaces"));
        }
Ejemplo n.º 5
0
        public async Task CreateSpacesWithMultipleRootsMakesRequestsAndReturnsAllRootIds()
        {
            (var httpClient, var httpHandler) = FakeDigitalTwinsHttpClient.Create(
                postResponseGuids: new [] { guid1, guid2 },
                getResponses: Enumerable.Repeat(Responses.NotFound, 1000));

            var descriptions = new []
            {
                new SpaceDescription()
                {
                    name = "Test1",
                },
                new SpaceDescription()
                {
                    name = "Test2",
                }
            };

            var results = await Actions.CreateSpaces(httpClient, Loggers.SilentLogger, descriptions, Guid.Empty);

            Assert.Equal(new [] { guid1, guid2 }, results.Select(r => r.Id));
            Assert.Equal(2, httpHandler.PostRequests["spaces"].Count);
            Assert.Equal(2, httpHandler.GetRequests["spaces"].Count);
        }