public async Task TRexExecutor_Manual_Sad_ProjectNotFound() { var projectUid = Guid.NewGuid().ToString(); var projectAccountUid = Guid.NewGuid().ToString(); var projectOfInterest = new ProjectData { ProjectUID = projectUid, ProjectType = CwsProjectType.AcceptsTagFiles, CustomerUID = projectAccountUid }; var getProjectUidsRequest = new GetProjectUidsRequest(projectUid, "ec520Serial", 91, 181); var projectForProjectUid = (ProjectData)null; var platformSerialDeviceUid = Guid.NewGuid().ToString(); var platformSerialAccountUid = Guid.NewGuid().ToString(); var platformSerialDevice = new DeviceData { CustomerUID = platformSerialAccountUid, DeviceUID = platformSerialDeviceUid }; var projectListForPlatformSerial = new ProjectDataResult() { ProjectDescriptors = new List <ProjectData>() { projectOfInterest } }; var expectedResult = new GetProjectUidsResult(string.Empty, platformSerialDeviceUid, platformSerialAccountUid); await ExecuteManual (getProjectUidsRequest, projectForProjectUid, platformSerialDevice, projectListForPlatformSerial, null, expectedResult, expectedCode : 3038, expectedMessage : ContractExecutionStatesEnum.FirstNameWithOffset(38) ); }
public async Task Test_ValidateFailed_InvalidManualProjectType() { var projectUid = Guid.NewGuid(); var moqRequest = new GetProjectUidsRequest(projectUid.ToString(), string.Empty, 0, 0); var moqResult = new GetProjectUidsResult(string.Empty, string.Empty, string.Empty, 3044, "Manual Import: cannot import to a Civil type project"); SetupDITfa(true, moqRequest, moqResult); byte[] tagContent; using (var tagFileStream = new FileStream(Path.Combine("TestData", "TAGFiles", "TestTAGFile.tag"), FileMode.Open, FileAccess.Read)) { tagContent = new byte[tagFileStream.Length]; tagFileStream.Read(tagContent, 0, (int)tagFileStream.Length); } var td = new TagFileDetail() { assetId = null, projectId = projectUid, tagFileName = "Test.tag", tagFileContent = tagContent, tccOrgId = "", IsJohnDoe = false }; var tagFilePreScan = new TAGFilePreScan(); await using (var stream = new MemoryStream(td.tagFileContent)) tagFilePreScan.Execute(stream); var result = await TagfileValidator.ValidSubmission(td, tagFilePreScan).ConfigureAwait(false); Assert.True(result.Code == 3044, "Failed to return correct error code"); Assert.Equal("Manual Import: cannot import to a Civil type project", result.Message); }
public async Task Test_UsingNEE_ValidateOk() { var projectUid = Guid.NewGuid(); var moqRequest = new GetProjectUidsRequest(projectUid.ToString(), "1639J101YU", 0, 0, 5876814.5384829007, 7562822.7801738745); var moqResult = new GetProjectUidsResult(projectUid.ToString(), string.Empty, string.Empty, 0, "success"); SetupDITfa(true, moqRequest, moqResult); byte[] tagContent; using (var tagFileStream = new FileStream(Path.Combine("TestData", "TAGFiles", "SeedPosition-usingNEE.tag"), FileMode.Open, FileAccess.Read)) { tagContent = new byte[tagFileStream.Length]; tagFileStream.Read(tagContent, 0, (int)tagFileStream.Length); } var td = new TagFileDetail() { assetId = null, projectId = projectUid, tagFileName = "Bug ccssscon-401 NEE SeedPosition.tag", tagFileContent = tagContent, tccOrgId = "", IsJohnDoe = false }; var tagFilePreScan = new TAGFilePreScan(); await using (var stream = new MemoryStream(td.tagFileContent)) tagFilePreScan.Execute(stream); var result = await TagfileValidator.ValidSubmission(td, tagFilePreScan).ConfigureAwait(false); Assert.True(result.Code == (int)TRexTagFileResultCode.Valid, "Failed to return a Valid request"); Assert.Equal("success", result.Message); }
/// <summary> /// this needs to be public, only for unit tests /// </summary> public static async Task <GetProjectUidsResult> CheckFileIsProcessable(TagFileDetail tagDetail, TAGFilePreScan preScanState) { /* * Three different types of tagfile submission * Type A: Automatic submission. * This is where a tagfile comes in from a known org and the system works out what Asset and Project it belongs to. Licensing is checked * * Type B: Manual submission. * This is where the project is known and supplied as an override projectid value. The Asset is worked out via TFA service or assigned a JohnDoe id if not known. * Licensing is checked for manual subscription * * Type C: Override submission. * This is where the ProjectId and AssetId is both supplied. It bypasses TFA service and providing the tagfile is valid, is processed straight into the project. * This is not a typical submission but is handy for testing and in a situation where a known third party source other than NG could determine the AssetId and Project. Typical NG users could not submit via this method thus avoiding our license check. */ var platformSerialNumber = string.Empty; if (preScanState.PlatformType >= CWSDeviceTypeEnum.EC520 && preScanState.PlatformType <= CWSDeviceTypeEnum.TMC) { platformSerialNumber = preScanState.HardwareID; } // Type C. Do we have what we need already (Most likely test tool submission) if (tagDetail.assetId != null && tagDetail.projectId != null) { if (tagDetail.assetId != Guid.Empty && tagDetail.projectId != Guid.Empty) { return(new GetProjectUidsResult(tagDetail.projectId.ToString(), tagDetail.assetId.ToString(), string.Empty, 0, "success")); } } if ((tagDetail.projectId == null || tagDetail.projectId == Guid.Empty) && string.IsNullOrEmpty(platformSerialNumber)) { // this is a TFA code. This check is also done as a pre-check as the scenario is very frequent, to avoid the API call overhead. var message = "#Progress# CheckFileIsProcessable. Must have either a valid platformSerialNumber or ProjectUID"; Log.LogWarning(message); return(new GetProjectUidsResult(tagDetail.projectId.ToString(), tagDetail.assetId.ToString(), string.Empty, (int)TRexTagFileResultCode.TRexMissingProjectUidAndPlatformSerial, message)); } var seedLatitude = MathUtilities.RadiansToDegrees(preScanState.SeedLatitude ?? 0.0); var seedLongitude = MathUtilities.RadiansToDegrees(preScanState.SeedLongitude ?? 0.0); var seedNorthing = preScanState.SeedNorthing; var seedEasting = preScanState.SeedEasting; if (Math.Abs(seedLatitude) < Consts.TOLERANCE_DECIMAL_DEGREE && Math.Abs(seedLongitude) < Consts.TOLERANCE_DECIMAL_DEGREE && (seedNorthing == null || seedEasting == null)) { // This check is also done as a pre-check as the scenario is very frequent, to avoid the TFA API call overhead. var message = $"#Progress# CheckFileIsProcessable. Unable to determine a tag file seed position. projectID {tagDetail.projectId} serialNumber {platformSerialNumber} filename {tagDetail.tagFileName} Lat {preScanState.SeedLatitude} Long {preScanState.SeedLongitude} northing {preScanState.SeedNorthing} easting {preScanState.SeedNorthing}"; Log.LogWarning(message); return(new GetProjectUidsResult(tagDetail.projectId.ToString(), tagDetail.assetId.ToString(), string.Empty, (int)TRexTagFileResultCode.TRexInvalidLatLong, message)); } var tfaRequest = new GetProjectUidsRequest( tagDetail.projectId == null ? string.Empty : tagDetail.projectId.ToString(), platformSerialNumber, seedLatitude, seedLongitude, preScanState.SeedNorthing, preScanState.SeedEasting); Log.LogInformation($"#Progress# CheckFileIsProcessable. tfaRequest {JsonConvert.SerializeObject(tfaRequest)}"); var tfaResult = await ValidateWithTfa(tfaRequest).ConfigureAwait(false); Log.LogInformation($"#Progress# CheckFileIsProcessable. TFA validate returned for {tagDetail.tagFileName} tfaResult: {JsonConvert.SerializeObject(tfaResult)}"); if (tfaResult?.Code == (int)TRexTagFileResultCode.Valid) { // if not overriding take TFA projectid if ((tagDetail.projectId == null || tagDetail.projectId == Guid.Empty) && (Guid.Parse(tfaResult.ProjectUid) != Guid.Empty)) { tagDetail.projectId = Guid.Parse(tfaResult.ProjectUid); } // take what TFA gives us including an empty guid which is a JohnDoe tagDetail.assetId = string.IsNullOrEmpty(tfaResult.DeviceUid) ? Guid.Empty : (Guid.Parse(tfaResult.DeviceUid)); // Check For JohnDoe machines. if you get a valid pass and no assetid it means it had a manual3dlicense if (tagDetail.assetId == Guid.Empty) { tagDetail.IsJohnDoe = true; // JohnDoe Machine and OK to process } } return(tfaResult); }
private void SetupDITfa(bool enableTfaService = true, GetProjectUidsRequest getProjectUidsRequest = null, GetProjectUidsResult getProjectUidsResult = null) { // this setup includes the DITagFileFixture. Done here to try to avoid random test failures. var moqStorageProxy = new Mock <IStorageProxy>(); var moqStorageProxyFactory = new Mock <IStorageProxyFactory>(); moqStorageProxyFactory.Setup(mk => mk.Storage(StorageMutability.Immutable)).Returns(moqStorageProxy.Object); moqStorageProxyFactory.Setup(mk => mk.Storage(StorageMutability.Mutable)).Returns(moqStorageProxy.Object); moqStorageProxyFactory.Setup(mk => mk.MutableGridStorage()).Returns(moqStorageProxy.Object); moqStorageProxyFactory.Setup(mk => mk.ImmutableGridStorage()).Returns(moqStorageProxy.Object); var moqSurveyedSurfaces = new Mock <ISurveyedSurfaces>(); var moqSiteModels = new Mock <ISiteModels>(); moqSiteModels.Setup(mk => mk.PrimaryMutableStorageProxy).Returns(moqStorageProxy.Object); DIBuilder .Continue() .Add(x => x.AddSingleton <IStorageProxyFactory>(moqStorageProxyFactory.Object)) .Add(x => x.AddSingleton <ISiteModels>(moqSiteModels.Object)) .Add(x => x.AddSingleton <ISurveyedSurfaces>(moqSurveyedSurfaces.Object)) .Add(x => x.AddSingleton <IProductionEventsFactory>(new ProductionEventsFactory())) .Build(); var newSiteModelGuidTfa = Guid.NewGuid(); ISiteModel mockedSiteModel = new SiteModel(newSiteModelGuidTfa, StorageMutability.Immutable); mockedSiteModel.SetStorageRepresentationToSupply(StorageMutability.Mutable); var moqSiteModelFactory = new Mock <ISiteModelFactory>(); moqSiteModelFactory.Setup(mk => mk.NewSiteModel(StorageMutability.Mutable)).Returns(mockedSiteModel); moqSiteModels.Setup(mk => mk.GetSiteModel(newSiteModelGuidTfa)).Returns(mockedSiteModel); // Mock the new site model creation API to return just a new site model moqSiteModels.Setup(mk => mk.GetSiteModel(newSiteModelGuidTfa, true)).Returns(mockedSiteModel); //Moq doesn't support extension methods in IConfiguration/Root. var moqConfiguration = DIContext.Obtain <Mock <IConfigurationStore> >(); var moqMinTagFileLength = 100; moqConfiguration.Setup(x => x.GetValueBool("ENABLE_TFA_SERVICE", It.IsAny <bool>())).Returns(enableTfaService); moqConfiguration.Setup(x => x.GetValueBool("ENABLE_TFA_SERVICE")).Returns(enableTfaService); moqConfiguration.Setup(x => x.GetValueInt("MIN_TAGFILE_LENGTH", It.IsAny <int>())).Returns(moqMinTagFileLength); moqConfiguration.Setup(x => x.GetValueInt("MIN_TAGFILE_LENGTH")).Returns(moqMinTagFileLength); var moqTfaProxy = new Mock <ITagFileAuthProjectV5Proxy>(); if (enableTfaService && getProjectUidsRequest != null) { moqTfaProxy.Setup(x => x.GetProjectUids(It.IsAny <GetProjectUidsRequest>(), It.IsAny <IHeaderDictionary>())).ReturnsAsync(getProjectUidsResult); } DIBuilder .Continue() .Add(x => x.AddSingleton(moqConfiguration.Object)) .Add(x => x.AddSingleton <ISiteModelFactory>(new SiteModelFactory())) .Add(x => x.AddSingleton(moqTfaProxy.Object)) .Complete(); }
public void Should_indicate_whether_request_is_manual_import(string projectUid, bool expectedResult) { var request = new GetProjectUidsRequest(projectUid, null, 0.0, 0.0); Assert.AreEqual(expectedResult, request.IsManualImport); }