Example #1
0
        public async void AddInvalidSpanEquipmentSpecificationWithRootTemplateLevelDifferentFromOne_ShouldFail()
        {
            // Setup some span structure specifications to be used in the span equipment specification
            var outerConduitSpanStructureSpec1 = new SpanStructureSpecification(Guid.NewGuid(), "Conduit", "Ø50", "Orange")
            {
                OuterDiameter = 50,
                InnerDiameter = 45
            };
            await _commandDispatcher.HandleAsync <AddSpanStructureSpecification, Result>(new AddSpanStructureSpecification(outerConduitSpanStructureSpec1));


            // Setup a span equipment specification with level 0 in root span template.
            // Must fail, because we want the root template to always have level 1
            var spanEquipmentSpecification = new SpanEquipmentSpecification(Guid.NewGuid(), "Conduit", "Ø50 2x12",
                                                                            new SpanStructureTemplate(outerConduitSpanStructureSpec1.Id, 0, 1,
                                                                                                      new SpanStructureTemplate[] {
            }
                                                                                                      ));

            // Act
            var addSpanEquipmentSpecificationCommandResult = await _commandDispatcher.HandleAsync <AddSpanEquipmentSpecification, Result>(new AddSpanEquipmentSpecification(spanEquipmentSpecification));

            // Assert
            addSpanEquipmentSpecificationCommandResult.IsFailed.Should().BeTrue();
        }
Example #2
0
        public async void AddInvalidSpanEquipmentSpecificationWithNonUniqueLevelAndPosition_ShouldFail()
        {
            // Setup some span structure specifications to be used in the span equipment specification
            var outerConduitSpanStructureSpec1 = new SpanStructureSpecification(Guid.NewGuid(), "Conduit", "Ø50", "Orange")
            {
                OuterDiameter = 50,
                InnerDiameter = 45
            };
            await _commandDispatcher.HandleAsync <AddSpanStructureSpecification, Result>(new AddSpanStructureSpecification(outerConduitSpanStructureSpec1));

            // Add span equipment specification with two child template having same level and position
            var spanEquipmentSpecification = new SpanEquipmentSpecification(Guid.NewGuid(), "Conduit", "Ø50 2x12",
                                                                            new SpanStructureTemplate(outerConduitSpanStructureSpec1.Id, 1, 1,
                                                                                                      new SpanStructureTemplate[] {
                new SpanStructureTemplate(outerConduitSpanStructureSpec1.Id, 2, 1, Array.Empty <SpanStructureTemplate>()),
                new SpanStructureTemplate(outerConduitSpanStructureSpec1.Id, 2, 1, Array.Empty <SpanStructureTemplate>())
            }
                                                                                                      ));

            // Act
            var addSpanEquipmentSpecificationCommandResult = await _commandDispatcher.HandleAsync <AddSpanEquipmentSpecification, Result>(new AddSpanEquipmentSpecification(spanEquipmentSpecification));

            // Assert
            addSpanEquipmentSpecificationCommandResult.IsFailed.Should().BeTrue();
        }
        private async Task AddSpecification(SpanEquipmentSpecification spec)
        {
            var cmd       = new AddSpanEquipmentSpecification(Guid.NewGuid(), new UserContext("test", Guid.Empty), spec);
            var cmdResult = await _commandDispatcher.HandleAsync <AddSpanEquipmentSpecification, Result>(cmd);

            if (cmdResult.IsFailed)
            {
                throw new ApplicationException(cmdResult.Errors.First().Message);
            }
        }
        private async void AddSpecification(SpanEquipmentSpecification spec)
        {
            var cmd       = new AddSpanEquipmentSpecification(spec);
            var cmdResult = await _commandDispatcher.HandleAsync <AddSpanEquipmentSpecification, Result>(cmd);

            if (cmdResult.IsFailed)
            {
                throw new ApplicationException(cmdResult.Errors.First().Message);
            }
        }
 private static void ValidateSpanStructureSpecificationReferences(SpanEquipmentSpecification spanEquipmentSpecification, LookupCollection <SpanStructureSpecification> spanStructureSpecifications)
 {
     // Checkthat all span structures references exists
     foreach (var spanStructureTemplate in spanEquipmentSpecification.RootTemplate.GetAllSpanStructureTemplatesRecursive())
     {
         if (!spanStructureSpecifications.ContainsKey(spanStructureTemplate.SpanStructureSpecificationId))
         {
             throw new ArgumentException($"Cannot find span structure specification with id: {spanStructureTemplate.SpanStructureSpecificationId}");
         }
     }
 }
Example #6
0
        public async void AddValidMultiLevelSpanEquipmentSpecification_ShouldSucceed()
        {
            // Create manufacturer
            var manufacturer = new Manufacturer(Guid.NewGuid(), "Super Manufacturer");
            await _commandDispatcher.HandleAsync <AddManufacturer, Result>(new AddManufacturer(manufacturer));


            // Setup some span structure specifications to be used in the span equipment specification
            var outerConduitSpanStructureSpec1 = new SpanStructureSpecification(Guid.NewGuid(), "Conduit", "Ø50", "Orange")
            {
                OuterDiameter = 50,
                InnerDiameter = 45
            };
            await _commandDispatcher.HandleAsync <AddSpanStructureSpecification, Result>(new AddSpanStructureSpecification(outerConduitSpanStructureSpec1));

            var innerConduitSpanStructureSpec1 = new SpanStructureSpecification(Guid.NewGuid(), "Conduit", "Ø12/10", "Red")
            {
                OuterDiameter = 12,
                InnerDiameter = 10
            };
            await _commandDispatcher.HandleAsync <AddSpanStructureSpecification, Result>(new AddSpanStructureSpecification(innerConduitSpanStructureSpec1));

            var innerConduitSpanStructureSpec2 = new SpanStructureSpecification(Guid.NewGuid(), "Conduit", "Ø12/10", "Blue")
            {
                OuterDiameter = 12,
                InnerDiameter = 10
            };
            await _commandDispatcher.HandleAsync <AddSpanStructureSpecification, Result>(new AddSpanStructureSpecification(innerConduitSpanStructureSpec2));


            // Setup a span equipment specification with 2 levels
            var spanEquipmentSpecification = new SpanEquipmentSpecification(Guid.NewGuid(), "Conduit", "Ø50 2x12",
                                                                            new SpanStructureTemplate(outerConduitSpanStructureSpec1.Id, 1, 1,
                                                                                                      new SpanStructureTemplate[] {
                new SpanStructureTemplate(innerConduitSpanStructureSpec1.Id, 2, 1, Array.Empty <SpanStructureTemplate>()),
                new SpanStructureTemplate(innerConduitSpanStructureSpec2.Id, 2, 2, Array.Empty <SpanStructureTemplate>())
            }
                                                                                                      )
                                                                            )
            {
                Description      = "Ø50 2x12/10",
                ManufacturerRefs = new Guid[] { manufacturer.Id }
            };

            // Act
            var addSpanEquipmentSpecificationCommandResult = await _commandDispatcher.HandleAsync <AddSpanEquipmentSpecification, Result>(new AddSpanEquipmentSpecification(spanEquipmentSpecification));

            var spanEqipmentSpecificationsQueryResult = await _queryDispatcher.HandleAsync <GetSpanEquipmentSpecifications, Result <LookupCollection <SpanEquipmentSpecification> > >(new GetSpanEquipmentSpecifications());


            // Assert
            addSpanEquipmentSpecificationCommandResult.IsSuccess.Should().BeTrue();
            spanEqipmentSpecificationsQueryResult.IsSuccess.Should().BeTrue();
        }
Example #7
0
        private void AddSpecification(SpanEquipmentSpecification spec)
        {
            var cmd = new AddSpanEquipmentSpecification(Guid.NewGuid(), new UserContext("specification seeder", _specSeederId), spec);

            var cmdResult = _commandDispatcher.HandleAsync <AddSpanEquipmentSpecification, Result>(cmd).Result;

            if (cmdResult.IsFailed)
            {
                throw new ApplicationException(cmdResult.Errors.First().Message);
            }
        }
 private static void ValidateManufacturerReferences(SpanEquipmentSpecification spanEquipmentSpecification, LookupCollection <Manufacturer> manufacturer)
 {
     // Check that all manufacturer exists if provided
     if (spanEquipmentSpecification.ManufacturerRefs != null)
     {
         foreach (var manufacturerId in spanEquipmentSpecification.ManufacturerRefs)
         {
             if (!manufacturer.ContainsKey(manufacturerId))
             {
                 throw new ArgumentException($"Cannot find manufaturer with id: {manufacturerId}");
             }
         }
     }
 }
Example #9
0
        public async void AddInvalidSpanEquipmentSpecificationWithNonExistingStructureSpecification_ShouldFail()
        {
            // Setup
            var spanEquipmentIdThatDontExist = Guid.NewGuid();

            var spanEquipmentSpecification = new SpanEquipmentSpecification(Guid.NewGuid(), "Conduit", "Ø50 2x12",
                                                                            new SpanStructureTemplate(spanEquipmentIdThatDontExist, 1, 1, Array.Empty <SpanStructureTemplate>()
                                                                                                      ));

            // Act
            var addSpanEquipmentSpecificationCommandResult = await _commandDispatcher.HandleAsync <AddSpanEquipmentSpecification, Result>(new AddSpanEquipmentSpecification(spanEquipmentSpecification));

            // Assert
            addSpanEquipmentSpecificationCommandResult.IsFailed.Should().BeTrue();
        }
        private static void ValidateSpanStructureLevelAndPosition(SpanEquipmentSpecification spanEquipmentSpecification, LookupCollection <SpanStructureSpecification> spanStructureSpecifications)
        {
            // Used to check level+position uniqueness
            HashSet <(int, int)> levelPositionUsed = new HashSet <(int, int)>();

            // Root template must have level 1
            if (spanEquipmentSpecification.RootTemplate.Level != 1)
            {
                throw new ArgumentException("Root template must always have level set to 1");
            }

            levelPositionUsed.Add((spanEquipmentSpecification.RootTemplate.Level, spanEquipmentSpecification.RootTemplate.Position));

            var childsToCheck = spanEquipmentSpecification.RootTemplate.ChildTemplates;

            var expectedChildLevel = 2;

            while (childsToCheck.Length != 0)
            {
                List <SpanStructureTemplate> nextLevelChildsToCheck = new List <SpanStructureTemplate>();

                foreach (var childTemplate in childsToCheck)
                {
                    if (childTemplate.Level != expectedChildLevel)
                    {
                        throw new ArgumentException($"Expected level: {expectedChildLevel} in template referencing span structure specification: {childTemplate.SpanStructureSpecificationId}");
                    }

                    if (levelPositionUsed.Contains((childTemplate.Level, childTemplate.Position)))
                    {
                        throw new ArgumentException($"Level {childTemplate.Level} Position {childTemplate.Position} in template referencing span structure specification: {childTemplate.SpanStructureSpecificationId} is used more than once. Must be unique.");
                    }

                    levelPositionUsed.Add((childTemplate.Level, childTemplate.Position));

                    nextLevelChildsToCheck.AddRange(childTemplate.ChildTemplates);
                }

                childsToCheck = nextLevelChildsToCheck.ToArray();

                expectedChildLevel++;
            }
        }
        public void AddSpecification(CommandContext cmdContext, SpanEquipmentSpecification spanEquipmentSpecification, LookupCollection <SpanStructureSpecification> spanStructureSpecifications, LookupCollection <Manufacturer> manufacturer)
        {
            if (_spanEquipmentSpecifications.ContainsKey(spanEquipmentSpecification.Id))
            {
                throw new ArgumentException($"A span equipment specification with id: {spanEquipmentSpecification.Id} already exists");
            }

            ValidateSpanStructureSpecificationReferences(spanEquipmentSpecification, spanStructureSpecifications);
            ValidateManufacturerReferences(spanEquipmentSpecification, manufacturer);
            ValidateSpanStructureLevelAndPosition(spanEquipmentSpecification, spanStructureSpecifications);

            RaiseEvent(
                new SpanEquipmentSpecificationAdded(spanEquipmentSpecification)
            {
                CorrelationId = cmdContext.CorrelationId,
                IncitingCmdId = cmdContext.CmdId,
                UserName      = cmdContext.UserContext?.UserName,
                WorkTaskId    = cmdContext.UserContext?.WorkTaskId
            }
                );
        }
Example #12
0
        private static NamingInfo CalculateName(IEventStore eventStore, NamingInfo namingInfo, SpanEquipmentSpecification spec)
        {
            if (spec.Category != null && spec.Category.ToLower().Contains("conduit"))
            {
                var nextConduitSeqStr = eventStore.Sequences.GetNextVal("conduit").ToString();

                var conduitName = "R" + nextConduitSeqStr.PadLeft(6, '0');
                namingInfo = new NamingInfo(conduitName, null);
            }
            else if (spec.Category != null && spec.Category.ToLower().Contains("cable"))
            {
                var nextCableSeqStr = eventStore.Sequences.GetNextVal("cable").ToString();

                var conduitName = "K" + nextCableSeqStr.PadLeft(6, '0');
                namingInfo = new NamingInfo(conduitName, null);
            }

            return(namingInfo);
        }