public void UpdateTestWithoutFileUploadTest()
        {
            var analyzerController = new AnalyzerController(mockHttpContextAccessor.Object);

            var result = analyzerController.Update(null);

            var objectResult = Assert.IsType <BadRequestObjectResult>(result);
            var model        = Assert.IsAssignableFrom <string>(objectResult.Value);

            Assert.Equal("Kérem töltsön fel először fájlt!", model);
        }
        public void UpdateTest(int no)
        {
            var analyzerController = new AnalyzerController(mockHttpContextAccessor.Object);

            var file = new FileData {
                Name = "Valami", Content = System.IO.File.ReadAllText($@"..\..\..\..\AngularApp\Files\demo{no}.txt")
            };
            var value = Encoding.ASCII.GetBytes(JsonSerializer.Serialize(file));

            mockSession.Setup(_ => _.TryGetValue(Key.File.ToString("g"), out value)).Returns(true);

            var content = file.Content;

            var controlFlowGraph = P4ToGraph.ControlFlowGraph(ref content);
            var controlValue     = Encoding.ASCII.GetBytes(controlFlowGraph.ToJson());

            mockSession.Setup(_ => _.TryGetValue(Key.ControlFlowGraph.ToString("g"), out controlValue)).Returns(true);

            var dataFlowGraph = P4ToGraph.DataFlowGraph(content, controlFlowGraph);
            var dataValue     = Encoding.ASCII.GetBytes(dataFlowGraph.ToJson());

            mockSession.Setup(_ => _.TryGetValue(Key.DataFlowGraph.ToString("g"), out dataValue)).Returns(true);

            var analyzeDatas = new List <AnalyzeData>();

            for (var i = 0; i < 5; ++i)
            {
                var    structs      = Analyzer.GetStructs(file.Content);
                var    _struct      = structs.FirstOrDefault(x => x.Name == "headers_t");
                Random random       = new Random();
                var    randomNumber = random.Next(0, 2);

                var ethernet = _struct.Headers["ethernet"];
                if (randomNumber == 1)
                {
                    ethernet.Valid = true;
                    ethernet.Variables.ForEach(x => x.IsInitialize = true);
                }

                randomNumber = random.Next(0, 2);

                var ipv4 = _struct.Headers["ipv4"];
                if (randomNumber == 1)
                {
                    ipv4.Valid = true;
                    ipv4.Variables.ForEach(x => x.IsInitialize = true);
                }

                analyzeDatas.Add(new AnalyzeData
                {
                    Id         = i,
                    StartState = structs,
                    EndState   = structs
                });
            }

            var result = analyzerController.Update(analyzeDatas);

            var objectResult = Assert.IsType <OkObjectResult>(result);
            var model        = Assert.IsAssignableFrom <CalculatedData>(objectResult.Value);

            var analyzers = new List <Analyzer>();

            analyzeDatas.ForEach(x =>
            {
                analyzers.Add(new Analyzer(controlFlowGraph.ToJson(), dataFlowGraph.ToJson(), x, file.Content));
            });

            Parallel.ForEach(analyzers, (analyzer) =>
            {
                analyzer.Analyze();
                analyzer.FinishOperations();
            });

            analyzers.DistinctGraphs(out List <List <ViewNode> > controlFlowGraphs, out List <List <ViewNode> > dataFlowGraphs);
            analyzers.CreateCharts(out BarChartData readAndWriteChartData, out PieChartData useVariable, out PieChartData useful, out BarChartData headers);

            var calculateData = new CalculatedData
            {
                ControlFlowGraphs     = controlFlowGraphs,
                DataFlowGraphs        = dataFlowGraphs,
                ReadAndWriteChartData = readAndWriteChartData,
                UseVariable           = useVariable,
                Useful  = useful,
                Headers = headers,
                File    = file
            };

            Assert.Equal(calculateData.File.Name, model.File.Name);
            Assert.Equal(calculateData.File.Content, model.File.Content);
            CompareBarChartData(calculateData.ReadAndWriteChartData, model.ReadAndWriteChartData);
            CompareBarChartData(calculateData.Headers, model.Headers);
            ComparePieChartData(calculateData.UseVariable, model.UseVariable);
            ComparePieChartData(calculateData.Useful, model.Useful);
        }