Exemplo n.º 1
0
        public async Task CreateShouldSuccess()
        {
            // Arrange
            var id            = Guid.NewGuid();
            var name          = "name";
            var description   = "description";
            var image         = "image";
            var diagram       = "diagram";
            var filterContent = "{\"sources\":[{\"id\":\"dcfe1db6-2484-42c2-9d9e-a77a28a5078d\",\"name\":\"BKAL33+KBT T\",\"description\":\"Plato Chemicals Test\",\"sourceBusinessUnits\":[]}],\"operations\":[{\"id\":\"d2760435-9d0b-4b69-adce-09017f2840c6\",\"name\":\"Unload into warehouse\",\"description\":\"Unloading goods into the warehouse\",\"icon\":null,\"tags\":[\"string\"]}]}";

            var flow = new Flow(id, name);

            flow.SetDescription(description);
            flow.SetImage(image);
            flow.SetDiagram(diagram);
            flow.SetFilterContent(filterContent);

            // Act
            await _repository.CreateAsync(flow);

            // Assert
            var data = RepositoryHelper.ForFlow.GetFlows();

            data.Should().HaveCount(1);
            var result = data.First();

            result.Name.Should().Be(name);
            result.Id.Should().Be(id);
            result.Description.Should().Be(description);
            result.Image.Should().Be(image);
            result.Diagram.Should().Be(diagram);
            result.FilterContent.Should().Be(filterContent);
        }
Exemplo n.º 2
0
        public async Task <Result> Handle(CreateFlowCommand request, CancellationToken cancellationToken)
        {
            var id = _identifierProvider.Generate();

            var flowToCreate = new Flow(id, request.Name);

            if (!string.IsNullOrWhiteSpace(request.Description))
            {
                flowToCreate.SetDescription(request.Description);
            }
            if (!string.IsNullOrWhiteSpace(request.Image))
            {
                flowToCreate.SetImage(request.Image);
            }
            //command.BuildingBlocks.ToList().ForEach(x => flowToCreate.AddBuildingBlock(new BuildingBlock(x.Id, (BlockType)Enum.Parse(typeof(BlockType), x.BlockType, true))));
            //command.FreeActions.ToList().ForEach(x => flowToCreate.AddFreeAction(new BuildingBlock(x.Id, (BlockType)Enum.Parse(typeof(BlockType), x.BlockType, true))));
            //command.OperationalDepartments.ToList().ForEach(x => flowToCreate.AddOperationalDepartment(new FlowOperationalDepartment(x)));
            //command.Operations.ToList().ForEach(x => flowToCreate.AddOperation(new FlowOperation(x)));
            //command.ProductionSites.ToList().ForEach(x => flowToCreate.AddProductionSite(new FlowProductionSite(x)));
            //command.Sites.ToList().ForEach(x => flowToCreate.AddSite(new FlowSite(x)));
            //command.Sources.ToList().ForEach(x => flowToCreate.AddSource(new FlowSource(x)));
            //command.TransportTypes.ToList().ForEach(x => flowToCreate.AddTransportType(new FlowTransportType(x)));
            //command.TypePlannings.ToList().ForEach(x => flowToCreate.AddTypePlanning(new FlowTypePlanning(x)));
            //command.Customers.ToList().ForEach(x => flowToCreate.AddCustomer(new FlowCustomer(x)));

            flowToCreate.Version = _versionProvider.Generate();

            Result result;

            try
            {
                await _flowWriteRepository.CreateAsync(flowToCreate);

                result = Result.Ok(id, flowToCreate.Version);
            }
            catch (UniqueKeyException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.Conflict.Name,
                        Message = HandlerFailures.Conflict,
                        Target  = "name"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.CreateFlowFailure);
            }

            return(result);
        }