public async void TestDelete() { var builder = new WebHostBuilder() .UseEnvironment("Production") .UseStartup <TestStartup>(); TestServer testServer = new TestServer(builder); var client = new ApiClient(testServer.CreateClient()); var createModel = new ApiStudentRequestModel(); createModel.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), "B", true, 1, "B", true, "B", "B", true, 1); CreateResponse <ApiStudentResponseModel> createResult = await client.StudentCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiStudentResponseModel getResponse = await client.StudentGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.StudentDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiStudentResponseModel verifyResponse = await client.StudentGetAsync(2); verifyResponse.Should().BeNull(); }
public async void Update() { var mock = new ServiceMockFacade <IStudentRepository>(); var model = new ApiStudentRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Student>())).Returns(Task.FromResult(new Student())); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new Student())); var service = new StudentService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.StudentModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLStudentMapperMock, mock.DALMapperMockFactory.DALStudentMapperMock, mock.BOLMapperMockFactory.BOLLessonXStudentMapperMock, mock.DALMapperMockFactory.DALLessonXStudentMapperMock, mock.BOLMapperMockFactory.BOLLessonXTeacherMapperMock, mock.DALMapperMockFactory.DALLessonXTeacherMapperMock, mock.BOLMapperMockFactory.BOLStudentXFamilyMapperMock, mock.DALMapperMockFactory.DALStudentXFamilyMapperMock); UpdateResponse <ApiStudentResponseModel> response = await service.Update(default(int), model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.StudentModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiStudentRequestModel>())); mock.RepositoryMock.Verify(x => x.Update(It.IsAny <Student>())); }
private async Task <ApiStudentResponseModel> CreateRecord() { var model = new ApiStudentRequestModel(); model.SetProperties(DateTime.Parse("1/1/1988 12:00:00 AM"), "B", true, 1, "B", true, "B", "B", true, 1); CreateResponse <ApiStudentResponseModel> result = await this.Client.StudentCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public virtual async Task <IActionResult> Create([FromBody] ApiStudentRequestModel model) { CreateResponse <ApiStudentResponseModel> result = await this.StudentService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Students/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiStudentRequestModel model) { this.BirthdayRules(); this.EmailRules(); this.EmailRemindersEnabledRules(); this.FamilyIdRules(); this.FirstNameRules(); this.IsAdultRules(); this.LastNameRules(); this.PhoneRules(); this.SmsRemindersEnabledRules(); this.StudioIdRules(); return(await this.ValidateAsync(model, id)); }
private async Task <ApiStudentRequestModel> PatchModel(int id, JsonPatchDocument <ApiStudentRequestModel> patch) { var record = await this.StudentService.Get(id); if (record == null) { return(null); } else { ApiStudentRequestModel request = this.StudentModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual async Task <CreateResponse <ApiStudentResponseModel> > Create( ApiStudentRequestModel model) { CreateResponse <ApiStudentResponseModel> response = new CreateResponse <ApiStudentResponseModel>(await this.StudentModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.BolStudentMapper.MapModelToBO(default(int), model); var record = await this.StudentRepository.Create(this.DalStudentMapper.MapBOToEF(bo)); response.SetRecord(this.BolStudentMapper.MapBOToModel(this.DalStudentMapper.MapEFToBO(record))); } return(response); }
public async void Delete() { var mock = new ServiceMockFacade <IStudentRepository>(); var model = new ApiStudentRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask); var service = new StudentService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.StudentModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLStudentMapperMock, mock.DALMapperMockFactory.DALStudentMapperMock); ActionResponse response = await service.Delete(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>())); mock.ModelValidatorMockFactory.StudentModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>())); }
public void MapModelToBO() { var mapper = new BOLStudentMapper(); ApiStudentRequestModel model = new ApiStudentRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), "A", true, 1, "A", true, "A", "A", true, 1); BOStudent response = mapper.MapModelToBO(1, model); response.Birthday.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Email.Should().Be("A"); response.EmailRemindersEnabled.Should().Be(true); response.FamilyId.Should().Be(1); response.FirstName.Should().Be("A"); response.IsAdult.Should().Be(true); response.LastName.Should().Be("A"); response.Phone.Should().Be("A"); response.SmsRemindersEnabled.Should().Be(true); response.UserId.Should().Be(1); }
public virtual async Task <UpdateResponse <ApiStudentResponseModel> > Update( int id, ApiStudentRequestModel model) { var validationResult = await this.StudentModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.BolStudentMapper.MapModelToBO(id, model); await this.StudentRepository.Update(this.DalStudentMapper.MapBOToEF(bo)); var record = await this.StudentRepository.Get(id); return(new UpdateResponse <ApiStudentResponseModel>(this.BolStudentMapper.MapBOToModel(this.DalStudentMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiStudentResponseModel>(validationResult)); } }
public virtual BOStudent MapModelToBO( int id, ApiStudentRequestModel model ) { BOStudent boStudent = new BOStudent(); boStudent.SetProperties( id, model.Birthday, model.Email, model.EmailRemindersEnabled, model.FamilyId, model.FirstName, model.IsAdult, model.LastName, model.Phone, model.SmsRemindersEnabled, model.StudioId); return(boStudent); }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiStudentRequestModel model) { ApiStudentRequestModel request = await this.PatchModel(id, this.StudentModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiStudentResponseModel> result = await this.StudentService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public void CreatePatch() { var mapper = new ApiStudentModelMapper(); var model = new ApiStudentRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), "A", true, 1, "A", true, "A", "A", true, 1); JsonPatchDocument <ApiStudentRequestModel> patch = mapper.CreatePatch(model); var response = new ApiStudentRequestModel(); patch.ApplyTo(response); response.Birthday.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Email.Should().Be("A"); response.EmailRemindersEnabled.Should().Be(true); response.FamilyId.Should().Be(1); response.FirstName.Should().Be("A"); response.IsAdult.Should().Be(true); response.LastName.Should().Be("A"); response.Phone.Should().Be("A"); response.SmsRemindersEnabled.Should().Be(true); response.StudioId.Should().Be(1); }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiStudentRequestModel> patch) { ApiStudentResponseModel record = await this.StudentService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiStudentRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiStudentResponseModel> result = await this.StudentService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiStudentResponseModel> > StudentUpdateAsync(int id, ApiStudentRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Students/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiStudentResponseModel> >(httpResponse.Content.ContentToString())); }