Ejemplo n.º 1
0
        public async Task <ActionResult <IEnumerable <TestRunCaseDto> > > AddTestCases([FromBody] TestCasesModel model)
        {
            if (ModelState.IsValid)
            {
                var testCases = await _runService.AddTestCases(
                    model.ProjectId, model.TestRunId, model.TestCasesIds);

                return(Created("", testCases));
            }

            return(BadRequest());
        }
Ejemplo n.º 2
0
        public async Task AddCasesToRunTest()
        {
            // In-memory database only exists while the connection is open
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <ProjectRespository>()
                              .UseSqlite(connection)
                              .Options;

                long projectId  = 0;
                long rootSuitId = 0;
                long suitId     = 0;
                long testRunId  = 0;
                // Create the schema in the database
                using (var context = new ProjectRespository(options))
                {
                    context.Database.EnsureCreated();

                    var projectService = new ProjectService(context);
                    var project        = await projectService.AddProjectAsync("test name", "test description");

                    projectId  = project.Id;
                    rootSuitId = 1;

                    var suitService = new SuitService(context);
                    var suit        = await suitService.AddSuitAsync("suit name", "suit description", projectId);

                    suitId = suit.Id;

                    var testCaseService = new TestCaseService(context);

                    var testCase = await testCaseService.AddTestCaseAsync(
                        "name0", "description0", "expected0", projectId, rootSuitId,
                        new List <Step> {
                        new Step(0, "description", "expectedResult")
                    });

                    var testCase1 = await testCaseService.AddTestCaseAsync(
                        "name1", "description1", "expected1", projectId, rootSuitId, null);

                    var testCase2 = await testCaseService.AddTestCaseAsync(
                        "name2", "description2", "expected2", projectId, suitId, new List <Step> {
                        new Step(1, "description", "expectedResult")
                    });

                    var testCase3 = await testCaseService.AddTestCaseAsync(
                        "name3", "description3", "expected3", projectId, suitId, null);

                    var testRunService = new TestRunService(context);
                    var testRun        = await testRunService.AddTestRunAsync(projectId, "first test run",
                                                                              "first description", new HashSet <long> {
                        2
                    });

                    await testRunService.AddTestRunAsync(projectId, "second test run",
                                                         "second description", new HashSet <long> {
                        2, 1
                    });

                    testRunId = testRun.Id;
                }

                // Run the test against one instance of the context
                using (var repository = new ProjectRespository(options))
                {
                    var testRunService = new TestRunService(repository);
                    await testRunService.AddTestCases(projectId, testRunId, new HashSet <long> {
                        2, 4, 1
                    });
                }

                // Use a separate instance of the context to verify correct data was saved to database

                using (var context = new ProjectRespository(options))
                {
                    // 2 + root suit
                    Assert.Equal(2, context.TestRuns.Count());
                    Assert.Equal(5, context.TestRunCases.Count());
                    Assert.Equal(2, context.TestRunSteps.Count());
                    Assert.Equal(2, context.TestRuns.Count());

                    var project = await context.GetAsync(projectId, testRunId);

                    Assert.Collection(project.TestRuns, item =>
                    {
                        Assert.NotNull(item.TestCases);
                        Assert.NotEmpty(item.TestCases);

                        Assert.Collection(item.TestCases,
                                          testCase =>
                        {
                            Assert.NotNull(testCase.TestCase);
                            Assert.Equal(2, testCase.TestCase.Id);
                            Assert.Equal(TestCaseStatus.None, testCase.Status);
                            Assert.NotNull(testCase.Steps);
                            Assert.Empty(testCase.Steps);
                        },
                                          testCase =>
                        {
                            Assert.NotNull(testCase.TestCase);
                            Assert.Equal(1, testCase.TestCase.Id);
                            Assert.Equal(TestCaseStatus.None, testCase.Status);
                            Assert.NotNull(testCase.Steps);
                            Assert.NotEmpty(testCase.Steps);

                            Assert.Collection(testCase.Steps, step =>
                            {
                                Assert.NotNull(step.Step);
                                Assert.Equal(StepRunStatus.None, step.Status);
                            });
                        },
                                          testCase =>
                        {
                            Assert.NotNull(testCase.TestCase);
                            Assert.Equal(4, testCase.TestCase.Id);
                            Assert.Equal(TestCaseStatus.None, testCase.Status);
                            Assert.NotNull(testCase.Steps);
                            Assert.Empty(testCase.Steps);
                        });
                    }, testRun => { });
                }
            }
            finally
            {
                connection.Close();
            }
        }