public async Task Delete_All_Versions(IAuthorizationService authorizationService, IStateService stateService, List <Lesson> entities, Lesson target) { var context = TestSetup.SetupContext(); var service = new LessonService(context, TestSetup.SetupHttpContext(), authorizationService, stateService); await context.Lessons.AddRangeAsync(entities); var version = 0; for (var i = 0; i < 5; i++) { var newLesson = new Lesson(); newLesson.CloneFrom(target); newLesson.Version = version; await context.Lessons.AddAsync(target); version += 1; } await context.SaveChangesAsync(); var result = await service.Delete(target.Id); result.Should().BeTrue(); context.Lessons.Any(x => x.Id == target.Id).Should().BeFalse(); context.Lessons.Count().Should().Be(entities.Count); }
public async Task Update_Lesson_Version(IAuthorizationService authorizationService, IStateService stateService, Lesson entity, LessonRequest request) { var context = TestSetup.SetupContext(); var service = new LessonService(context, TestSetup.SetupHttpContext(), authorizationService, stateService); await context.Lessons.AddAsync(entity); await context.SaveChangesAsync(); var expected = new Lesson(); expected.CloneFrom(entity); expected.CloneFrom(request); expected.Version += 1; var result = await service.Update(entity.Id, request); result.Should().NotBeNull().And.BeEquivalentTo(expected, config => TestSetup.IgnoreTimestamps <Lesson>()(config.Excluding(lesson => lesson.Exercises))); context.Lessons.Count().Should().Be(2); }