Beispiel #1
0
        /// <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());
        }
Beispiel #2
0
        /// <inheritdoc/>
        public async Task CreateAsync(Test newTest)
        {
            FileEntity.Test        testEntity = newTest.MapToFileEntity();
            List <FileEntity.Test> tests      = await RetrieveOrCreateTestsAsync();

            tests.Add(testEntity);
            await SaveChangesAsync(tests);
        }
Beispiel #3
0
        public void MapToModel_InputNull_ThrowsException()
        {
            // Arrange
            FileEntity.Test input = null;

            // Act
            Action action = () => input.MapToModel();

            // Assert
            action.Should().Throw <ArgumentNullException>();
        }
Beispiel #4
0
        /// <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));
        }
Beispiel #5
0
        /// <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);
        }
Beispiel #6
0
        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);
            }
        }
Beispiel #7
0
        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);
        }