コード例 #1
0
        public async Task CreateTwoUdfRoleAssignments()
        {
            (var httpClient, var httpHandler) = FakeDigitalTwinsHttpClient.CreateWithSpace(
                postResponseGuids: new [] { roleAssignmentGuid1, roleAssignmentGuid2 },
                getResponses: new [] { space1GetResponse, function1GetResponse, function2GetResponse }
                );

            var descriptions = new [] { new SpaceDescription()
                                        {
                                            name            = FakeDigitalTwinsHttpClient.Space.Name,
                                            roleassignments = new [] {
                                                new RoleAssignmentDescription()
                                                {
                                                    roleId       = roleIdGuid.ToString(),
                                                    objectName   = "Function 1",
                                                    objectIdType = "UserDefinedFunctionId"
                                                },
                                                new RoleAssignmentDescription()
                                                {
                                                    roleId       = roleIdGuid.ToString(),
                                                    objectName   = "Function 2",
                                                    objectIdType = "UserDefinedFunctionId"
                                                }
                                            },
                                        } };

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

            Assert.Equal(2, httpHandler.PostRequests["roleassignments"].Count);
            Assert.Equal(2, httpHandler.GetRequests["userdefinedfunctions"].Count);
            Assert.False(httpHandler.GetRequests.ContainsKey("roleassignments"));
        }
コード例 #2
0
        public async Task CreateRoleAssignmentWithUnknownTypeAndNameFails()
        {
            // How 'objectName' is used is based on objectIdType. In this test we choose an unknow type
            // and expect it then to fail the role assignment creation since it doesn't know how to use the name

            (var httpClient, var httpHandler) = FakeDigitalTwinsHttpClient.CreateWithSpace(
                postResponseGuids: null,
                getResponses: new [] { space1GetResponse }
                );

            var descriptions = new [] { new SpaceDescription()
                                        {
                                            name            = FakeDigitalTwinsHttpClient.Space.Name,
                                            roleassignments = new [] {
                                                new RoleAssignmentDescription()
                                                {
                                                    roleId       = roleIdGuid.ToString(),
                                                    objectName   = "SomeName",
                                                    objectIdType = "UnknownObjectIdType"
                                                }
                                            },
                                        } };

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

            Assert.False(httpHandler.PostRequests.ContainsKey("roleassignments"));
        }
コード例 #3
0
        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"));
        }
コード例 #4
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"));
        }
コード例 #5
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);
        }
コード例 #6
0
        public async Task UpdateUserDefinedFunction()
        {
            (var httpClient, var httpHandler) = FakeDigitalTwinsHttpClient.CreateWithSpace(
                postResponseGuids: new [] { udfGuid1, udfGuid2 },
                getResponses: new [] { matcher1GetResponse, udf1GetResponse },
                patchResponses: new [] { Responses.OK }
                );

            var descriptions = new [] { new SpaceDescription()
                                        {
                                            name = FakeDigitalTwinsHttpClient.Space.Name,
                                            userdefinedfunctions = new [] {
                                                new UserDefinedFunctionDescription()
                                                {
                                                    name         = "Function 1",
                                                    matcherNames = new [] { "Matcher1" },
                                                    script       = "userDefinedFunctions/function1.js",
                                                }
                                            },
                                        } };

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

            Assert.False(httpHandler.PostRequests.ContainsKey("userdefinedfunctions"));
            Assert.Equal(1, httpHandler.PatchRequests["userdefinedfunctions"].Count);
            Assert.Equal(1, httpHandler.GetRequests["matchers"].Count);
            Assert.Equal(1, httpHandler.GetRequests["userdefinedfunctions"].Count);
        }
コード例 #7
0
        public async Task CreateTwoMatchers()
        {
            (var httpClient, var httpHandler) = FakeDigitalTwinsHttpClient.CreateWithSpace(
                postResponseGuids: new [] { matcher1Guid, matcher2Guid },
                getResponses: null
                );

            var descriptions = new [] { new SpaceDescription()
                                        {
                                            name     = FakeDigitalTwinsHttpClient.Space.Name,
                                            matchers = new [] {
                                                new MatcherDescription()
                                                {
                                                    name          = "Matcher1",
                                                    dataTypeValue = "DataType1",
                                                },
                                                new MatcherDescription()
                                                {
                                                    name          = "Matcher2",
                                                    dataTypeValue = "DataType2",
                                                }
                                            },
                                        } };

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

            Assert.Equal(2, httpHandler.PostRequests["matchers"].Count);
            Assert.False(httpHandler.GetRequests.ContainsKey("matchers"));
        }
コード例 #8
0
        public async Task CreateTwoSensors()
        {
            (var httpClient, var httpHandler) = FakeDigitalTwinsHttpClient.CreateWithDevice(
                postResponseGuids: new [] { sensor1Guid, sensor2Guid },
                getResponses: Enumerable.Repeat(Responses.NotFound, 2)
                );

            var descriptions = new [] { new SpaceDescription()
                                        {
                                            name    = FakeDigitalTwinsHttpClient.Space.Name,
                                            devices = new [] {
                                                new DeviceDescription()
                                                {
                                                    name       = FakeDigitalTwinsHttpClient.Device.Name,
                                                    hardwareId = FakeDigitalTwinsHttpClient.Device.HardwareId,
                                                    sensors    = new [] {
                                                        new SensorDescription()
                                                        {
                                                            dataType   = "SensorType1",
                                                            hardwareId = "SensorHardwareId1",
                                                        },
                                                        new SensorDescription()
                                                        {
                                                            dataType   = "SensorType2",
                                                            hardwareId = "SensorHardwareId2",
                                                        }
                                                    }
                                                }
                                            },
                                        } };

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

            Assert.Equal(2, httpHandler.PostRequests["sensors"].Count);
        }
コード例 #9
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"));
        }
コード例 #10
0
        public async Task CreateSpacesWithAlreadyCreatedSpaceUsesIt()
        {
            (var httpClient, var httpHandler) = FakeDigitalTwinsHttpClient.CreateWithSpace(
                postResponseGuids: new [] { guid1 },
                space: space1);

            var descriptions = new [] { new SpaceDescription()
                                        {
                                            name = space1.Name,
                                        } };

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

            Assert.Equal(guid1, results.Single().Id);
            Assert.False(httpHandler.PostRequests.ContainsKey("spaces"));
            Assert.Equal(1, httpHandler.GetRequests["spaces"].Count);
        }
コード例 #11
0
        public async Task CreateTwoDevices()
        {
            (var httpClient, var httpHandler) = FakeDigitalTwinsHttpClient.CreateWithSpace(
                postResponseGuids: new [] { device1Guid, device2Guid },
                getResponses: new [] { Responses.NotFound, getDeviceResponse_device1, Responses.NotFound, getDeviceResponse_device2 }
                );

            var descriptions = new [] { new SpaceDescription()
                                        {
                                            name    = FakeDigitalTwinsHttpClient.Space.Name,
                                            devices = new [] {
                                                new DeviceDescription()
                                                {
                                                    name       = "Device1",
                                                    hardwareId = "HardwareId1",
                                                },
                                                new DeviceDescription()
                                                {
                                                    name       = "Device2",
                                                    hardwareId = "HardwareId2",
                                                }
                                            },
                                        } };

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

            Assert.Equal(2, httpHandler.PostRequests["devices"].Count);
            Assert.Equal(4, httpHandler.GetRequests["devices"].Count);
            Assert.Equal(new [] {
                new ProvisionResults.Device()
                {
                    ConnectionString = "ConnectionString1",
                    HardwareId       = "HardwareId1",
                },
                new ProvisionResults.Device()
                {
                    ConnectionString = "ConnectionString2",
                    HardwareId       = "HardwareId2",
                }
            },
                         spaceResult.Devices);
        }
コード例 #12
0
        public async Task CreateSingleResource()
        {
            (var httpClient, var httpHandler) = FakeDigitalTwinsHttpClient.CreateWithSpace(
                postResponseGuids: new [] { resource1Guid },
                getResponses: new [] { resource1GetResponse });

            var descriptions = new [] { new SpaceDescription()
                                        {
                                            name      = FakeDigitalTwinsHttpClient.Space.Name,
                                            resources = new [] { new ResourceDescription()
                                                                 {
                                                                     type = "ResourceType",
                                                                 } },
                                        } };

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

            Assert.Equal(1, httpHandler.PostRequests["resources"].Count);
            Assert.Equal(1, httpHandler.GetRequests["resources"].Count);
        }
コード例 #13
0
        public async Task CreateTwoUserDefinedFunctions()
        {
            (var httpClient, var httpHandler) = FakeDigitalTwinsHttpClient.CreateWithSpace(
                postResponseGuids: new [] { udfGuid1, udfGuid2 },
                getResponses: new [] { matchers1And2GetResponse, Responses.NotFound, matcher1GetResponse, Responses.NotFound }
                );

            var descriptions = new [] { new SpaceDescription()
                                        {
                                            name = FakeDigitalTwinsHttpClient.Space.Name,
                                            userdefinedfunctions = new [] {
                                                new UserDefinedFunctionDescription()
                                                {
                                                    name         = "Function 1",
                                                    matcherNames = new [] { "Matcher1", "Matcher2" },
                                                    script       = "userDefinedFunctions/function1.js",
                                                },
                                                new UserDefinedFunctionDescription()
                                                {
                                                    name         = "Function 2",
                                                    matcherNames = new [] { "Matcher1" },
                                                    script       = "userDefinedFunctions/function2.js",
                                                }
                                            },
                                        } };

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

            Assert.Equal(2, httpHandler.PostRequests["userdefinedfunctions"].Count);
            Assert.Equal(2, httpHandler.GetRequests["matchers"].Count);
            Assert.Equal(
                "http://bing.com/matchers?names=Matcher1,Matcher2&spaceIds=90000000-0000-0000-0000-000000000001",
                httpHandler.GetRequests["matchers"][0].RequestUri.ToString());
            Assert.Equal(
                "http://bing.com/matchers?names=Matcher1&spaceIds=90000000-0000-0000-0000-000000000001",
                httpHandler.GetRequests["matchers"][1].RequestUri.ToString());
            Assert.Equal(2, httpHandler.GetRequests["userdefinedfunctions"].Count);
        }
コード例 #14
0
        public async Task CreateDeviceReusesMatchingPreexistingDevice()
        {
            (var httpClient, var httpHandler) = FakeDigitalTwinsHttpClient.CreateWithSpace(
                postResponseGuids: null,
                getResponses: new [] { getDevicesResponse_device1, getDeviceResponse_device1 }
                );

            var descriptions = new [] { new SpaceDescription()
                                        {
                                            name    = FakeDigitalTwinsHttpClient.Space.Name,
                                            devices = new [] {
                                                new DeviceDescription()
                                                {
                                                    name       = device1.Name,
                                                    hardwareId = device1.HardwareId,
                                                }
                                            },
                                        } };

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

            Assert.False(httpHandler.PostRequests.ContainsKey("devices"));
            Assert.Equal(2, httpHandler.GetRequests["devices"].Count);
        }
コード例 #15
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);
        }