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"));
        }
        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"));
        }
Exemple #3
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);
        }
        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"));
        }
        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);
        }
        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);
        }
        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);
        }
Exemple #8
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);
        }
        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);
        }