public void Given_Grade_When_DeleteGradeAsync_Then_ShouldBeTrue() { RunOnDatabase(context => { // ARRANGE context.Roles.Add(Role.Create("student")); context.SaveChanges(); var userType = context.Roles.FirstOrDefault(); if (userType != null) { context.Users.Add(User.Create("User first name", "User last name", "User1", "*****@*****.**", "parola")); } context.SaveChanges(); var user = context.Users.FirstOrDefault(); if (user == null) { return; } context.Groups.Add(Group.Create("Grup", "Grup mare", user.Id)); context.SaveChanges(); context.TestTypes.Add(TestType.Create("Grila")); context.SaveChanges(); var testType = context.TestTypes.FirstOrDefault(); if (testType != null) { context.Tests.Add(Test.Create("Test", "Test surpriza", user.Id, testType.Id)); } context.SaveChanges(); var test = context.Tests.FirstOrDefault(); var group = context.Groups.FirstOrDefault(); if (group != null && test != null) { context.TestInstances.Add(TestInstance.Create(50, @group.Id, test.Id, DateTime.Now)); } context.SaveChanges(); var testInstance = context.TestInstances.FirstOrDefault(); var gradesRepository = new GradesRepository(context); if (testInstance != null) { var grade = Grade.Create(7, user.Id, testInstance.Id); context.Add(grade); context.SaveChanges(); // ACT var result = gradesRepository.DeleteGradeAsync(grade.UserId, grade.TestInstanceId); // ASSERT result.Result.Should().Be(true); } }); }
public void Given_Test_When_UpdateTestAsync_Then_ShouldBeTrue() { RunOnDatabase(context => { // ARRANGE context.Roles.Add(Role.Create("student")); context.SaveChanges(); var userType = context.Roles.FirstOrDefault(); if (userType != null) { context.Users.Add(User.Create( "John", "Mark", "john.mar", "*****@*****.**", "password" ) ); } context.SaveChanges(); var user = context.Users.FirstOrDefault(); context.TestTypes.Add(TestType.Create("grila")); context.SaveChanges(); var testType = context.TestTypes.FirstOrDefault(); var testsRepository = new TestsRepository(context); if (user == null) { return; } if (testType == null) { return; } var test = Test.Create( "mytest", "descriere", user.Id, testType.Id ); context.Add(test); context.SaveChanges(); test.Update("test2", "descrierile", user.Id, testType.Id, false); // ACT var result = testsRepository.UpdateAsync(test); // ASSERT result.Result.Should().Be(true); }); }
public void Given_Answer_When_UpdateAnswerAsync_Then_ShouldBeTrue() { RunOnDatabase(context => { // ARRANGE var databaseContext = context; var answersRepository = new AnswersRepository(context); databaseContext.Roles.Add(Role.Create("student")); databaseContext.SaveChanges(); var userType = databaseContext.Roles.FirstOrDefault(); databaseContext.TestTypes.Add(TestType.Create("Grila")); databaseContext.SaveChanges(); var testType = databaseContext.TestTypes.FirstOrDefault(); if (userType != null) { databaseContext.Users.Add(User.Create("User first name", "User last name", "User1", "*****@*****.**", "#$$RR#$TED")); } databaseContext.SaveChanges(); var user = databaseContext.Users.FirstOrDefault(); if (user != null && testType != null) { databaseContext.Tests.Add(Test.Create("NumeleTestului", "DescriereaTextului", user.Id, testType.Id)); } databaseContext.SaveChanges(); var test = databaseContext.Tests.FirstOrDefault(); if (test != null) { databaseContext.Exercises.Add(Exercise.Create("Problema1", test.Id)); } databaseContext.SaveChanges(); var exercise = databaseContext.Exercises.FirstOrDefault(); if (exercise == null) { return; } var answer = Answer.Create("RaspunsProblema1", true, exercise.Id); databaseContext.Add(answer); databaseContext.SaveChanges(); answer.Update("Raspuns Problema 2", false, exercise.Id, false); // ACT var result = answersRepository.UpdateAsync(answer); // ASSERT result.Result.Should().Be(true); }); }
public async Task InsertTestTypesData() { var testTypeNames = TestTypesConstants.GetTestTypeNames(); foreach (var testTypeName in testTypeNames) { var testType = TestType.Create(testTypeName); await _testTypesRepository.InsertAsync(testType); } await _databaseContext.SaveChangesAsync(); }
public void Given_Answer_When_NewAnswerIsAdded_Then_ShouldHaveOneAnswerInDatabase() { RunOnDatabase(context => { // ARRANGE DatabaseContext databaseContext = context; var answersRepository = new AnswersRepository(context); databaseContext.Roles.Add(Role.Create("student")); databaseContext.SaveChanges(); var userType = databaseContext.Roles.FirstOrDefault(); databaseContext.TestTypes.Add(TestType.Create("Grila")); databaseContext.SaveChanges(); var testType = databaseContext.TestTypes.FirstOrDefault(); if (userType != null) { databaseContext.Users.Add(User.Create("Johny", "Bravo", "ohnnybravo", "*****@*****.**", "#$$RR#$TED")); } databaseContext.SaveChanges(); var user = databaseContext.Users.FirstOrDefault(); if (user != null && testType != null) { databaseContext.Tests.Add(Test.Create("NumeleTestului", "DescriereaTextului", user.Id, testType.Id)); } databaseContext.SaveChanges(); var test = databaseContext.Tests.FirstOrDefault(); if (test != null) { databaseContext.Exercises.Add(Exercise.Create("Problema1", test.Id)); } databaseContext.SaveChanges(); var exercise = databaseContext.Exercises.FirstOrDefault(); if (exercise == null) { return; } var answer = Answer.Create("RaspunsProblema1", true, exercise.Id); var answerInserted = answersRepository.InsertAsync(answer).Result; // ACT var result = answersRepository.GetByIdAsync(answerInserted.Id); // ASSERT result.Should().NotBe(null); }); }
public void Given_Test_When_NewTestIsAdded_Then_ShouldHaveOneTestInDatabase() { RunOnDatabase(context => { // ARRANGE context.Roles.Add(Role.Create("student")); context.SaveChanges(); var userType = context.Roles.FirstOrDefault(); if (userType != null) { context.Users.Add(User.Create( "John", "Mark", "john.mar", "*****@*****.**", "password" ) ); } context.SaveChanges(); var user = context.Users.FirstOrDefault(); context.TestTypes.Add(TestType.Create("grila")); context.SaveChanges(); var testType = context.TestTypes.FirstOrDefault(); var testsRepository = new TestsRepository(context); if (user == null) { return; } if (testType == null) { return; } var test = Test.Create( "mytest", "descriere", user.Id, testType.Id ); var testInserted = testsRepository.InsertAsync(test).Result; // ACT var result = testsRepository.GetByIdAsync(testInserted.Id); // ASSERT result.Should().NotBe(null); }); }
public void Given_TestType_When_DeleteTestTypeAsync_Then_ShouldBeTrue() { RunOnDatabase(context => { // ARRANGE var testTypeRepository = new TestTypesRepository(context); var testType = TestType.Create("grila"); context.TestTypes.Add(testType); context.SaveChanges(); // ACT var result = testTypeRepository.DeleteAsync(testType.Id); // ASSERT result.Result.Should().Be(true); }); }
public void Given_TestType_When_NewTestTypeIsAdded_Then_ShouldHaveOneTestTypeInDatabase() { RunOnDatabase(context => { // ARRANGE var testTypeRepository = new TestTypesRepository(context); var testType = TestType.Create("grila"); var testTypeInserted = testTypeRepository.InsertAsync(testType).Result; // ACT var result = testTypeRepository.GetByIdAsync(testTypeInserted.Id); // ASSERT result.Should().NotBe(null); }); }
public void Given_Exercise_When_UpdateExerciseAsync_Then_ShouldBeTrue() { RunOnDatabase(context => { // ARRANGE DatabaseContext databaseContext = context; var exercisesRepository = new ExercisesRepository(context); databaseContext.Roles.Add(Role.Create("student")); databaseContext.SaveChanges(); var userType = databaseContext.Roles.FirstOrDefault(); databaseContext.TestTypes.Add(TestType.Create("Grila")); databaseContext.SaveChanges(); var testType = databaseContext.TestTypes.FirstOrDefault(); if (userType != null) { databaseContext.Users.Add(User.Create("Johny", "Bravo", "johnnybravo", "*****@*****.**", "#$$RR#$TED")); } databaseContext.SaveChanges(); var user = databaseContext.Users.FirstOrDefault(); if (user != null && testType != null) { databaseContext.Tests.Add(Test.Create("NumeleTestului", "DescriereaTextului", user.Id, testType.Id)); } databaseContext.SaveChanges(); var test = databaseContext.Tests.FirstOrDefault(); if (test != null) { var exercise = Exercise.Create("Problema1", test.Id); databaseContext.Add(exercise); databaseContext.SaveChanges(); exercise.Update("Problema2", test.Id, false); // ACT var result = exercisesRepository.UpdateAsync(exercise); // ASSERT result.Result.Should().Be(true); } }); }
public File CreateFile(DatabaseContext context, string path, string url) { context.Roles.Add(Role.Create("teacher")); context.SaveChanges(); var userType = context.Roles.FirstOrDefault(); if (userType != null) { context.Users.Add(User.Create("Johnny", "Bravo", "johnnybravo", "*****@*****.**", "2G3GSDGDFG")); } context.SaveChanges(); var user = context.Users.FirstOrDefault(); if (user != null) { context.Groups.Add(Group.Create("some group", "description", user.Id)); context.SaveChanges(); var group = context.Groups.FirstOrDefault(); context.TestTypes.Add(TestType.Create("grila")); context.SaveChanges(); var testType = context.TestTypes.FirstOrDefault(); if (testType != null) { context.Tests.Add(Test.Create("Partial Exam Python", "No description needed", user.Id, testType.Id)); } context.SaveChanges(); var test = context.Tests.FirstOrDefault(); if (group != null && test != null) { context.TestInstances.Add(TestInstance.Create(300, @group.Id, test.Id, DateTime.Now)); } } context.SaveChanges(); var testInstance = context.TestInstances.FirstOrDefault(); return(testInstance != null?File.Create(path, url, testInstance.Id) : null); }
public void Given_TestInstance_When_NewTestInstanceIsAdded_Then_ShouldHaveOneTestInstanceInDatabase() { RunOnDatabase(context => { // ARRANGE context.Roles.Add(Role.Create("student")); context.SaveChanges(); var userType = context.Roles.FirstOrDefault(); if (userType != null) { var user = User.Create( "User first name", "User last name", "User", "*****@*****.**", "parola" ); context.Users.Add(user); } context.SaveChanges(); var userId = context.Users.FirstOrDefault(); if (userId != null) { var group = Group.Create( "A2", "grupa din anul III", userId.Id ); context.Groups.Add(group); } context.SaveChanges(); var groupId = context.Groups.FirstOrDefault(); context.TestTypes.Add(TestType.Create("Test_1")); context.SaveChanges(); var testType = context.TestTypes.FirstOrDefault(); if (userId != null && testType != null) { context.Tests.Add(Test.Create("Testul nr 1", "Matematica", userId.Id, testType.Id)); } context.SaveChanges(); var testId = context.Tests.FirstOrDefault(); var testInstancesRepository = new TestInstancesRepository(context); if (groupId != null && testId != null) { var testInstance = TestInstance.Create( 100, groupId.Id, testId.Id, DateTime.Now ); var testInstanceInserted = testInstancesRepository.InsertAsync(testInstance).Result; // ACT var result = testInstancesRepository.GetByIdAsync(testInstanceInserted.Id); // ASSERT result.Should().NotBe(null); } }); }
public void Given_TestInstance_When_UpdateTestInstanceAsync_Then_ShouldBeTrue() { RunOnDatabase(context => { // ARRANGE context.Roles.Add(Role.Create("student")); context.SaveChanges(); var userType = context.Roles.FirstOrDefault(); if (userType != null) { var user = User.Create( "User first name", "User last name", "User", "*****@*****.**", "parola" ); context.Users.Add(user); } context.SaveChanges(); var userId = context.Users.FirstOrDefault(); if (userId != null) { var group = Group.Create( "A2", "grupa din anul III", userId.Id ); context.Groups.Add(group); } context.SaveChanges(); var groupId = context.Groups.FirstOrDefault(); context.TestTypes.Add(TestType.Create("Test_1")); context.SaveChanges(); var testType = context.TestTypes.FirstOrDefault(); if (userId != null && testType != null) { context.Tests.Add(Test.Create("Testul nr 1", "Matematica", userId.Id, testType.Id)); } context.SaveChanges(); var testId = context.Tests.FirstOrDefault(); var testInstancesRepository = new TestInstancesRepository(context); if (groupId == null) { return; } if (testId == null) { return; } var testInstance = TestInstance.Create( 100, groupId.Id, testId.Id, DateTime.Now ); context.Add(testInstance); context.SaveChanges(); testInstance.Update(200, groupId.Id, testId.Id, DateTime.Now, false); // ACT var result = testInstancesRepository.UpdateAsync(testInstance); // ASSERT result.Result.Should().Be(true); }); }