Exemplo n.º 1
0
        public void GetDeviceByDeviceUidTest()
        {
            const string DeviceId             = "trn::profilex:us-west-2:device:560c2a6c-6b7e-48d8-b1a5-e4009e2d4c97";
            const string expectedDeviceId     = DeviceId;
            const string expectedDeviceType   = "CB460";
            const string expectedDeviceName   = "The device Name";
            const string expectedSerialNumber = "2002J032SW";

            var deviceResponseModel = new DeviceResponseModel()
            {
                TRN = expectedDeviceId, DeviceType = expectedDeviceType, DeviceName = expectedDeviceName, SerialNumber = expectedSerialNumber
            };

            var route       = $"/devices/{DeviceId}";
            var expectedUrl = $"{baseUrl}{route}";

            mockServiceResolution.Setup(m => m.ResolveRemoteServiceEndpoint(
                                            It.IsAny <string>(), It.IsAny <ApiType>(), It.IsAny <ApiVersion>(), route, It.IsAny <IList <KeyValuePair <string, string> > >())).Returns(Task.FromResult(expectedUrl));

            MockUtilities.TestRequestSendsCorrectJson("Get device by deviceUid", mockWebRequest, null, expectedUrl, HttpMethod.Get, deviceResponseModel, async() =>
            {
                var client = ServiceProvider.GetRequiredService <ICwsDeviceClient>();
                var result = await client.GetDeviceByDeviceUid(TRNHelper.ExtractGuid(DeviceId).Value);

                Assert.NotNull(result);
                Assert.Equal(TRNHelper.ExtractGuidAsString(expectedDeviceId), result.Id);
                Assert.Equal(expectedDeviceType, result.DeviceType);
                Assert.Equal(expectedDeviceName, result.DeviceName);
                Assert.Equal(expectedSerialNumber, result.SerialNumber);
                return(true);
            });
        }
Exemplo n.º 2
0
        public void UpdateProjectBoundaryTest()
        {
            var customerUid = new Guid("560c2a6c-6b7e-48d8-b1a5-e4009e2d4c97");
            //var accountTrn = "trn::profilex:us-west-2:account:{customerUid}";
            string projectUid = "560c2a6c-6b7e-48d8-b1a5-e4009e2d4c97";
            string projectTrn = TRNHelper.MakeTRN(projectUid, TRNHelper.TRN_PROJECT);

            var projectBoundary = new ProjectBoundary()
            {
                type        = "Polygon",
                coordinates = new List <List <double[]> > {
                    new List <double[]> {
                        new [] { 151.3, 1.2 }, new[] { 151.4, 1.2 }, new[] { 151.4, 1.3 }, new[] { 151.4, 1.4 }, new[] { 151.3, 1.2 }
                    }
                }
            };

            string route       = $"/projects/{projectTrn}/boundary";
            var    expectedUrl = $"{baseUrl}{route}";

            mockServiceResolution.Setup(m => m.ResolveRemoteServiceEndpoint(
                                            It.IsAny <string>(), It.IsAny <ApiType>(), It.IsAny <ApiVersion>(), route, It.IsAny <IList <KeyValuePair <string, string> > >())).Returns(Task.FromResult(expectedUrl));

            MockUtilities.TestRequestSendsCorrectJson("Update a projects boundary", mockWebRequest, null, expectedUrl, HttpMethod.Post, projectBoundary, async() =>
            {
                var client = ServiceProvider.GetRequiredService <ICwsProjectClient>();
                await client.UpdateProjectBoundary(new Guid(projectUid), projectBoundary);

                return(true);
            });
        }
Exemplo n.º 3
0
        public void GetProjectConfiguration()
        {
            var projectUid = new Guid("560c2a6c-6b7e-48d8-b1a5-e4009e2d4c97");
            var projectConfigurationModel = new ProjectConfigurationModel
            {
                FileName         = "MyTestFilename.dc",
                FileDownloadLink = "http//whatever",
                FileType         = ProjectConfigurationFileType.CALIBRATION.ToString(),
                CreatedAt        = DateTime.UtcNow.ToString(),
                UpdatedAt        = DateTime.UtcNow.ToString(),
                Size             = 66
            };
            string route       = $"/projects/{TRNHelper.MakeTRN(projectUid)}/configuration/CALIBRATION";
            var    expectedUrl = $"{baseUrl}{route}";

            mockServiceResolution.Setup(m => m.ResolveRemoteServiceEndpoint(
                                            It.IsAny <string>(), It.IsAny <ApiType>(), It.IsAny <ApiVersion>(), route, It.IsAny <IList <KeyValuePair <string, string> > >())).Returns(Task.FromResult(expectedUrl));

            MockUtilities.TestRequestSendsCorrectJson("Get a project calibration file", mockWebRequest, null, expectedUrl, HttpMethod.Get, projectConfigurationModel, async() =>
            {
                var client = ServiceProvider.GetRequiredService <ICwsProfileSettingsClient>();
                var result = await client.GetProjectConfiguration(projectUid, ProjectConfigurationFileType.CALIBRATION);

                Assert.NotNull(result);
                Assert.Equal(projectConfigurationModel.FileName, result.FileName);
                return(true);
            });
        }
Exemplo n.º 4
0
        public void CreateFileTest()
        {
            string projectUid = Guid.NewGuid().ToString();

            var createFileRequestModel = new CreateFileRequestModel
            {
                FileName = "myFirstProject.dc"
            };

            var createFileResponseModel = new CreateFileResponseModel
            {
                FileSpaceId = Guid.NewGuid().ToString(),
                UploadUrl   = $"{createFileRequestModel.FileName} {projectUid}"
            };
            string route       = $"/projects/{TRNHelper.MakeTRN(projectUid)}/file";
            var    expectedUrl = $"{baseUrl}{route}";

            mockServiceResolution.Setup(m => m.ResolveRemoteServiceEndpoint(
                                            It.IsAny <string>(), It.IsAny <ApiType>(), It.IsAny <ApiVersion>(), route, It.IsAny <IList <KeyValuePair <string, string> > >())).Returns(Task.FromResult(expectedUrl));

            MockUtilities.TestRequestSendsCorrectJson("Create a file", mockWebRequest, null, expectedUrl, HttpMethod.Post, createFileResponseModel, async() =>
            {
                var client = ServiceProvider.GetRequiredService <ICwsDesignClient>();
                var result = await client.CreateFile(new Guid(projectUid), createFileRequestModel);

                Assert.NotNull(result);
                Assert.Equal(createFileResponseModel.FileSpaceId, result.FileSpaceId);
                return(true);
            });
        }
Exemplo n.º 5
0
        public void UpdateProjectDetailsTest()
        {
            var customerUid = new Guid("560c2a6c-6b7e-48d8-b1a5-e4009e2d4c97");
            //var accountTrn = "trn::profilex:us-west-2:account:{customerUid}";
            string projectUid = "560c2a6c-6b7e-48d8-b1a5-e4009e2d4c97";
            string projectTrn = TRNHelper.MakeTRN(projectUid, TRNHelper.TRN_PROJECT);

            var updateProjectDetailsRequestModel = new UpdateProjectDetailsRequestModel
            {
                projectName = "my updated project"
            };

            string route       = $"/projects/{projectTrn}";
            var    expectedUrl = $"{baseUrl}{route}";

            mockServiceResolution.Setup(m => m.ResolveRemoteServiceEndpoint(
                                            It.IsAny <string>(), It.IsAny <ApiType>(), It.IsAny <ApiVersion>(), route, It.IsAny <IList <KeyValuePair <string, string> > >())).Returns(Task.FromResult(expectedUrl));

            MockUtilities.TestRequestSendsCorrectJson("Update a projects details", mockWebRequest, null, expectedUrl, HttpMethod.Post, updateProjectDetailsRequestModel, async() =>
            {
                var client = ServiceProvider.GetRequiredService <ICwsProjectClient>();
                await client.UpdateProjectDetails(new Guid(projectUid), updateProjectDetailsRequestModel);

                return(true);
            });
        }
Exemplo n.º 6
0
        public void GetDeviceBySerialNumberTest_UpperLower()
        {
            var          serialNumber         = (Guid.NewGuid().ToString()).ToLower();
            const string expectedDeviceId     = "trn::profilex:us-west-2:device:560c2a6c-6b7e-48d8-b1a5-e4009e2d4c97";
            const string expectedDeviceType   = "CB460";
            const string expectedDeviceName   = "The device Name";
            var          expectedSerialNumber = serialNumber.ToUpper();

            var deviceResponseModel = new DeviceResponseModel()
            {
                TRN = expectedDeviceId, DeviceType = expectedDeviceType, DeviceName = expectedDeviceName, SerialNumber = expectedSerialNumber
            };

            var route           = $"/devices/getDeviceWithSerialNumber";
            var queryParameters = new List <KeyValuePair <string, string> > {
                new KeyValuePair <string, string>("serialNumber", serialNumber.ToUpper())
            };
            var expectedUrl = $"{baseUrl}{route}?serialNumber={serialNumber.ToUpper()}";

            mockServiceResolution.Setup(m => m.ResolveRemoteServiceEndpoint(
                                            It.IsAny <string>(), It.IsAny <ApiType>(), It.IsAny <ApiVersion>(), route, queryParameters)).Returns(Task.FromResult(expectedUrl));

            MockUtilities.TestRequestSendsCorrectJson("Get device by serial number", mockWebRequest, null, expectedUrl, HttpMethod.Get, deviceResponseModel, async() =>
            {
                var client = ServiceProvider.GetRequiredService <ICwsDeviceClient>();
                var result = await client.GetDeviceBySerialNumber(serialNumber);

                Assert.NotNull(result);
                Assert.Equal(TRNHelper.ExtractGuidAsString(expectedDeviceId), result.Id);
                Assert.Equal(expectedDeviceType, result.DeviceType);
                Assert.Equal(expectedDeviceName, result.DeviceName);
                Assert.Equal(expectedSerialNumber, result.SerialNumber);
                return(true);
            });
        }
Exemplo n.º 7
0
        public void GetMyProject()
        {
            var customerUid = Guid.NewGuid();
            var userUid     = Guid.NewGuid();
            var projectUid  = Guid.NewGuid();

            var projectDetailResponseModel = new ProjectDetailResponseModel()
            {
                AccountTRN      = TRNHelper.MakeTRN(customerUid, TRNHelper.TRN_ACCOUNT),
                ProjectTRN      = TRNHelper.MakeTRN(projectUid),
                ProjectSettings = new ProjectSettingsModel()
                {
                    ProjectTRN = TRNHelper.MakeTRN(projectUid),
                    TimeZone   = "Pacific/Auckland",
                    Boundary   = new ProjectBoundary()
                    {
                        type        = "Polygon",
                        coordinates = new List <List <double[]> > {
                            new List <double[]> {
                                new double[] { 150.3, 1.2 }, new double[] { 150.4, 1.2 }, new double[] { 150.4, 1.3 }, new double[] { 150.4, 1.4 }, new double[] { 150.3, 1.2 }
                            }
                        }
                    },
                    Config = new List <ProjectConfigurationModel>()
                    {
                        new ProjectConfigurationModel()
                        {
                            FileType = ProjectConfigurationFileType.CALIBRATION.ToString()
                        }
                    }
                }
            };

            var route       = $"/projects/{TRNHelper.MakeTRN(projectUid)}";
            var expectedUrl = $"{baseUrl}{route}";

            mockServiceResolution.Setup(m => m.ResolveRemoteServiceEndpoint(
                                            It.IsAny <string>(), It.IsAny <ApiType>(), It.IsAny <ApiVersion>(), route, It.IsAny <IList <KeyValuePair <string, string> > >())).Returns(Task.FromResult(expectedUrl));

            MockUtilities.TestRequestSendsCorrectJson("Get my project", mockWebRequest, null, expectedUrl, HttpMethod.Get, projectDetailResponseModel, async() =>
            {
                var client = ServiceProvider.GetRequiredService <ICwsProjectClient>();
                var result = await client.GetMyProject(projectUid, userUid);

                Assert.NotNull(result);
                Assert.Equal(customerUid.ToString(), result.AccountId);
                Assert.Equal(projectUid.ToString(), result.ProjectId);
                Assert.Equal(projectUid.ToString(), result.ProjectSettings.ProjectId);
                Assert.Equal("Polygon", result.ProjectSettings.Boundary.type);
                Assert.Equal(ProjectConfigurationFileType.CALIBRATION.ToString(), result.ProjectSettings.Config[0].FileType);
                return(true);
            });
        }
Exemplo n.º 8
0
        public void CreateProjectTest()
        {
            var customerUid        = new Guid("560c2a6c-6b7e-48d8-b1a5-e4009e2d4c97");
            var expectedProjectUid = "560c2a6c-6b7e-48d8-b1a5-e4009e2d4c97";
            var expectedProjectTrn = TRNHelper.MakeTRN(expectedProjectUid);

            var createProjectRequestModel = new CreateProjectRequestModel
            {
                AccountId   = customerUid.ToString(),
                ProjectName = "my first project",
                Timezone    = "Mountain Standard Time",
                Boundary    = new ProjectBoundary()
                {
                    type        = "Polygon",
                    coordinates = new List <List <double[]> > {
                        new List <double[]> {
                            new double[] { 150.3, 1.2 }, new double[] { 150.4, 1.2 }, new double[] { 150.4, 1.3 }, new double[] { 150.4, 1.4 }, new double[] { 150.3, 1.2 }
                        }
                    }
                }
            };

            var createProjectResponseModel = new CreateProjectResponseModel
            {
                TRN = expectedProjectTrn
            };
            const string route       = "/projects";
            var          expectedUrl = $"{baseUrl}{route}";

            mockServiceResolution.Setup(m => m.ResolveRemoteServiceEndpoint(
                                            It.IsAny <string>(), It.IsAny <ApiType>(), It.IsAny <ApiVersion>(), route, It.IsAny <IList <KeyValuePair <string, string> > >())).Returns(Task.FromResult(expectedUrl));

            MockUtilities.TestRequestSendsCorrectJson("Create a project", mockWebRequest, null, expectedUrl, HttpMethod.Post, createProjectResponseModel, async() =>
            {
                var client = ServiceProvider.GetRequiredService <ICwsProjectClient>();
                var result = await client.CreateProject(createProjectRequestModel);

                Assert.NotNull(result);
                Assert.Equal(expectedProjectUid, result.Id);
                return(true);
            });
        }
Exemplo n.º 9
0
        public void CreateDeviceLKS()
        {
            var deviceType   = CWSDeviceTypeEnum.EC520;
            var serialNumber = "12456YU";
            var deviceName   = $"{deviceType}-{serialNumber}";

            var deviceLKSModel = new DeviceLKSModel()
            {
                TimeStamp         = DateTime.UtcNow.AddDays(1),
                Latitude          = -2,
                Longitude         = 3,
                Height            = 1,
                AssetSerialNumber = serialNumber,
                AssetType         = "Dozer",
                AssetNickname     = "Little Nicky",
                DesignName        = "Highway to hell",
                AppName           = "Trimble Groundworks",
                AppVersion        = "1.1.19200.96",
                Devices           = new List <ConnectedDevice> {
                    new ConnectedDevice {
                        Model = "SNM940", SerialNumber = "123456"
                    }
                }
            };

            var route       = $"/devicegateway/status/{deviceName}";
            var expectedUrl = $"{baseUrl}{route}";

            mockServiceResolution.Setup(m => m.ResolveRemoteServiceEndpoint(
                                            It.IsAny <string>(), It.IsAny <ApiType>(), It.IsAny <ApiVersion>(),
                                            route, It.IsAny <IList <KeyValuePair <string, string> > >())).Returns(Task.FromResult(expectedUrl));

            MockUtilities.TestRequestSendsCorrectJson("Post device LKS", mockWebRequest, null, expectedUrl,
                                                      HttpMethod.Post, async() =>

            {
                var client = ServiceProvider.GetRequiredService <ICwsDeviceGatewayClient>();
                await client.CreateDeviceLKS(deviceName, deviceLKSModel);
                return(true);
            });
        }
Exemplo n.º 10
0
        public void GetMyAccountsTest()
        {
            const string userId       = "trn::profilex:us-west-2:user:d79a392d-6513-46c1-baa1-75c537cf0c32";
            const string expectedId   = "trn::profilex:us-west-2:account:560c2a6c-6b7e-48d8-b1a5-e4009e2d4c97";
            const string expectedName = "Berthoud";
            const string route        = "/users/me/accounts";

            var accountListModel = new AccountListResponseModel
            {
                HasMore  = false,
                Accounts = new List <AccountResponseModel>()
                {
                    new AccountResponseModel()
                    {
                        TRN = expectedId, Name = expectedName, DeviceCount = 10, UserCount = 5, ProjectCount = 0
                    }
                }
            };

            var expectedUrl = $"{baseUrl}{route}";

            mockServiceResolution.Setup(m => m.ResolveRemoteServiceEndpoint(
                                            It.IsAny <string>(), It.IsAny <ApiType>(), It.IsAny <ApiVersion>(), route, It.IsAny <IList <KeyValuePair <string, string> > >())).Returns(Task.FromResult(expectedUrl));

            MockUtilities.TestRequestSendsCorrectJson("Get My Accounts", mockWebRequest, null, expectedUrl, HttpMethod.Get, accountListModel, async() =>
            {
                var client = ServiceProvider.GetRequiredService <ICwsAccountClient>();
                var result = await client.GetMyAccounts(TRNHelper.ExtractGuid(userId).Value);

                Assert.NotNull(result);
                Assert.False(result.HasMore);
                Assert.NotNull(result.Accounts);
                Assert.Single(result.Accounts);
                Assert.Equal(TRNHelper.ExtractGuidAsString(expectedId), result.Accounts[0].Id);
                Assert.Equal(expectedName, result.Accounts[0].Name);
                Assert.Equal(accountListModel.Accounts[0].DeviceCount, result.Accounts[0].DeviceCount);
                Assert.Equal(accountListModel.Accounts[0].UserCount, result.Accounts[0].UserCount);
                Assert.Equal(accountListModel.Accounts[0].ProjectCount, result.Accounts[0].ProjectCount);
                return(true);
            });
        }
Exemplo n.º 11
0
        public void DeleteProjectConfiguration()
        {
            var projectUid = new Guid("560c2a6c-6b7e-48d8-b1a5-e4009e2d4c97");
            var projectConfigurationFileRequestModel = new ProjectConfigurationFileRequestModel
            {
                MachineControlFilespaceId = Guid.NewGuid().ToString()
            };

            string route       = $"/projects/{TRNHelper.MakeTRN(projectUid)}/configuration/CALIBRATION";
            var    expectedUrl = $"{baseUrl}{route}";

            mockServiceResolution.Setup(m => m.ResolveRemoteServiceEndpoint(
                                            It.IsAny <string>(), It.IsAny <ApiType>(), It.IsAny <ApiVersion>(), route, It.IsAny <IList <KeyValuePair <string, string> > >())).Returns(Task.FromResult(expectedUrl));

            MockUtilities.TestRequestSendsCorrectJson("Delete a project calibration file", mockWebRequest, null, expectedUrl, HttpMethod.Delete, async() =>
            {
                var client = ServiceProvider.GetRequiredService <ICwsProfileSettingsClient>();
                await client.DeleteProjectConfiguration(projectUid, ProjectConfigurationFileType.CALIBRATION);
                return(true);
            });
        }
Exemplo n.º 12
0
        public void GetAndDownloadFileTest()
        {
            string projectUid  = Guid.NewGuid().ToString();
            string filespaceId = Guid.NewGuid().ToString();

            var fileName             = "trn::profilex:us-west-2:project:2092b1a9-e4d6-41e5-b210-b8fff3e922da||2020-04-20 23:30:28.253||BootCamp 2012.dc";
            var downloadUrl          = "https://fs-ro-us1.staging-tdata-cdn.com/r/af390a82-8cc2-4486-aba8-e66a2dcfa3f8?Signature=eVLwMzTwyAlUg~ClgMu2V1BD0QqtwiNDHD~323QfKZw5bEYHs329k2E2fwbarld3HhhoV9xuBFuom6YHGfd7Tlj4j9nFC~8vl4bh0oFsuZF0DsVG0PBKWeQmOnWGvw-HbyRYqstJa5QybeGT1B8JnJG9ApMmBUkC0Myb2nTTbirCgz1mHZ2~kSPe8gqY5WNH~1pRXhB7NeEdYr76~rVr5zlwMcesKoSxPhKVuwBDy5P7rtY-NfbHg5-bSB703bvDCdANrZAw4zTItg0Z9fsa~YiSdKyaaaetPc9PkY7Wkbo048VWXiyM3yRAM0jamN4txTTQjPs3WcpTBqRWxz-mEw__&Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiaHR0cHM6Ly9mcy1yby11czEuc3RhZ2luZy10ZGF0YS1jZG4uY29tL3IvYWYzOTBhODItOGNjMi00NDg2LWFiYTgtZTY2YTJkY2ZhM2Y4IiwiQ29uZGl0aW9uIjp7IkRhdGVMZXNzVGhhbiI6eyJBV1M6RXBvY2hUaW1lIjoxNTg3NTA3NzY1fX19XX0_&Key-Pair-Id=APKAJ4FHA7WZOWHG4EOQ";
            var getFileResponseModel = new GetFileResponseModel
            {
                FileSpaceId = filespaceId,
                FileName    = fileName,
                DownloadUrl = downloadUrl
            };
            var fileContents = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };

            string route       = $"/projects/{TRNHelper.MakeTRN(projectUid)}/file/{filespaceId}";
            var    expectedUrl = $"{baseUrl}{route}";

            mockServiceResolution.Setup(m => m.ResolveRemoteServiceEndpoint(
                                            It.IsAny <string>(), It.IsAny <ApiType>(), It.IsAny <ApiVersion>(), route, It.IsAny <IList <KeyValuePair <string, string> > >())).Returns(Task.FromResult(expectedUrl));
            var expectedContent = new ByteArrayContent(fileContents);

            mockWebRequest.Setup(s => s.ExecuteRequestAsStreamContent(downloadUrl, HttpMethod.Get, It.IsAny <IHeaderDictionary>(), null, null, 0, false))
            .Returns(Task.FromResult(expectedContent as HttpContent));

            MockUtilities.TestRequestSendsCorrectJson("Get and download a file", mockWebRequest, null, expectedUrl, HttpMethod.Get, getFileResponseModel, async() =>
            {
                var client = ServiceProvider.GetRequiredService <ICwsDesignClient>();
                using (var ms = new MemoryStream(fileContents))
                {
                    var result = await client.GetAndDownloadFile(new Guid(projectUid), filespaceId);
                    Assert.NotNull(result);
                    Assert.Equal(getFileResponseModel.FileSpaceId, result.FileSpaceId);
                    Assert.Equal(getFileResponseModel.FileName, result.FileName);
                    Assert.Equal(getFileResponseModel.FileSpaceId, result.FileSpaceId);
                    Assert.Equal(fileContents, result.FileContents);
                }
                return(true);
            });
        }
Exemplo n.º 13
0
        public void GetAccountsForDeviceTest()
        {
            const string deviceTrn          = "trn::profilex:us-west-2:device:560c2a6c-6b7e-48d8-b1a5-e4009e2d4c97";
            const string expectedAccountTrn = "trn::profilex:us-west-2:account:560c2a6c-6b7e-48d8-b1a5-e4009e2d4c97";

            var deviceAccountListResponseModel = new DeviceAccountListResponseModel
            {
                HasMore  = false,
                Accounts = new List <DeviceAccountResponseModel>()
                {
                    new DeviceAccountResponseModel()
                    {
                        TRN             = expectedAccountTrn,
                        AccountName     = "an account name",
                        RelationStatus  = RelationStatusEnum.Active,
                        TccDeviceStatus = TCCDeviceStatusEnum.Pending
                    }
                }
            };
            var route       = $"/devices/{deviceTrn}/accounts";
            var expectedUrl = $"{baseUrl}{route}?from=0&limit=20";

            mockServiceResolution.Setup(m => m.ResolveRemoteServiceEndpoint(
                                            It.IsAny <string>(), It.IsAny <ApiType>(), It.IsAny <ApiVersion>(), route, It.IsAny <IList <KeyValuePair <string, string> > >())).Returns(Task.FromResult(expectedUrl));

            MockUtilities.TestRequestSendsCorrectJson("Get accounts for a device", mockWebRequest, null, expectedUrl, HttpMethod.Get, deviceAccountListResponseModel, async() =>
            {
                var client = ServiceProvider.GetRequiredService <ICwsDeviceClient>();
                var result = await client.GetAccountsForDevice(TRNHelper.ExtractGuid(deviceTrn).Value);

                Assert.NotNull(result);
                Assert.False(result.HasMore);
                Assert.NotNull(result.Accounts);
                Assert.Single(result.Accounts);
                Assert.Equal(TRNHelper.ExtractGuidAsString(expectedAccountTrn), result.Accounts[0].Id);
                Assert.Equal(RelationStatusEnum.Active, result.Accounts[0].RelationStatus);
                return(true);
            });
        }
Exemplo n.º 14
0
        public void GetDevicesLKSForProject_earliestReportDate()
        {
            var deviceUid             = Guid.NewGuid();
            var projectUid            = Guid.NewGuid();
            var earliestOfInterestUtc = DateTime.UtcNow.AddDays(-2).AddHours(4.5);

            var serialNumber = "12456YU";
            var devices      = new List <DeviceLKSResponseModel>()
            {
                new DeviceLKSResponseModel()
                {
                    DeviceTrn         = TRNHelper.MakeTRN(deviceUid.ToString(), TRNHelper.TRN_DEVICE),
                    Latitude          = 89.3, Longitude = 189.1,
                    AssetType         = "Excavator",
                    AssetSerialNumber = serialNumber,
                    DeviceName        = $"{CWSDeviceTypeEnum.EC520}{serialNumber}",
                    LastReportedUtc   = earliestOfInterestUtc.AddDays(1),
                }
            };

            var route       = $"/devicegateway/devicelks";
            var expectedUrl = $"{baseUrl}{route}?projectid={TRNHelper.MakeTRN(projectUid.ToString())}&lastReported={earliestOfInterestUtc:yyyy-MM-ddTHH:mm:ssZ}";

            mockServiceResolution.Setup(m => m.ResolveRemoteServiceEndpoint(
                                            It.IsAny <string>(), It.IsAny <ApiType>(), It.IsAny <ApiVersion>(), route, It.IsAny <IList <KeyValuePair <string, string> > >())).Returns(Task.FromResult(expectedUrl));

            MockUtilities.TestRequestSendsCorrectJson("Get devices for project with earliestDate", mockWebRequest, null, expectedUrl, HttpMethod.Get, devices, async() =>
            {
                var client = ServiceProvider.GetRequiredService <ICwsDeviceGatewayClient>();
                var result = await client.GetDevicesLKSForProject(projectUid);

                Assert.NotNull(result);
                Assert.Single(result);
                Assert.Equal(deviceUid.ToString(), result[0].DeviceUid);
                Assert.Equal(devices[0].LastReportedUtc, result[0].LastReportedUtc);
                return(true);
            });
        }
Exemplo n.º 15
0
        public void CreateAndUploadFileTest()
        {
            string projectUid = Guid.NewGuid().ToString();

            var createFileRequestModel = new CreateFileRequestModel
            {
                FileName = "myFirstProject.dc"
            };
            var uploadUrl = $"{createFileRequestModel.FileName} {projectUid}";
            var createFileResponseModel = new CreateFileResponseModel
            {
                FileSpaceId = Guid.NewGuid().ToString(),
                UploadUrl   = uploadUrl
            };
            var fileContents = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };

            string route       = $"/projects/{TRNHelper.MakeTRN(projectUid)}/file";
            var    expectedUrl = $"{baseUrl}{route}";

            mockServiceResolution.Setup(m => m.ResolveRemoteServiceEndpoint(
                                            It.IsAny <string>(), It.IsAny <ApiType>(), It.IsAny <ApiVersion>(), route, It.IsAny <IList <KeyValuePair <string, string> > >())).Returns(Task.FromResult(expectedUrl));
            var expectedContent = new StringContent("Dummy");

            mockWebRequest.Setup(s => s.ExecuteRequestAsStreamContent(uploadUrl, HttpMethod.Put, It.IsAny <IHeaderDictionary>(), It.IsAny <Stream>(), null, 3, false))
            .Returns(Task.FromResult(expectedContent as HttpContent));

            MockUtilities.TestRequestSendsCorrectJson("Create and upload a file", mockWebRequest, null, expectedUrl, HttpMethod.Post, createFileResponseModel, async() =>
            {
                var client = ServiceProvider.GetRequiredService <ICwsDesignClient>();
                using (var ms = new MemoryStream(fileContents))
                {
                    var result = await client.CreateAndUploadFile(new Guid(projectUid), createFileRequestModel, ms);
                    Assert.NotNull(result);
                    Assert.Equal(createFileResponseModel.FileSpaceId, result.FileSpaceId);
                }
                return(true);
            });
        }
Exemplo n.º 16
0
        public void GetDeviceLicensesTest()
        {
            const string accountId = "trn::profilex:us-west-2:account:560c2a6c-6b7e-48d8-b1a5-e4009e2d4c97";

            var deviceLicensesModel = new DeviceLicenseResponseModel
            {
                Total = 57
            };
            var route       = $"/accounts/{accountId}/devicelicense";
            var expectedUrl = $"{baseUrl}{route}";

            mockServiceResolution.Setup(m => m.ResolveRemoteServiceEndpoint(
                                            It.IsAny <string>(), It.IsAny <ApiType>(), It.IsAny <ApiVersion>(), route, It.IsAny <IList <KeyValuePair <string, string> > >())).Returns(Task.FromResult(expectedUrl));

            MockUtilities.TestRequestSendsCorrectJson("Get Device Licenses", mockWebRequest, null, expectedUrl, HttpMethod.Get, deviceLicensesModel, async() =>
            {
                var client = ServiceProvider.GetRequiredService <ICwsAccountClient>();
                var result = await client.GetDeviceLicenses(TRNHelper.ExtractGuid(accountId).Value);

                Assert.NotNull(result);
                Assert.Equal(57, result.Total);
                return(true);
            });
        }
Exemplo n.º 17
0
        public void GetDeviceLKS()
        {
            var deviceUid    = Guid.NewGuid();
            var deviceType   = CWSDeviceTypeEnum.CB450;
            var serialNumber = "12456YU";
            var deviceName   = $"{deviceType}-{serialNumber}";

            var deviceLksResponseModel = new DeviceLKSResponseModel()
            {
                DeviceTrn         = TRNHelper.MakeTRN(deviceUid.ToString(), TRNHelper.TRN_DEVICE),
                Latitude          = 89.3, Longitude = 189.1,
                AssetType         = "BargeMountedExcavator",
                AssetSerialNumber = serialNumber,
                DeviceName        = deviceName,
                LastReportedUtc   = DateTime.UtcNow.AddDays(1),
            };

            var route       = $"/devicegateway/devicelks/{deviceName}";
            var expectedUrl = $"{baseUrl}{route}";

            mockServiceResolution.Setup(m => m.ResolveRemoteServiceEndpoint(
                                            It.IsAny <string>(), It.IsAny <ApiType>(), It.IsAny <ApiVersion>(),
                                            route, It.IsAny <IList <KeyValuePair <string, string> > >())).Returns(Task.FromResult(expectedUrl));

            MockUtilities.TestRequestSendsCorrectJson("Get device LKS", mockWebRequest, null, expectedUrl, HttpMethod.Get, deviceLksResponseModel, async() =>
            {
                var client = ServiceProvider.GetRequiredService <ICwsDeviceGatewayClient>();
                var result = await client.GetDeviceLKS(deviceName);

                Assert.NotNull(result);
                Assert.Equal(deviceUid.ToString(), result.DeviceUid);
                Assert.Equal(deviceName, result.DeviceName);
                Assert.Equal(serialNumber, result.AssetSerialNumber);
                return(true);
            });
        }