public async Task HydrateJsonWithBoundary_NoGeofence(FilterType filterType) { var log = serviceProvider.GetRequiredService <ILoggerFactory>().CreateLogger <ValidationTests>(); var geofenceRepo = new Mock <IGeofenceRepository>(); geofenceRepo.Setup(g => g.GetGeofence(It.IsAny <string>())).ReturnsAsync((Geofence)null); //var geofenceProxy = new Mock<IGeofenceProxy>(); //geofenceProxy.Setup(g => g.GetGeofenceForCustomer(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<HeaderDictionary>())).ReturnsAsync( // (GeofenceData)null); var request = FilterRequestFull.Create(null, custUid, false, userUid, new ProjectData { ProjectUID = projectUid }, new FilterRequest { FilterUid = filterUid, Name = "a filter", FilterType = filterType, FilterJson = "{\"designUID\": \"id\", \"vibeStateOn\": true, \"polygonUID\": \"" + boundaryUid + "\"}" }); var ex = await Assert.ThrowsAsync <ServiceException>(async() => await ValidationUtil .HydrateJsonWithBoundary(/*geofenceProxy.Object,*/ geofenceRepo.Object, log, serviceExceptionHandler, request).ConfigureAwait(false)); Assert.Contains("2040", ex.GetContent); Assert.Contains("Validation of Project/Boundary failed. Not allowed.", ex.GetContent); }
public async Task UpsertFilterExecutor_Transient_Existing_FilterUidNotSupported() { var custUid = Guid.NewGuid(); var userId = Guid.NewGuid(); var projectUid = Guid.NewGuid(); var filterUid = Guid.NewGuid(); string name = string.Empty; FilterType filterType = FilterType.Transient; string filterJson = "{\"designUID\":\"c2e5940c-4370-4d23-a930-b5b74a9fc22b\",\"contributingMachines\":[{\"assetID\":\"123456789\",\"machineName\":\"TheMachineName\",\"isJohnDoe\":false,\"assetUid\":null}]}"; string filterJsonUpdated = "{\"designUID\":\"c2e5940c-4370-4d23-a930-b5b74a9fc22b\",\"onMachineDesignID\":null,\"elevationType\":3,\"vibeStateOn\":true}"; WriteEventToDb(new CreateFilterEvent { CustomerUID = custUid, UserID = userId.ToString(), ProjectUID = projectUid, FilterUID = filterUid, Name = name, FilterType = filterType, FilterJson = filterJson, ActionUTC = DateTime.UtcNow }); var request = FilterRequestFull.Create(new HeaderDictionary(), custUid.ToString(), false, userId.ToString(), new ProjectData { ProjectUID = projectUid.ToString() }, new FilterRequest { FilterUid = filterUid.ToString(), Name = name, FilterJson = filterJsonUpdated, FilterType = filterType }); var ex = await Assert.ThrowsExceptionAsync <ServiceException>(async() => await executor.ProcessAsync(request)).ConfigureAwait(false); Assert.AreNotEqual(-1, ex.GetContent.IndexOf("2016", StringComparison.Ordinal), "executor threw exception but incorrect code"); Assert.AreNotEqual(-1, ex.GetContent.IndexOf("UpsertFilter failed. Transient filter not updateable, should not have filterUid provided.", StringComparison.Ordinal), "executor threw exception but incorrect messaage"); }
protected FilterRequestFull CreateAndValidateRequest( ProjectData projectData, bool isApplicationContext = false, string userId = null, string filterUid = null, string name = null, string filterJson = "", string boundaryUid = null, string customerUid = null, FilterType filterType = FilterType.Transient, bool onlyFilterUid = false) { var request = FilterRequestFull.Create( new HeaderDictionary(), customerUid ?? Guid.NewGuid().ToString(), isApplicationContext, userId ?? Guid.NewGuid().ToString(), projectData ?? new ProjectData() { ProjectUID = Guid.NewGuid().ToString() }, new FilterRequest { FilterUid = filterUid ?? Guid.NewGuid().ToString(), Name = name, FilterType = filterType, FilterJson = filterJson }); request.Validate(ServiceExceptionHandler, onlyFilterUid); return(request); }
public async Task HydrateJsonWithBoundary_InvalidBoundary2(FilterType filterType) { var log = serviceProvider.GetRequiredService <ILoggerFactory>().CreateLogger <ValidationTests>(); var geofenceRepo = new Mock <IGeofenceRepository>(); var geofence = new Geofence { GeofenceType = GeofenceType.Filter, GeometryWKT = "POLYGON((-115.0200886019198 36.20745605916501,-115.02005976817289 36.20734622441246,-115.01992699882665 36.2073559634608,-115.0198176988093 36.207342978062755,-115.01973320922532 36.20734027277125,-115.01974729082266 36.20738950906242,-115.01975466689743 36.2074300884,-115.01996052643932 36.20746201079744))" }; // var geofence = new Geofence { GeometryWKT = "POLYGON((-115.02022874734084 36.20751287018342,-115.02025556943099 36.207300775504265,-115.02001953503766 36.20729428280093,-115.01966816565673 36.20726506562927,-115.01945493004004 36.20714170411769,-115.0192846097676 36.20734189594616,-115.01962927362601 36.20748581732266,-115.02022874734084 36.20751287018342))" }; geofenceRepo.Setup(g => g.GetGeofence(It.IsAny <string>())).ReturnsAsync(geofence); //var geofenceProxy = new Mock<IGeofenceProxy>(); //var geofenceData = new GeofenceData { GeofenceType = GeofenceType.Generic.ToString(), GeometryWKT = geofence.GeometryWKT }; //geofenceProxy.Setup(g => g.GetGeofenceForCustomer(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<HeaderDictionary>())).ReturnsAsync(geofenceData); var request = FilterRequestFull.Create(null, custUid, false, userUid, new ProjectData { ProjectUID = projectUid }, new FilterRequest { FilterUid = filterUid, Name = "a filter", FilterType = filterType, FilterJson = "{\"designUID\": \"id\", \"vibeStateOn\": true, \"polygonUID\": \"" + boundaryUid + "\"}" }); var ex = await Assert.ThrowsAsync <ServiceException>(async() => await ValidationUtil .HydrateJsonWithBoundary(/*geofenceProxy.Object,*/ geofenceRepo.Object, log, serviceExceptionHandler, request).ConfigureAwait(false)); Assert.Contains("2045", ex.GetContent); Assert.Contains("Invalid spatial filter boundary. One or more polygon components are missing.", ex.GetContent); }
public async Task HydrateJsonWithBoundary_IncludeAlignment(FilterType filterType) { var log = serviceProvider.GetRequiredService <ILoggerFactory>().CreateLogger <ValidationTests>(); var geofenceRepo = new Mock <IGeofenceRepository>(); //var geofenceProxy = new Mock<IGeofenceProxy>(); var alignmentUid = Guid.NewGuid().ToString(); var startStation = 100.456; var endStation = 200.5; var leftOffset = 4.5; var rightOffset = 2.5; var request = FilterRequestFull.Create(null, custUid, false, userUid, new ProjectData { ProjectUID = projectUid }, new FilterRequest { FilterUid = filterUid, Name = "a filter", FilterType = filterType, FilterJson = "{\"designUID\": \"id\", \"vibeStateOn\": true, \"alignmentUid\": \"" + alignmentUid + "\", \"startStation\":" + startStation + ", \"endStation\":" + endStation + ", \"leftOffset\":" + leftOffset + ", \"rightOffset\":" + rightOffset + "}" }); var result = await ValidationUtil .HydrateJsonWithBoundary(/*geofenceProxy.Object,*/ geofenceRepo.Object, log, serviceExceptionHandler, request).ConfigureAwait(false); Assert.Equal(request.FilterJson, result); }
public async Task HydrateJsonWithBoundary_HappyPath_Custom(FilterType filterType) { var log = serviceProvider.GetRequiredService <ILoggerFactory>().CreateLogger <ValidationTests>(); var geofenceRepo = new Mock <IGeofenceRepository>(); var geofence = new Geofence { GeofenceUID = boundaryUid, Name = Name, GeometryWKT = GeometryWKT, GeofenceType = GeofenceType.Filter }; geofenceRepo.Setup(g => g.GetGeofence(It.IsAny <string>())).ReturnsAsync(geofence); //var geofenceProxy = new Mock<IGeofenceProxy>(); var request = FilterRequestFull.Create(null, custUid, false, userUid, new ProjectData { ProjectUID = projectUid }, new FilterRequest { FilterUid = filterUid, Name = "a filter", FilterType = filterType, FilterJson = "{\"designUid\": \"id\", \"vibeStateOn\": true, \"polygonUid\": \"" + geofence.GeofenceUID + "\"}" }); var result = await ValidationUtil .HydrateJsonWithBoundary(/*geofenceProxy.Object,*/ geofenceRepo.Object, log, serviceExceptionHandler, request).ConfigureAwait(false); var expectedResult = "{\"designUid\":\"id\",\"vibeStateOn\":true,\"polygonUid\":\"" + geofence.GeofenceUID + "\",\"polygonName\":\"" + geofence.Name + "\",\"polygonLL\":[{\"Lat\":12.677856,\"Lon\":80.257874},{\"Lat\":13.039345,\"Lon\":79.856873},{\"Lat\":13.443052,\"Lon\":80.375977}]," + "\"polygonType\":" + (int)geofence.GeofenceType + "}"; Assert.Equal(expectedResult, result); }
public void MapFilterRequestToCreateFilterEvent_UserContext_NoFilterUID(FilterType filterType) { var filterRequest = FilterRequestFull.Create ( null, Guid.NewGuid().ToString(), false, Guid.NewGuid().ToString(), new ProjectData { ProjectUID = Guid.NewGuid().ToString() }, new FilterRequest { FilterUid = Guid.NewGuid().ToString(), Name = "the name", FilterJson = "the Json", FilterType = filterType } ); filterRequest.FilterUid = Guid.NewGuid().ToString(); var result = AutoMapperUtility.Automapper.Map <CreateFilterEvent>(filterRequest); Assert.Equal(filterRequest.CustomerUid, result.CustomerUID.ToString()); Assert.Equal(filterRequest.UserId, result.UserID); Assert.Equal(filterRequest.ProjectUid, result.ProjectUID.ToString()); Assert.Equal(filterRequest.FilterUid, result.FilterUID.ToString()); Assert.Equal(filterRequest.Name, result.Name); Assert.Equal(filterRequest.FilterJson, result.FilterJson); Assert.Equal(filterRequest.FilterType, result.FilterType); }
public async Task UpsertFilterExecutor_Transient_Existing_NoFilterUidProvided() { var custUid = Guid.NewGuid(); var userId = UIDs.JWT_USER_ID; var projectUid = UIDs.MOCK_WEB_API_DIMENSIONS_PROJECT_UID; var filterUid = Guid.NewGuid(); string name = string.Empty; FilterType filterType = FilterType.Transient; string filterJson = "{\"designUid\":\"c2e5940c-4370-4d23-a930-b5b74a9fc22b\",\"contributingMachines\":[{\"assetID\":\"123456789\",\"machineName\":\"TheMachineName\",\"isJohnDoe\":false,\"assetUid\":null}]}"; string filterJsonUpdated = "{\"designUid\":\"c2e5940c-4370-4d23-a930-b5b74a9fc22b\",\"onMachineDesignID\":null,\"elevationType\":3,\"vibeStateOn\":true}"; WriteEventToDb(new CreateFilterEvent { CustomerUID = custUid, UserID = userId, ProjectUID = projectUid, FilterUID = filterUid, Name = name, FilterType = filterType, FilterJson = filterJson, ActionUTC = DateTime.UtcNow }); var request = FilterRequestFull.Create(new HeaderDictionary(), custUid.ToString(), false, userId, new ProjectData { ProjectUID = projectUid.ToString() }, new FilterRequest { Name = name, FilterJson = filterJsonUpdated, FilterType = filterType }); var result = await executor.ProcessAsync(request) as FilterDescriptorSingleResult; Assert.IsNotNull(result, "executor should always return a result"); Assert.AreNotEqual(filterUid, result.FilterDescriptor.FilterUid, "executor returned incorrect FilterUid"); Assert.AreEqual(name, result.FilterDescriptor.Name, "executor returned incorrect filter Name"); Assert.AreEqual("{\"designUid\":\"c2e5940c-4370-4d23-a930-b5b74a9fc22b\",\"elevationType\":3,\"vibeStateOn\":true}", result.FilterDescriptor.FilterJson, "executor returned incorrect FilterJson"); }
public void FilterRequestValidation_InvalidAlignment(FilterType filterType) { var alignmentUid = Guid.NewGuid().ToString(); var startStation = 100.456; var leftOffset = 4.5; var rightOffset = 2.5; var request = FilterRequestFull.Create(null, custUid, false, userUid, new ProjectData { ProjectUID = projectUid }, new FilterRequest { FilterUid = filterUid, Name = "a filter", FilterType = filterType, FilterJson = "{\"vibeStateOn\": true, \"alignmentUid\": \"" + alignmentUid + "\", \"startStation\":" + startStation + ", \"endStation\": null, \"leftOffset\":" + leftOffset + ", \"rightOffset\":" + rightOffset + "}" }); var ex = Assert.Throws <ServiceException>(() => request.Validate(serviceExceptionHandler)); Assert.Contains("2065", ex.GetContent); Assert.Contains("Invalid alignment filter. Start or end station are invalid.", ex.GetContent); }
public async Task HydrateJsonWithBoundary_InvalidBoundary(FilterType filterType) { var log = serviceProvider.GetRequiredService <ILoggerFactory>().CreateLogger <ValidationTests>(); var geofenceRepo = new Mock <IGeofenceRepository>(); var geofence = new Geofence { GeometryWKT = "This is not a valid polygon WKT", GeofenceType = GeofenceType.Filter }; geofenceRepo.Setup(g => g.GetGeofence(It.IsAny <string>())).ReturnsAsync(geofence); //var geofenceProxy = new Mock<IGeofenceProxy>(); var geofenceData = new GeofenceData { GeometryWKT = geofence.GeometryWKT, GeofenceType = GeofenceType.Generic.ToString() }; //geofenceProxy.Setup(g => g.GetGeofenceForCustomer(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<HeaderDictionary>())).ReturnsAsync(geofenceData); var request = FilterRequestFull.Create(null, custUid, false, userUid, new ProjectData { ProjectUID = projectUid }, new FilterRequest { FilterUid = filterUid, Name = "a filter", FilterType = filterType, FilterJson = "{\"designUID\": \"id\", \"vibeStateOn\": true, \"polygonUID\": \"" + boundaryUid + "\"}" }); var ex = await Assert.ThrowsAsync <ServiceException>(async() => await ValidationUtil .HydrateJsonWithBoundary(/*geofenceProxy.Object,*/ geofenceRepo.Object, log, serviceExceptionHandler, request).ConfigureAwait(false)); Assert.Contains("2045", ex.GetContent); Assert.Contains("Invalid spatial filter boundary. One or more polygon components are missing.", ex.GetContent); }
public async Task GetFiltersExecutor() { string custUid = Guid.NewGuid().ToString(); string userUid = Guid.NewGuid().ToString(); string projectUid = Guid.NewGuid().ToString(); string filterUid = Guid.NewGuid().ToString(); string name = "blah"; var configStore = serviceProvider.GetRequiredService <IConfigurationStore>(); var logger = serviceProvider.GetRequiredService <ILoggerFactory>(); var filterRepo = new Mock <FilterRepository>(configStore, logger); var filters = new List <MasterData.Repositories.DBModels.Filter> { new MasterData.Repositories.DBModels.Filter { CustomerUid = custUid, UserId = userUid, ProjectUid = projectUid, FilterUid = filterUid, Name = name, FilterJson = "{\"dateRangeType\":\"0\",\"elevationType\":null}", FilterType = FilterType.Persistent, LastActionedUtc = DateTime.UtcNow } }; filterRepo.As <IFilterRepository>().Setup(ps => ps.GetFiltersForProjectUser(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), false)).ReturnsAsync(filters); var filterListToTest = new FilterDescriptorListResult { FilterDescriptors = filters .Select(filter => AutoMapperUtility.Automapper.Map <FilterDescriptor>(filter)) .ToImmutableList() }; var request = FilterRequestFull.Create ( null, custUid, false, userUid, new ProjectData { ProjectUID = projectUid }); var executor = RequestExecutorContainer.Build <GetFiltersExecutor>(configStore, logger, serviceExceptionHandler, filterRepo.Object, null); var filterListResult = await executor.ProcessAsync(request) as FilterDescriptorListResult; Assert.NotNull(filterListResult); Assert.Equal(filterListToTest.FilterDescriptors[0].FilterUid, filterListResult.FilterDescriptors[0].FilterUid); Assert.Equal(filterListToTest.FilterDescriptors[0].Name, filterListResult.FilterDescriptors[0].Name); Assert.Equal("{\"dateRangeType\":0,\"dateRangeName\":\"Today\"}", filterListResult.FilterDescriptors[0].FilterJson); Assert.Equal(filterListToTest.FilterDescriptors[0].FilterType, filterListResult.FilterDescriptors[0].FilterType); }
public void FilterRequestValidation_PartialFill() { var requestFull = FilterRequestFull.Create(null, custUid, false, userUid, new ProjectData { ProjectUID = projectUid }); requestFull.Validate(serviceExceptionHandler); }
public void FilterRequestValidation_MissingProjectUid() { var requestFull = FilterRequestFull.Create(null, custUid, false, userUid, null, new FilterRequest { FilterUid = filterUid, Name = Name, FilterJson = FilterJson, FilterType = filterType }); var ex = Assert.Throws <ServiceException>(() => requestFull.Validate(serviceExceptionHandler)); Assert.Contains("2001", ex.GetContent); Assert.Contains("Invalid projectUid.", ex.GetContent); }
public void FilterRequestValidation_InvalidFilterJson() { var requestFull = FilterRequestFull.Create(null, custUid, false, userUid, new ProjectData { ProjectUID = projectUid }, new FilterRequest { FilterUid = filterUid, Name = Name, FilterJson = null, FilterType = filterType }); requestFull.Validate(serviceExceptionHandler); }
public async Task GetFilterExecutor_ExistingFilter(FilterType filterType) { var custUid = Guid.NewGuid(); var userId = Guid.NewGuid(); var projectUid = Guid.NewGuid(); var filterUid = Guid.NewGuid(); string name = "blah"; string filterJson = "{\"dateRangeType\":1,\"elevationType\":null}"; WriteEventToDb(new CreateFilterEvent { CustomerUID = custUid, UserID = userId.ToString(), ProjectUID = projectUid, FilterUID = filterUid, Name = name, FilterType = filterType, FilterJson = filterJson, ActionUTC = DateTime.UtcNow }); var request = FilterRequestFull.Create(null, custUid.ToString(), false, userId.ToString(), new ProjectData() { ProjectUID = projectUid.ToString() }, new FilterRequest { FilterUid = filterUid.ToString(), FilterType = filterType }); var executor = RequestExecutorContainer.Build <GetFilterExecutor>(ConfigStore, Logger, ServiceExceptionHandler, FilterRepo, null); var result = await executor.ProcessAsync(request).ConfigureAwait(false) as FilterDescriptorSingleResult; var filterToTest = new FilterDescriptorSingleResult( new FilterDescriptor { FilterUid = filterUid.ToString(), Name = name, FilterType = filterType, FilterJson = filterJson } ); Assert.IsNotNull(result, Responses.ShouldReturnResult); Assert.AreEqual(filterToTest.FilterDescriptor.FilterUid, result.FilterDescriptor.FilterUid, Responses.IncorrectFilterDescriptorFilterUid); Assert.AreEqual(filterToTest.FilterDescriptor.Name, result.FilterDescriptor.Name, Responses.IncorrectFilterDescriptorName); Assert.AreEqual("{\"dateRangeType\":1,\"dateRangeName\":\"Yesterday\"}", result.FilterDescriptor.FilterJson, Responses.IncorrectFilterDescriptorFilterJson); Assert.AreEqual(filterToTest.FilterDescriptor.FilterType, result.FilterDescriptor.FilterType, Responses.IncorrectFilterDescriptorFilterType); }
/// <summary> /// Validates and saves a single filter. Also creates the project-geofence association if the filter contains a polygon boundary. /// </summary> private async Task <FilterDescriptorSingleResult> UpsertFilter(UpsertFilterExecutor filterExecutor, ProjectData project, FilterRequest filterRequest) { var requestFull = FilterRequestFull.Create( Request.Headers.GetCustomHeaders(), CustomerUid, IsApplication, GetUserId, project, filterRequest); requestFull.Validate(ServiceExceptionHandler); return(await filterExecutor.ProcessAsync(requestFull) as FilterDescriptorSingleResult); }
public void FilterRequestValidation_Should_fail_When_supplied_string_is_invalid_json() { var requestFull = FilterRequestFull.Create(null, custUid, false, userUid, new ProjectData { ProjectUID = projectUid }, new FilterRequest { FilterUid = filterUid, Name = Name, FilterJson = "de blah", FilterType = filterType }); var ex = Assert.Throws <ServiceException>(() => requestFull.Validate(serviceExceptionHandler)); Assert.Contains("2042", ex.GetContent); Assert.Contains("Invalid filterJson. Exception: ", ex.GetContent); }
public async Task DeleteFilterExecutor(FilterType filterType) { string custUid = Guid.NewGuid().ToString(); string userUid = Guid.NewGuid().ToString(); string projectUid = Guid.NewGuid().ToString(); string filterUid = Guid.NewGuid().ToString(); string name = "not entry"; string filterJson = "theJsonString"; var configStore = serviceProvider.GetRequiredService <IConfigurationStore>(); var logger = serviceProvider.GetRequiredService <ILoggerFactory>(); var projectProxy = new Mock <IProjectProxy>(); var productivity3dV2ProxyNotification = new Mock <IProductivity3dV2ProxyNotification>(); productivity3dV2ProxyNotification.Setup(ps => ps.NotifyFilterChange(It.IsAny <Guid>(), It.IsAny <Guid>(), null)).ReturnsAsync(new BaseMasterDataResult()); var filterRepo = new Mock <FilterRepository>(configStore, logger); var filters = new List <MasterData.Repositories.DBModels.Filter> { new MasterData.Repositories.DBModels.Filter { CustomerUid = custUid, UserId = userUid, ProjectUid = projectUid, FilterUid = filterUid, Name = name, FilterJson = filterJson, FilterType = filterType, LastActionedUtc = DateTime.UtcNow } }; filterRepo.As <IFilterRepository>().Setup(ps => ps.GetFiltersForProjectUser(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), true)).ReturnsAsync(filters); filterRepo.As <IFilterRepository>().Setup(ps => ps.StoreEvent(It.IsAny <DeleteFilterEvent>())).ReturnsAsync(1); var request = FilterRequestFull.Create(null, custUid, false, userUid, new ProjectData { ProjectUID = projectUid }, new FilterRequest { FilterUid = filterUid, Name = name, FilterJson = filterJson, FilterType = filterType }); var executor = RequestExecutorContainer.Build <DeleteFilterExecutor>(configStore, logger, serviceExceptionHandler, filterRepo.Object, null, projectProxy.Object, productivity3dV2ProxyNotification: productivity3dV2ProxyNotification.Object); var result = await executor.ProcessAsync(request); Assert.NotNull(result); Assert.Equal(0, result.Code); }
public async Task GetFilterExecutor_DoesntBelongToUser(FilterType filterType) { string custUid = Guid.NewGuid().ToString(); string requestingUserUid = Guid.NewGuid().ToString(); string filterUserUid = Guid.NewGuid().ToString(); string projectUid = Guid.NewGuid().ToString(); string filterUid = Guid.NewGuid().ToString(); string name = "blah"; string filterJson = "{{\"dateRangeType\":\"0\",\"elevationType\":null}}"; var configStore = serviceProvider.GetRequiredService <IConfigurationStore>(); var logger = serviceProvider.GetRequiredService <ILoggerFactory>(); var filterRepo = new Mock <FilterRepository>(configStore, logger); var filter = new MasterData.Repositories.DBModels.Filter { CustomerUid = custUid, UserId = filterUserUid, ProjectUid = projectUid, FilterUid = filterUid, Name = name, FilterJson = filterJson, FilterType = filterType, LastActionedUtc = DateTime.UtcNow }; filterRepo.As <IFilterRepository>().Setup(ps => ps.GetFilter(It.IsAny <string>())).ReturnsAsync(filter); var request = FilterRequestFull.Create ( null, custUid, false, requestingUserUid, new ProjectData { ProjectUID = projectUid }, new FilterRequest { FilterUid = filterUid } ); var executor = RequestExecutorContainer.Build <GetFilterExecutor>(configStore, logger, serviceExceptionHandler, filterRepo.Object, null); var ex = await Assert.ThrowsAsync <ServiceException>(async() => await executor.ProcessAsync(request)); Assert.Contains("2036", ex.GetContent); Assert.Contains("GetFilter By filterUid. The requested filter does not exist, or does not belong to the requesting customer; project or user.", ex.GetContent); }
public void FilterRequestValidation_MissingName() { var requestFull = FilterRequestFull.Create(null, custUid, false, userUid, new ProjectData { ProjectUID = projectUid }, new FilterRequest { FilterUid = filterUid, Name = string.Empty, FilterJson = string.Empty, FilterType = filterType }); Assert.Throws <ServiceException>(() => requestFull.Validate(serviceExceptionHandler)); }
public void FilterRequestValidation_InvalidName() { var requestFull = FilterRequestFull.Create(null, custUid, false, userUid, new ProjectData { ProjectUID = projectUid }, new FilterRequest { FilterUid = filterUid, Name = null, FilterJson = string.Empty, FilterType = FilterType.Transient }); requestFull.Validate(serviceExceptionHandler); }
public void FilterRequestValidation_Should_succeed_When_supplied_json_is_valid(string filterJson) { var requestFull = FilterRequestFull.Create(null, custUid, false, userUid, new ProjectData { ProjectUID = projectUid }, new FilterRequest { FilterUid = filterUid, Name = string.Empty, FilterJson = filterJson, FilterType = FilterType.Transient }); requestFull.Validate(serviceExceptionHandler); }
public async Task UpsertFilterExecutor_Persistent_ExistingName_FilterUidProvided_ChangeJson() { //Note: this test only applies to persistent filters not report filters. //Report filters are allowed duplicate names. var custUid = Guid.NewGuid(); var userId = Guid.NewGuid(); var projectUid = Guid.NewGuid(); var filterUid1 = Guid.NewGuid(); var filterUid2 = Guid.NewGuid(); string name = "theName"; string filterJson = "{\"designUID\":\"c2e5940c-4370-4d23-a930-b5b74a9fc22b\",\"contributingMachines\":[{\"assetID\":\"123456789\",\"machineName\":\"TheMachineName\",\"isJohnDoe\":false,\"assetUid\":null}]}"; string filterJsonUpdated = "{\"designUID\":\"c2e5940c-4370-4d23-a930-b5b74a9fc22b\",\"onMachineDesignID\":null,\"elevationType\":3,\"vibeStateOn\":true}"; var filterType = FilterType.Persistent; var filterEvent = new CreateFilterEvent { CustomerUID = custUid, UserID = userId.ToString(), ProjectUID = projectUid, FilterUID = filterUid1, Name = name, FilterType = filterType, FilterJson = filterJson, ActionUTC = DateTime.UtcNow }; WriteEventToDb(filterEvent); filterEvent.FilterUID = filterUid2; filterEvent.Name = "something else"; WriteEventToDb(filterEvent); // now try to change the 2nd filter to the name of the first var request = FilterRequestFull.Create(new HeaderDictionary(), custUid.ToString(), false, userId.ToString(), new ProjectData { ProjectUID = projectUid.ToString() }, new FilterRequest { FilterUid = filterUid2.ToString(), Name = name, FilterJson = filterJsonUpdated, FilterType = filterType }); var ex = await Assert.ThrowsExceptionAsync <ServiceException>(async() => await executor.ProcessAsync(request)).ConfigureAwait(false); var content = ex.GetContent; Assert.AreNotEqual(-1, content.IndexOf("2039", StringComparison.Ordinal), "executor threw exception but incorrect code"); Assert.AreNotEqual(-1, content.IndexOf("UpsertFilter failed. Unable to add persistent filter as Name already exists.", StringComparison.Ordinal), "executor threw exception but incorrect messaage"); }
public void FilterRequestValidation_InvalidFilterUid() { var requestFull = FilterRequestFull.Create(null, custUid, false, userUid, new ProjectData { ProjectUID = projectUid }, new FilterRequest { FilterUid = "this is so wrong", Name = Name, FilterJson = FilterJson, FilterType = filterType }); var ex = Assert.Throws <ServiceException>(() => requestFull.Validate(serviceExceptionHandler)); Assert.Contains("2002", ex.GetContent); Assert.Contains("Invalid filterUid.", ex.GetContent); }
public void FilterRequestValidation_ValidPassCountRange(FilterType filterType) { var minPassCount = 5; var maxPassCount = 8; var request = FilterRequestFull.Create(null, custUid, false, userUid, new ProjectData { ProjectUID = projectUid }, new FilterRequest { FilterUid = filterUid, Name = "a filter", FilterType = filterType, FilterJson = "{\"vibeStateOn\": true, \"passCountRangeMin\": \"" + minPassCount + "\", \"passCountRangeMax\": \"" + maxPassCount + "\" }" }); request.Validate(serviceExceptionHandler); }
public void FilterRequestValidation_ValidTemperatureRange(FilterType filterType) { var minTemperature = 100.5; var maxTemperature = 120.9; var request = FilterRequestFull.Create(null, custUid, false, userUid, new ProjectData { ProjectUID = projectUid }, new FilterRequest { FilterUid = filterUid, Name = "a filter", FilterType = filterType, FilterJson = "{\"vibeStateOn\": true, \"temperatureRangeMin\": \"" + minTemperature + "\", \"temperatureRangeMax\": \"" + maxTemperature + "\" }" }); request.Validate(serviceExceptionHandler); }
public async Task UpsertFilterExecutor_Persistent_NoExisting_InvalidFilterUidProvided(FilterType filterType) { string custUid = Guid.NewGuid().ToString(); string userUid = Guid.NewGuid().ToString(); string projectUid = Guid.NewGuid().ToString(); string filterUid = Guid.NewGuid().ToString(); string name = "the Name"; string filterJson = "{\"designUID\":\"c2e5940c-4370-4d23-a930-b5b74a9fc22b\",\"contributingMachines\":[{\"assetID\":\"123456789\",\"machineName\":\"TheMachineName\",\"isJohnDoe\":false,\"assetUid\":null}]}"; var request = FilterRequestFull.Create(new HeaderDictionary(), custUid, false, userUid, new ProjectData { ProjectUID = projectUid }, new FilterRequest { FilterUid = filterUid, Name = name, FilterJson = filterJson, FilterType = filterType }); var ex = await Assert.ThrowsExceptionAsync <ServiceException>(async() => await executor.ProcessAsync(request)).ConfigureAwait(false); Assert.AreNotEqual(-1, ex.GetContent.IndexOf("2021", StringComparison.Ordinal), "executor threw exception but incorrect code"); Assert.AreNotEqual(-1, ex.GetContent.IndexOf("UpsertFilter failed. Unable to find persistent filterUid provided.", StringComparison.Ordinal), "executor threw exception but incorrect messaage"); }
public async Task UpsertFilterExecutor_Transient_DuplicateNamesShouldBeAllowed() { string custUid = Guid.NewGuid().ToString(); string userUid = UIDs.JWT_USER_ID; string projectUid = UIDs.MOCK_WEB_API_DIMENSIONS_PROJECT_UID.ToString(); string name = string.Empty; FilterType filterType = FilterType.Transient; string filterJson1 = "{\"designUid\":\"c2e5940c-4370-4d23-a930-b5b74a9fc22b\"}"; string filterJson2 = "{\"designUid\":\"c2e5940c-4370-4d23-a930-b5b74a9fc22b\",\"onMachineDesignID\":null,\"elevationType\":3,\"vibeStateOn\":true}"; var request = FilterRequestFull.Create(new HeaderDictionary(), custUid, false, userUid, new ProjectData { ProjectUID = projectUid }, new FilterRequest { Name = name, FilterJson = filterJson1, FilterType = filterType }); var result1 = await executor.ProcessAsync(request) as FilterDescriptorSingleResult; Assert.IsNotNull(result1, "executor should always return a result"); Assert.IsNotNull(result1.FilterDescriptor.FilterUid, "executor returned incorrect FilterUid"); Assert.AreEqual(name, result1.FilterDescriptor.Name, "executor returned incorrect filter Name"); Assert.AreEqual(filterJson1, result1.FilterDescriptor.FilterJson, "executor returned incorrect FilterJson"); Assert.AreEqual(filterType, result1.FilterDescriptor.FilterType, "executor returned incorrect FilterType"); request = FilterRequestFull.Create(new HeaderDictionary(), custUid, false, userUid, new ProjectData { ProjectUID = projectUid }, new FilterRequest { Name = name, FilterJson = filterJson2, FilterType = filterType }); var result2 = await executor.ProcessAsync(request).ConfigureAwait(false) as FilterDescriptorSingleResult; Assert.IsNotNull(result2, "executor should always return a result"); Assert.AreNotEqual(result1.FilterDescriptor.FilterUid, result2.FilterDescriptor.FilterUid, "executor returned incorrect FilterUid"); Assert.AreEqual(name, result2.FilterDescriptor.Name, "executor returned incorrect filter Name"); Assert.AreEqual("{\"designUid\":\"c2e5940c-4370-4d23-a930-b5b74a9fc22b\",\"elevationType\":3,\"vibeStateOn\":true}", result2.FilterDescriptor.FilterJson, "executor returned incorrect FilterJson"); Assert.AreEqual(filterType, result2.FilterDescriptor.FilterType, "executor returned incorrect FilterType"); var fr = FilterRepo.GetFiltersForProjectUser(custUid, projectUid, userUid, true); fr.Wait(); Assert.IsNotNull(fr, "should return the new filter"); Assert.AreEqual(2, fr.Result.Count(), "should return 2 new filterUid"); }
public void FilterRequestValidation_InvalidPassCountRange(FilterType filterType) { var maxPassCount = 10; var request = FilterRequestFull.Create(null, custUid, false, userUid, new ProjectData { ProjectUID = projectUid }, new FilterRequest { FilterUid = filterUid, Name = "a filter", FilterType = filterType, FilterJson = "{\"vibeStateOn\": true, \"passCountRangeMin\": null, \"passCountRangeMax\": \"" + maxPassCount + "\" }" }); var ex = Assert.Throws <ServiceException>(() => request.Validate(serviceExceptionHandler)); Assert.Contains("2073", ex.GetContent); Assert.Contains("Invalid pass count range filter. Both minimum and maximum must be provided.", ex.GetContent); }
public async Task <FilterDescriptorListResult> GetProjectFilters(string projectUid) { Log.LogInformation($"{nameof(GetProjectFilters)}: CustomerUID={CustomerUid} isApplication={IsApplication} UserUid={GetUserId} projectUid: {projectUid}"); var requestFull = FilterRequestFull.Create( Request.Headers.GetCustomHeaders(), CustomerUid, IsApplication, GetUserId, await GetProject(projectUid)); requestFull.Validate(ServiceExceptionHandler, true); var executor = RequestExecutorContainer.Build <GetFiltersExecutor>(ConfigStore, Logger, ServiceExceptionHandler, filterRepo, null, null, productivity3dV2ProxyCompaction: Productivity3dV2ProxyCompaction); var result = await executor.ProcessAsync(requestFull) as FilterDescriptorListResult; Log.LogInformation($"{nameof(GetProjectFilters)} Completed: resultCode: {result?.Code} filterCount={result?.FilterDescriptors.Count}"); return(result); }