/// <inheritdoc/> public async Task <Test> GetAsync(Guid id) { List <FileEntity.Test> tests = await RetrieveOrCreateTestsAsync(); FileEntity.Test testEntity = tests.SingleOrDefault(x => x.Id == id); return(testEntity.MapToModel()); }
/// <inheritdoc/> public async Task CreateAsync(Test newTest) { FileEntity.Test testEntity = newTest.MapToFileEntity(); List <FileEntity.Test> tests = await RetrieveOrCreateTestsAsync(); tests.Add(testEntity); await SaveChangesAsync(tests); }
public void MapToModel_InputNull_ThrowsException() { // Arrange FileEntity.Test input = null; // Act Action action = () => input.MapToModel(); // Assert action.Should().Throw <ArgumentNullException>(); }
/// <summary> /// Maps a list of <see cref="Application.Models.Test.Test"/> to a list of <see cref="Test"/>. /// </summary> public static Application.Models.Test.Test MapToModel(this FileEntity.Test input) { ValidateNullInput(input); return(new Application.Models.Test.Test( input.Id, Name.CreateFromString(input.Name), StandardizationFactor.CreateFromByte(input.StandardizationFactor), Grade.CreateFromByte(input.MinimumGrade), input.Assignments.MapToModel(), input.NumberOfVersions)); }
/// <inheritdoc/> public async Task <ValidationMessage> UpdateAsync(Test test) { List <FileEntity.Test> tests = await RetrieveOrCreateTestsAsync(); int index = tests.FindIndex(x => x.Id == test.Id); if (index == -1) { return(new ValidationMessage(nameof(test), "The test was not found")); } FileEntity.Test testEntity = test.MapToFileEntity(); tests[index] = testEntity; await SaveChangesAsync(tests); return(null); }
public void MapToFileEntity_WithValidTest_MapsAssignments() { // Arrange var input = new TestUtilities.Application.TestBuilder() .WithValidMinimumGrade() .WithNumberOfVersions(1) .WithRandomAssignments() .Build(); // Act FileEntity.Test result = input.MapToFileEntity(); // Assert result.Assignments.Should().HaveCount(input.Assignments.Count); foreach (var assignment in input.Assignments) { result.Assignments.Should().Contain(x => x.Id == assignment.Id); } }
public void MapToFileEntity_WithValidTest_MapsTestProperties() { // Arrange var input = new TestUtilities.Application.TestBuilder() .WithValidMinimumGrade() .WithNumberOfVersions(1) .WithRandomAssignments() .Build(); // Act FileEntity.Test result = input.MapToFileEntity(); // Assert result.Id.Should().Be(input.Id); result.Name.Should().Be(input.Name.Value); result.MinimumGrade.Should().Be(input.MinimumGrade.Value); result.StandardizationFactor.Should().Be(input.StandardizationFactor.Value); result.NumberOfVersions.Should().Be(input.NumberOfVersions); }