예제 #1
0
        public async Task CreateAsync_ClassNumbValidationFailed_ThrowsError()
        {
            // Arrange
            var fixture  = new Fixture();
            var student  = new StudentsUpdateModel();
            var expected = fixture.Create <string>();

            var classNumbGetService = new Mock <IClassNumbGetService>();

            classNumbGetService
            .Setup(x => x.ValidateAsync(student))
            .Throws(new InvalidOperationException(expected));

            var studentDataAccess = new Mock <IStudentsRepository>();

            var studentCreateService = new StudentCreateService(studentDataAccess.Object, classNumbGetService.Object);

            // Act
            var action = new Func <Task>(() => studentCreateService.CreateAsync(student));

            // Assert
            await action.Should().ThrowAsync <InvalidOperationException>().WithMessage(expected);

            studentDataAccess.Verify(x => x.InsertAsync(student), Times.Never);
        }
예제 #2
0
        public async Task <Domain.Student> InsertAsync(StudentsUpdateModel student)
        {
            var result = await context.Students.AddAsync(mapper.Map <Entities.Student>(student));

            await context.SaveChangesAsync();

            return(mapper.Map <Domain.Student>(result.Entity));
        }
예제 #3
0
        public async Task <Student> CreateAsync(StudentsUpdateModel student)
        {
            await _classNumbGetService.ValidateAsync(student);

            //await CustomerGetService.ValidateAsync(order);

            //order.Date = DateTime.Now;
            //order.Arrived = false;

            return(await _studentDataAccess.InsertAsync(student));
        }
예제 #4
0
        public async Task <Domain.Student> UpdateAsync(StudentsUpdateModel student)
        {
            if (student == null)
            {
                throw new ArgumentNullException(nameof(student));
            }

            var entity = await context.Students.FirstOrDefaultAsync(x => x.id == student.Id);

            var result = mapper.Map(student, entity);

            context.Update(result);

            await context.SaveChangesAsync();

            return(mapper.Map <Domain.Student>(result));
        }
예제 #5
0
        public async Task CreateAsync_ClassNumbValidationSucceed_CreatesStudent()
        {
            // Arrange
            var student  = new StudentsUpdateModel();
            var expected = new Student();

            var classNumbGetService = new Mock <IClassNumbGetService>();

            classNumbGetService.Setup(x => x.ValidateAsync(student));

            var studentDataAccess = new Mock <IStudentsRepository>();

            studentDataAccess.Setup(x => x.InsertAsync(student)).ReturnsAsync(expected);

            var studentGetService = new StudentCreateService(studentDataAccess.Object, classNumbGetService.Object);

            // Act
            var result = await studentGetService.CreateAsync(student);

            // Assert
            result.Should().Be(expected);
        }
 public Task <Student> UpdateAsync(StudentsUpdateModel student)
 {
     return(_studentDataAccess.UpdateAsync(student));
 }