Ejemplo n.º 1
0
        public void Constructor_NewClass_GeneratesId()
        {
            var result = new Application.Models.Class.Class(Name.CreateFromString(_fixture.Create <string>()));

            result.Should().NotBeNull();
            result.Id.Should().NotBe(Guid.Empty);
        }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public async Task CreateAsync(Application.Models.Class.Class newClass)
        {
            Class        classEntity = newClass.MapToFileEntity();
            List <Class> classes     = await RetrieveOrCreateClassesAsync();

            classes.Add(classEntity);
            await SaveChangesAsync(classes);
        }
Ejemplo n.º 3
0
        public void AddStudent_WithStudentNull_ThrowsException()
        {
            var sut = new Application.Models.Class.Class(
                _fixture.Create <Guid>(),
                Name.CreateFromString(_fixture.Create <string>()),
                _fixture.CreateMany <Student>(0).ToList());

            Action action = () => sut.AddStudent(null);

            action.Should().Throw <ArgumentNullException>();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Maps <see cref="Application.Models.Class.Class"/> to <see cref="Class"/>.
        /// </summary>
        public static Class MapToFileEntity(this Application.Models.Class.Class input)
        {
            ValidateNullInput(input);

            return(new Class
            {
                Id = input.Id,
                Name = input.Name.Value,
                Students = input.Students.MapToFileEntity()
            });
        }
Ejemplo n.º 5
0
        public void AddStudent_WithStudent_AddStudentToClass()
        {
            var sut = new Application.Models.Class.Class(
                _fixture.Create <Guid>(),
                Name.CreateFromString(_fixture.Create <string>()),
                _fixture.CreateMany <Student>(0).ToList());
            var expectedStudent = _fixture.Create <Student>();

            sut.AddStudent(expectedStudent);

            sut.Students.Should().ContainSingle();
            sut.Students.Single().Should().Be(expectedStudent);
        }
Ejemplo n.º 6
0
        /// <inheritdoc/>
        public async Task <ValidationMessage> UpdateAsync(Application.Models.Class.Class @class)
        {
            List <Class> classes = await RetrieveOrCreateClassesAsync();

            int index = classes.FindIndex(x => x.Id == @class.Id);

            if (index == -1)
            {
                return(new ValidationMessage(nameof(@class), "The class was not found"));
            }
            Class classEntity = @class.MapToFileEntity();

            classes[index] = classEntity;
            await SaveChangesAsync(classes);

            return(null);
        }