Example #1
0
        /// <summary>
        /// Filter validation common to APIs passing 3dp Filter/s
        /// </summary>
        /// <param name="method"></param>
        /// <param name="projectUid"></param>
        /// <param name="filterResult"></param>
        /// <exception cref="ServiceException"></exception>
        protected void ValidateFilterMachines(string method, Guid?projectUid, FilterResult filterResult)
        {
            if (projectUid == null || projectUid == Guid.Empty)
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError,
                                                                       $"Invalid project UID {projectUid}"));
            }
            var siteModel = GatewayHelper.ValidateAndGetSiteModel(method, projectUid.Value);

            if (filterResult?.ContributingMachines != null)
            {
                GatewayHelper.ValidateMachines(filterResult.ContributingMachines.Select(m => m.AssetUid).ToList(), siteModel);
            }

            if (filterResult != null && !string.IsNullOrEmpty(filterResult.OnMachineDesignName))
            {
                var machineDesign = siteModel.SiteModelMachineDesigns.Locate(filterResult.OnMachineDesignName);
                if (machineDesign == null)
                {
                    throw new ServiceException(HttpStatusCode.BadRequest,
                                               new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError,
                                                                           $"Unknown DesignName: {filterResult.OnMachineDesignName}."));
                }

                filterResult.OnMachineDesignId = machineDesign.Id;
            }
        }
Example #2
0
        public void GatewayHelper_NoMachines()
        {
            var siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(DITagFileFixture.NewSiteModelGuid, true);

            var contributingMachines = new List <Guid?>();

            GatewayHelper.ValidateMachines(contributingMachines, siteModel);
        }
Example #3
0
        public void GatewayHelper_NoContributingMachines()
        {
            var siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(DITagFileFixture.NewSiteModelGuid, true);
            var machine   = siteModel.Machines.CreateNew("Test Machine 1", "", MachineType.Dozer, DeviceTypeEnum.SNM940, false, Guid.NewGuid());

            var contributingMachines = new List <Guid?>();

            GatewayHelper.ValidateMachines(contributingMachines, siteModel);
        }
Example #4
0
        public void GatewayHelper_ContributingMachineEmptyGuid()
        {
            var siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(DITagFileFixture.NewSiteModelGuid, true);
            var machine   = siteModel.Machines.CreateNew("Test Machine 1", "", MachineType.Dozer, DeviceTypeEnum.SNM940, false, Guid.NewGuid());

            var contributingMachines = new List <Guid?> {
                new Guid()
            };
            var result = Assert.Throws <ServiceException>(() => GatewayHelper.ValidateMachines(contributingMachines, siteModel));

            result.Code.Should().Be(HttpStatusCode.BadRequest);
            result.GetResult.Code.Should().Be(ContractExecutionStatesEnum.ValidationError);
            result.GetResult.Message.Should().Be($"ValidateMachines: SiteModel: {siteModel.ID} machineUid not found: {contributingMachines[0]}");
        }
Example #5
0
        public void GatewayHelper_ContributingMachineMultiExists()
        {
            var siteModel = DIContext.Obtain <ISiteModels>().GetSiteModel(DITagFileFixture.NewSiteModelGuid, true);
            var machine1  = siteModel.Machines.CreateNew("Test Machine 1", "", MachineType.Dozer, DeviceTypeEnum.SNM940, false, Guid.NewGuid());
            var machine2  = siteModel.Machines.CreateNew("Test Machine 2", "", MachineType.Dozer, DeviceTypeEnum.SNM940, true, Guid.NewGuid());
            var machine3  = siteModel.Machines.CreateNew("Test Machine 3", "", MachineType.Dozer, DeviceTypeEnum.SNM940, false, Guid.NewGuid());

            var contributingMachines = new List <Guid?>
            {
                new Guid(machine3.ID.ToString()),
                new Guid(machine2.ID.ToString())
            };

            GatewayHelper.ValidateMachines(contributingMachines, siteModel);
        }