public async Task GetAllTest() { // 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; // Create the schema in the database using (var context = new ProjectRespository(options)) { context.Database.EnsureCreated(); } // Run the test against one instance of the context using (var repository = new ProjectRespository(options)) { var projectService = new ProjectService(repository); await projectService.AddProjectAsync("test name 1", "test description 1"); await projectService.AddProjectAsync("test name 2", "test description 2"); } // Use a separate instance of the context to verify correct data was saved to database using (var context = new ProjectRespository(options)) { var projectService = new ProjectService(context); var projects = await projectService.GetAllAsync(); Assert.Collection(projects, project => { Assert.Equal(1, project.Id); Assert.Equal("test name 1", project.Name); Assert.Equal("test description 1", project.Description); }, project => { Assert.Equal(2, project.Id); Assert.Equal("test name 2", project.Name); Assert.Equal("test description 2", project.Description); }); } } finally { connection.Close(); } }
public EmployeeCreateForm(ProjectRespository projectRepository) { InitializeComponent(); _projectRepository = projectRepository; foreach (var job in Enum.GetValues(typeof(Job))) { employeeJobComboBox.Items.Add(job); } employeeJobComboBox.DropDownStyle = ComboBoxStyle.DropDownList; _projectRepository.GetAllProjects().ForEach(project => employeeProjectsCheckedListBox.Items.Add(project)); }
public async Task AddProjectTest() { // 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; // Create the schema in the database using (var context = new ProjectRespository(options)) { context.Database.EnsureCreated(); } // Run the test against one instance of the context using (var repository = new ProjectRespository(options)) { var projectService = new ProjectService(repository); var project = await projectService.AddProjectAsync("test name", "test description"); Assert.NotEqual(0, project.Id); } // Use a separate instance of the context to verify correct data was saved to database using (var context = new ProjectRespository(options)) { var project = await context.GetAsync(1); Assert.Equal(1, context.Projects.Count()); Assert.Equal("test name", project.Name); Assert.Equal("test description", project.Description); Assert.NotEqual(0, project.Id); Assert.NotNull(project.Suits); Assert.NotNull(project.RootSuit); Assert.NotNull(project.TestRuns); } } finally { connection.Close(); } }
public async Task AddSuitTest() { // 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; // 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; } // Run the test against one instance of the context using (var repository = new ProjectRespository(options)) { var suitService = new SuitService(repository); var suit = await suitService.AddSuitAsync("suit name", "suit description", projectId); Assert.NotEqual(0, suit.Id); var child = await suitService.AddSuitAsync("child name", "child description", projectId, suit.Id); await Assert.ThrowsAsync <ArgumentException>(async() => await suitService.AddSuitAsync("child name", "child description", 5, suit.Id)); } // 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(3, context.Suits.Count()); var project = await context.GetAsync(projectId); Assert.Collection(project.Suits, item => { Assert.Equal("suit name", item.Name); Assert.Equal("suit description", item.Description); Assert.NotNull(item.ParentSuit); Assert.Equal(item.ParentSuit, project.RootSuit); }, item => { Assert.Equal("child name", item.Name); Assert.Equal("child description", item.Description); Assert.NotNull(item.ParentSuit); }); } } finally { connection.Close(); } }
public Menu() { InitializeComponent(); _employeeRepository = new EmployeeRepository(); _projectRepository = new ProjectRespository(); }
public async Task AddTestCaseTest() { // 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; // 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; } // Run the test against one instance of the context using (var repository = new ProjectRespository(options)) { var testCaseService = new TestCaseService(repository); var testCase = await testCaseService.AddTestCaseAsync( "name0", "description0", "expected0", projectId, rootSuitId, new List <Step> { new Step(0, "description", "expectedResult") }); Assert.NotEqual(0, testCase.Id); Assert.Collection(testCase.Steps, item => { Assert.Equal("description", item.Description); Assert.Equal("expectedResult", item.ExpectedResult); Assert.Equal(0, item.Order); Assert.NotEqual(0, item.Id); }); var testCase1 = await testCaseService.AddTestCaseAsync( "name1", "description1", "expected1", projectId, rootSuitId, null); Assert.Equal <int>(1, testCase1.Order); await Assert.ThrowsAsync <ArgumentException>(async() => await testCaseService.AddTestCaseAsync( "name0", "description0", "expected0", projectId + 1, rootSuitId, new List <Step> { new Step(0, "description", "expectedResult") })); 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); } // 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(4, context.TestCases.Count()); Assert.Equal(2, context.Suits.Count()); Assert.Equal(1, context.Projects.Count()); Assert.Equal(2, context.Steps.Count()); var project = await context.GetAsync(projectId); Assert.Collection(project.RootSuit.TestCases, item => { Assert.Equal("name0", item.Name); Assert.Equal("description0", item.Description); Assert.NotNull(item.Steps); Assert.NotEmpty(item.Steps); Assert.Equal <int>(0, item.Order); Assert.Collection(item.Steps, step => { Assert.Equal("description", step.Description); Assert.Equal("expectedResult", step.ExpectedResult); Assert.Equal(0, step.Order); }); }, item => { Assert.Equal("name1", item.Name); Assert.Equal("description1", item.Description); Assert.NotNull(item.Steps); Assert.Equal <int>(1, item.Order); }); Assert.Collection(project.Suits[0].TestCases, item => { Assert.Equal("name2", item.Name); Assert.Equal("description2", item.Description); Assert.NotNull(item.Steps); Assert.NotEmpty(item.Steps); Assert.Equal <int>(0, item.Order); Assert.Collection(item.Steps, step => { Assert.Equal("description", step.Description); Assert.Equal("expectedResult", step.ExpectedResult); Assert.Equal(1, step.Order); }); }, item => { Assert.Equal("name3", item.Name); Assert.Equal("description3", item.Description); Assert.NotNull(item.Steps); Assert.Equal <int>(1, item.Order); }); } } finally { connection.Close(); } }
public async Task GetTest() { // 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; // Create the schema in the database using (var context = new ProjectRespository(options)) { context.Database.EnsureCreated(); } // Run the test against one instance of the context using (var repository = new ProjectRespository(options)) { var projectService = new ProjectService(repository); await projectService.AddProjectAsync("test name 1", "test description 1"); var suitService = new SuitService(repository); await suitService.AddSuitAsync("suit level 1", "suit description 1", 1, 1); await suitService.AddSuitAsync("suit level 2", "suit description 2", 1, 2); await suitService.AddSuitAsync("suit level 1.1", "suit description 1.1", 1, 1); await suitService.AddSuitAsync("suit level 3", "suit description 3", 1, 3); var testCaseService = new TestCaseService(repository); await testCaseService.AddTestCaseAsync("test case 1", "descr 1", "expected 1", 1, 1, new List <Step> { new Step(0, "step descr 1", "expected 1"), new Step(1, "step descr 2", "expected 2") }); await testCaseService.AddTestCaseAsync("test case 2", "descr 2", "expected 2", 1, 5, new List <Step> { new Step(0, "step descr 3", "expected 3"), new Step(1, "step descr 4", "expected 4") }); await testCaseService.AddTestCaseAsync("test case 3", "descr 3", "expected 3", 1, 5, null); } // Use a separate instance of the context to verify correct data was saved to database using (var context = new ProjectRespository(options)) { var projectService = new ProjectService(context); var project = await projectService.GetAsync(1); Assert.Equal(1, project.RootSuit.Id); Assert.Equal("root", project.RootSuit.Name); Assert.Equal("root", project.RootSuit.Description); Assert.Collection(project.RootSuit.TestCases, testCase => { Assert.Equal("test case 1", testCase.Name); Assert.Equal("descr 1", testCase.Description); Assert.Equal("expected 1", testCase.ExpectedResult); Assert.Collection(testCase.Steps, step => { Assert.Equal("step descr 1", step.Description); Assert.Equal("expected 1", step.ExpectedResult); Assert.Equal(0, step.Order); }, step => { Assert.Equal("step descr 2", step.Description); Assert.Equal("expected 2", step.ExpectedResult); Assert.Equal(1, step.Order); }); }); Assert.Collection(project.RootSuit.Suits, suit => { Assert.Equal(2, suit.Id); Assert.Equal("suit level 1", suit.Name); Assert.Equal("suit description 1", suit.Description); Assert.Collection(suit.Suits, suit1 => { Assert.Equal(3, suit1.Id); Assert.Equal("suit level 2", suit1.Name); Assert.Equal("suit description 2", suit1.Description); Assert.Collection(suit1.Suits, suit2 => { Assert.Equal(5, suit2.Id); Assert.Equal("suit level 3", suit2.Name); Assert.Equal("suit description 3", suit2.Description); Assert.Null(suit2.Suits); Assert.Collection(suit2.TestCases, testCase => { Assert.Equal("test case 2", testCase.Name); Assert.Equal("descr 2", testCase.Description); Assert.Equal("expected 2", testCase.ExpectedResult); Assert.Collection(testCase.Steps, step => { Assert.Equal("step descr 3", step.Description); Assert.Equal("expected 3", step.ExpectedResult); Assert.Equal(0, step.Order); }, step => { Assert.Equal("step descr 4", step.Description); Assert.Equal("expected 4", step.ExpectedResult); Assert.Equal(1, step.Order); }); }, testCase => { Assert.Equal("test case 3", testCase.Name); Assert.Equal("descr 3", testCase.Description); Assert.Equal("expected 3", testCase.ExpectedResult); }); }); }); }, suit => { Assert.Equal(4, suit.Id); Assert.Equal("suit level 1.1", suit.Name); Assert.Equal("suit description 1.1", suit.Description); Assert.Null(suit.Suits); }); } } finally { connection.Close(); } }
public ProjectsListForm(ProjectRespository projectRespository) { InitializeComponent(); _projectRespository = projectRespository; RefreshProjects(); }
public async Task AddTestRunTest() { // 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; // 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); } // Run the test against one instance of the context using (var repository = new ProjectRespository(options)) { var testRunService = new TestRunService(repository); var testRun = await testRunService.AddTestRunAsync(projectId, "first test run", "first description", new HashSet <long> { 2, 1 }); var testRun2 = await testRunService.AddTestRunAsync(projectId, "second test run", "second description", new HashSet <long> { 2, 1, 4 }); } // 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()); var project = await context.GetAsync(projectId, 1); await context.GetAsync(projectId, 2); // just for loading data into memory Assert.Collection(project.TestRuns, item => { Assert.Equal("first test run", item.Name); Assert.Equal("first description", item.Description); Assert.NotNull(item.TestCases); Assert.NotEmpty(item.TestCases); Assert.Collection(item.TestCases, 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(2, testCase.TestCase.Id); Assert.Equal(TestCaseStatus.None, testCase.Status); Assert.NotNull(testCase.Steps); Assert.Empty(testCase.Steps); }); }, item => { Assert.Equal("second test run", item.Name); Assert.Equal("second description", item.Description); Assert.NotNull(item.TestCases); Assert.NotEmpty(item.TestCases); Assert.Collection(item.TestCases, 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(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(4, testCase.TestCase.Id); Assert.Equal(TestCaseStatus.None, testCase.Status); Assert.NotNull(testCase.Steps); Assert.Empty(testCase.Steps); }); }); } } finally { connection.Close(); } }
public async Task RemoveTest() { // 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; // Create the schema in the database using (var context = new ProjectRespository(options)) { context.Database.EnsureCreated(); } // Run the test against one instance of the context using (var repository = new ProjectRespository(options)) { var projectService = new ProjectService(repository); await projectService.AddProjectAsync("test name 1", "test description 1"); var suitService = new SuitService(repository); await suitService.AddSuitAsync("suit level 1", "suit description 1", 1, 1); await suitService.AddSuitAsync("suit level 2", "suit description 2", 1, 2); await suitService.AddSuitAsync("suit level 1.1", "suit description 1.1", 1, 1); await suitService.AddSuitAsync("suit level 3", "suit description 3", 1, 3); var testCaseService = new TestCaseService(repository); await testCaseService.AddTestCaseAsync("test case 1", "descr 1", "expected 1", 1, 1, new List <Step> { new Step(0, "step descr 1", "expected 1"), new Step(1, "step descr 2", "expected 2") }); await testCaseService.AddTestCaseAsync("test case 2", "descr 2", "expected 2", 1, 5, new List <Step> { new Step(0, "step descr 3", "expected 3"), new Step(1, "step descr 4", "expected 4") }); await testCaseService.AddTestCaseAsync("test case 3", "descr 3", "expected 3", 1, 5, null); } // Use a separate instance of the context to verify correct data was saved to database using (var context = new ProjectRespository(options)) { var projectService = new ProjectService(context); await projectService.RemoveAsync(1); var project = projectService.GetAsync(1).Result; Assert.NotNull(project); Assert.True(project.State == ProjectAggregateState.Deleted); } } finally { connection.Close(); } }