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); }
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)); }
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)); }
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)); }
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)); }