public void Verify_verify_file_information_is_deleted_when_song_is_deleted() { // add dependent object var fileInformation = TestCaseService.SetupFileInformation(ExistingItem); base.VerifyDependentObjectIsDeletedWhenDeletingEntity(fileInformation, ExistingItem); }
protected override void Establish_context() { LoadConfiguration(); DbProviderFactories.RegisterFactory("System.Data.SqlClient", SqlClientFactory.Instance); var dir = TestContext.CurrentContext.TestDirectory; Directory.SetCurrentDirectory(dir); SetupServiceProvider(); Context = ServiceProvider.GetService <ShoppingDbContext>(); TestCaseService = new TestCaseService(Context); //if (ShouldLoadTestObjects) //{ // MusicObjects = new ShoppingTestsDataObjects(Context); // MusicObjects.LoadObjects(); //} TestStartedDatTime = DateTime.Now; base.Establish_context(); }
public async Task TestAddTestCaseFilesAsync_InvalidType() { // Arrange var dbContext = AppDBContextMocker.GetAppDbContext(nameof(TestAddTestCaseFilesAsync_InvalidType)); var tcService = new TestCaseService(new TestCaseRepository(dbContext), new UnitOfWork(dbContext), null); //auto mapper configuration var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new ResourceToModelProfile()); cfg.AddProfile(new ModelToResourceProfile()); }); var testModel = new SaveTestCaseResource() { Name = "Mad Max: Fury Road", Type = 10, //Type doesn't exist StepCount = 2, FolderId = 100, }; // Act var controller = new TestCaseFilesController(tcService, mockMapper.CreateMapper(), null); var response = await controller.AddTestCaserAsync(testModel) as ObjectResult; dbContext.Dispose(); // Assert Assert.NotNull(response); var rModel = response.Value as TestCaseResource; Assert.Null(rModel); }
public async Task TestListTestCaseFilesAsync_NotFound() { // Arrange var dbContext = AppDBContextMocker.GetAppDbContext(nameof(TestListTestCaseFilesAsync)); var tcService = new TestCaseService(new TestCaseRepository(dbContext), new UnitOfWork(dbContext), null); //auto mapper configuration var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new ResourceToModelProfile()); cfg.AddProfile(new ModelToResourceProfile()); }); // Act var controller = new TestCaseFilesController(tcService, mockMapper.CreateMapper(), null); var response = await controller.ListAsync(100) as IEnumerable <TestCaseResource>; dbContext.Dispose(); Assert.NotNull(response); Assert.Empty(response); }
public async Task TestDeleteTestCaseFilesAsync_Valid() { // Arrange var dbContext = AppDBContextMocker.GetAppDbContext(nameof(TestListTestCaseFilesAsync)); var tcService = new TestCaseService(new TestCaseRepository(dbContext), new UnitOfWork(dbContext), null); //auto mapper configuration var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new ResourceToModelProfile()); cfg.AddProfile(new ModelToResourceProfile()); }); var controller = new TestCaseFilesController(tcService, mockMapper.CreateMapper(), null); // Act var response = await controller.DeleteTestCaseFileAsync(101) as ObjectResult; dbContext.Dispose(); // Assert Assert.NotNull(response); var deletedModel = response.Value as TestCaseResource; Assert.NotNull(deletedModel); Assert.Equal("Email.txt", deletedModel.Name); Assert.Equal(3, deletedModel.Type); Assert.Equal(2, deletedModel.StepCount); Assert.Null(deletedModel.FolderId); }
public void Initialize() { var mocker = new AutoMocker(); _repoMock = mocker.GetMock <IDataRepo>(); _service = new TestCaseService(_repoMock.Object); }
public void Execute_test_case_with_correct_content_is_ok() { var content = new StringBuilder(); content.AppendLine("2"); content.AppendLine("4 5"); content.AppendLine("UPDATE 2 2 2 4"); content.AppendLine("QUERY 1 1 1 3 3 3"); content.AppendLine("UPDATE 1 1 1 23"); content.AppendLine("QUERY 2 2 2 4 4 4"); content.AppendLine("QUERY 1 1 1 3 3 3"); content.AppendLine("2 4"); content.AppendLine("UPDATE 2 2 2 1"); content.AppendLine("QUERY 1 1 1 1 1 1"); content.AppendLine("QUERY 1 1 1 2 2 2"); content.AppendLine("QUERY 2 2 2 2 2 2"); var expectedResult = new List <long> { 4, 4, 27, 0, 1, 1 }; var creator = new Mock <IOperationCreator>(); creator.Setup(x => x.CreateOperation("UPDATE")).Returns(new UpdateOperation()); creator.Setup(x => x.CreateOperation("QUERY")).Returns(new QueryOperation()); var service = new TestCaseService(creator.Object); var result = service.Execute(content.ToString()); Assert.Equal(expectedResult, result); }
public ActionResult ExecuteTestCase(ExecuteTestCaseModel model) { if (!ModelState.IsValid) { return(RedirectToAction("Index")); } try { IOperationCreator creator = new OperationCreator(); ITestCaseService service = new TestCaseService(creator); var result = service.Execute(model.Content); TestCaseResultModel resultModel = new TestCaseResultModel() { Conten = model.Content, Result = result }; return(View("Result", resultModel)); } catch { return(View("Error")); } }
public DetailModel( SubmissionService submissionService, TestCaseService testCaseService, TestService testService) { _submissionService = submissionService; _testCaseService = testCaseService; _testService = testService; }
public DetailModel(ILogger <DetailModel> logger, SubmissionService submissionService, TestCaseService testCaseService, IAuthorizationService authService, TestService testService) { _logger = logger; _submissionService = submissionService; _testCaseService = testCaseService; _authService = authService; _testService = testService; }
public void Execute_with_empty_content_will_fail() { var creator = new Mock <IOperationCreator>(); creator.Setup(x => x.CreateOperation("UPDATE")).Returns(new UpdateOperation()); creator.Setup(x => x.CreateOperation("QUERY")).Returns(new QueryOperation()); var service = new TestCaseService(creator.Object); var ex = Assert.Throws <ArgumentException>(() => service.Execute("")); Assert.Equal("Content is empty.", ex.Message); }
public CreateModel(ILogger <CreateModel> logger, TestCaseService testCaseService) { _logger = logger; _testCaseService = testCaseService; }
public IndexModel(TestCaseService testCaseService) { _testCaseService = testCaseService; }
public TestCaseController(TestCaseService testCaseService) { _testCaseService = testCaseService; }
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 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(); } }