public void CreatePatch() { var mapper = new ApiUserModelMapper(); var model = new ApiUserRequestModel(); model.SetProperties("A", 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1, 1, 1, "A"); JsonPatchDocument <ApiUserRequestModel> patch = mapper.CreatePatch(model); var response = new ApiUserRequestModel(); patch.ApplyTo(response); response.AboutMe.Should().Be("A"); response.AccountId.Should().Be(1); response.Age.Should().Be(1); response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.DisplayName.Should().Be("A"); response.DownVote.Should().Be(1); response.EmailHash.Should().Be("A"); response.LastAccessDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Location.Should().Be("A"); response.Reputation.Should().Be(1); response.UpVote.Should().Be(1); response.View.Should().Be(1); response.WebsiteUrl.Should().Be("A"); }
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 ApiUserRequestModel(); createModel.SetProperties("B", DateTime.Parse("1/1/1988 12:00:00 AM"), "B", "B", "B", "B", "B", 1, "B", "B", "B", "B", "B"); CreateResponse <ApiUserResponseModel> createResult = await client.UserCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiUserResponseModel getResponse = await client.UserGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.UserDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiUserResponseModel verifyResponse = await client.UserGetAsync(2); verifyResponse.Should().BeNull(); }
public void CreatePatch() { var mapper = new ApiUserModelMapper(); var model = new ApiUserRequestModel(); model.SetProperties("A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A", "A", "A", "A", "A", 1, "A", "A", "A", "A", "A"); JsonPatchDocument <ApiUserRequestModel> patch = mapper.CreatePatch(model); var response = new ApiUserRequestModel(); patch.ApplyTo(response); response.BioImgUrl.Should().Be("A"); response.Birthday.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.ContentDescription.Should().Be("A"); response.Email.Should().Be("A"); response.FullName.Should().Be("A"); response.HeaderImgUrl.Should().Be("A"); response.Interest.Should().Be("A"); response.LocationLocationId.Should().Be(1); response.Password.Should().Be("A"); response.PhoneNumber.Should().Be("A"); response.Privacy.Should().Be("A"); response.Username.Should().Be("A"); response.Website.Should().Be("A"); }
public async void Update() { var mock = new ServiceMockFacade <IUserRepository>(); var model = new ApiUserRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <User>())).Returns(Task.FromResult(new User())); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new User())); var service = new UserService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.UserModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLUserMapperMock, mock.DALMapperMockFactory.DALUserMapperMock, mock.BOLMapperMockFactory.BOLAdminMapperMock, mock.DALMapperMockFactory.DALAdminMapperMock, mock.BOLMapperMockFactory.BOLStudentMapperMock, mock.DALMapperMockFactory.DALStudentMapperMock, mock.BOLMapperMockFactory.BOLTeacherMapperMock, mock.DALMapperMockFactory.DALTeacherMapperMock); UpdateResponse <ApiUserResponseModel> response = await service.Update(default(int), model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.UserModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiUserRequestModel>())); mock.RepositoryMock.Verify(x => x.Update(It.IsAny <User>())); }
private async Task <ApiUserResponseModel> CreateRecord(ApiClient client) { var model = new ApiUserRequestModel(); model.SetProperties("B", DateTime.Parse("1/1/1988 12:00:00 AM"), "B", "B", "B", "B", "B", 1, "B", "B", "B", "B", "B"); CreateResponse <ApiUserResponseModel> result = await client.UserCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
private async Task <ApiUserResponseModel> CreateRecord() { var model = new ApiUserRequestModel(); model.SetProperties("B", "B", "B", "B", Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), true, true, "B", "B"); CreateResponse <ApiUserResponseModel> result = await this.Client.UserCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public void MapModelToBO() { var mapper = new BOLUserMapper(); ApiUserRequestModel model = new ApiUserRequestModel(); model.SetProperties("A", "A"); BOUser response = mapper.MapModelToBO(1, model); response.Password.Should().Be("A"); response.Username.Should().Be("A"); }
public void MapResponseToRequest() { var mapper = new ApiUserModelMapper(); var model = new ApiUserResponseModel(); model.SetProperties(1, "A", "A"); ApiUserRequestModel response = mapper.MapResponseToRequest(model); response.Password.Should().Be("A"); response.Username.Should().Be("A"); }
public virtual BOUser MapModelToBO( int id, ApiUserRequestModel model ) { BOUser boUser = new BOUser(); boUser.SetProperties( id, model.Password, model.Username); return(boUser); }
public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiUserRequestModel model) { this.DisplayNameRules(); this.EmailAddressRules(); this.ExternalIdRules(); this.ExternalIdentifiersRules(); this.IdentificationTokenRules(); this.IsActiveRules(); this.IsServiceRules(); this.JSONRules(); this.UsernameRules(); return(await this.ValidateAsync(model, id)); }
public virtual async Task <IActionResult> Create([FromBody] ApiUserRequestModel model) { CreateResponse <ApiUserResponseModel> result = await this.UserService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Users/{result.Record.UserId}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void CreatePatch() { var mapper = new ApiUserModelMapper(); var model = new ApiUserRequestModel(); model.SetProperties("A", "A"); JsonPatchDocument <ApiUserRequestModel> patch = mapper.CreatePatch(model); var response = new ApiUserRequestModel(); patch.ApplyTo(response); response.Password.Should().Be("A"); response.Username.Should().Be("A"); }
private async Task <ApiUserRequestModel> PatchModel(int id, JsonPatchDocument <ApiUserRequestModel> patch) { var record = await this.UserService.Get(id); if (record == null) { return(null); } else { ApiUserRequestModel request = this.UserModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public virtual async Task <CreateResponse <ApiUserResponseModel> > Create( ApiUserRequestModel model) { CreateResponse <ApiUserResponseModel> response = new CreateResponse <ApiUserResponseModel>(await this.UserModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.BolUserMapper.MapModelToBO(default(int), model); var record = await this.UserRepository.Create(this.DalUserMapper.MapBOToEF(bo)); response.SetRecord(this.BolUserMapper.MapBOToModel(this.DalUserMapper.MapEFToBO(record))); } return(response); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiUserRequestModel model) { this.BioImgUrlRules(); this.BirthdayRules(); this.ContentDescriptionRules(); this.EmailRules(); this.FullNameRules(); this.HeaderImgUrlRules(); this.InterestRules(); this.LocationLocationIdRules(); this.PasswordRules(); this.PhoneNumberRules(); this.PrivacyRules(); this.UsernameRules(); this.WebsiteRules(); return(await this.ValidateAsync(model, id)); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiUserRequestModel model) { this.AboutMeRules(); this.AccountIdRules(); this.AgeRules(); this.CreationDateRules(); this.DisplayNameRules(); this.DownVoteRules(); this.EmailHashRules(); this.LastAccessDateRules(); this.LocationRules(); this.ReputationRules(); this.UpVoteRules(); this.ViewRules(); this.WebsiteUrlRules(); return(await this.ValidateAsync(model, id)); }
public void MapModelToBO() { var mapper = new BOLUserMapper(); ApiUserRequestModel model = new ApiUserRequestModel(); model.SetProperties("A", "A", "A", "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), true, true, "A", "A"); BOUser response = mapper.MapModelToBO("A", model); response.DisplayName.Should().Be("A"); response.EmailAddress.Should().Be("A"); response.ExternalId.Should().Be("A"); response.ExternalIdentifiers.Should().Be("A"); response.IdentificationToken.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.IsActive.Should().Be(true); response.IsService.Should().Be(true); response.JSON.Should().Be("A"); response.Username.Should().Be("A"); }
public async void Delete() { var mock = new ServiceMockFacade <IUserRepository>(); var model = new ApiUserRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask); var service = new UserService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.UserModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLUserMapperMock, mock.DALMapperMockFactory.DALUserMapperMock); ActionResponse response = await service.Delete(default(string)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>())); mock.ModelValidatorMockFactory.UserModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>())); }
public virtual async Task <UpdateResponse <ApiUserResponseModel> > Update( int id, ApiUserRequestModel model) { var validationResult = await this.UserModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.BolUserMapper.MapModelToBO(id, model); await this.UserRepository.Update(this.DalUserMapper.MapBOToEF(bo)); var record = await this.UserRepository.Get(id); return(new UpdateResponse <ApiUserResponseModel>(this.BolUserMapper.MapBOToModel(this.DalUserMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiUserResponseModel>(validationResult)); } }
public virtual BOUser MapModelToBO( string id, ApiUserRequestModel model ) { BOUser boUser = new BOUser(); boUser.SetProperties( id, model.DisplayName, model.EmailAddress, model.ExternalId, model.ExternalIdentifiers, model.IdentificationToken, model.IsActive, model.IsService, model.JSON, model.Username); return(boUser); }
public void CreatePatch() { var mapper = new ApiUserModelMapper(); var model = new ApiUserRequestModel(); model.SetProperties("A", "A", "A", "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), true, true, "A", "A"); JsonPatchDocument <ApiUserRequestModel> patch = mapper.CreatePatch(model); var response = new ApiUserRequestModel(); patch.ApplyTo(response); response.DisplayName.Should().Be("A"); response.EmailAddress.Should().Be("A"); response.ExternalId.Should().Be("A"); response.ExternalIdentifiers.Should().Be("A"); response.IdentificationToken.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.IsActive.Should().Be(true); response.IsService.Should().Be(true); response.JSON.Should().Be("A"); response.Username.Should().Be("A"); }
public void MapModelToBO() { var mapper = new BOLUserMapper(); ApiUserRequestModel model = new ApiUserRequestModel(); model.SetProperties("A", 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A", 1, 1, 1, "A"); BOUser response = mapper.MapModelToBO(1, model); response.AboutMe.Should().Be("A"); response.AccountId.Should().Be(1); response.Age.Should().Be(1); response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.DisplayName.Should().Be("A"); response.DownVote.Should().Be(1); response.EmailHash.Should().Be("A"); response.LastAccessDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.Location.Should().Be("A"); response.Reputation.Should().Be(1); response.UpVote.Should().Be(1); response.View.Should().Be(1); response.WebsiteUrl.Should().Be("A"); }
public void MapModelToBO() { var mapper = new BOLUserMapper(); ApiUserRequestModel model = new ApiUserRequestModel(); model.SetProperties("A", DateTime.Parse("1/1/1987 12:00:00 AM"), "A", "A", "A", "A", "A", 1, "A", "A", "A", "A", "A"); BOUser response = mapper.MapModelToBO(1, model); response.BioImgUrl.Should().Be("A"); response.Birthday.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.ContentDescription.Should().Be("A"); response.Email.Should().Be("A"); response.FullName.Should().Be("A"); response.HeaderImgUrl.Should().Be("A"); response.Interest.Should().Be("A"); response.LocationLocationId.Should().Be(1); response.Password.Should().Be("A"); response.PhoneNumber.Should().Be("A"); response.Privacy.Should().Be("A"); response.Username.Should().Be("A"); response.Website.Should().Be("A"); }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiUserRequestModel model) { ApiUserRequestModel request = await this.PatchModel(id, this.UserModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiUserResponseModel> result = await this.UserService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual BOUser MapModelToBO( int userId, ApiUserRequestModel model ) { BOUser boUser = new BOUser(); boUser.SetProperties( userId, model.BioImgUrl, model.Birthday, model.ContentDescription, model.Email, model.FullName, model.HeaderImgUrl, model.Interest, model.LocationLocationId, model.Password, model.PhoneNumber, model.Privacy, model.Username, model.Website); return(boUser); }
public virtual BOUser MapModelToBO( int id, ApiUserRequestModel model ) { BOUser boUser = new BOUser(); boUser.SetProperties( id, model.AboutMe, model.AccountId, model.Age, model.CreationDate, model.DisplayName, model.DownVote, model.EmailHash, model.LastAccessDate, model.Location, model.Reputation, model.UpVote, model.View, model.WebsiteUrl); return(boUser); }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiUserRequestModel> patch) { ApiUserResponseModel record = await this.UserService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiUserRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiUserResponseModel> result = await this.UserService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiUserRequestModel model) { this.PasswordRules(); this.UsernameRules(); return(await this.ValidateAsync(model, id)); }
public virtual async Task <UpdateResponse <ApiUserResponseModel> > UserUpdateAsync(int id, ApiUserRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Users/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiUserResponseModel> >(httpResponse.Content.ContentToString())); }