Exemplo n.º 1
0
        public async Task Put_Should_Update_User_Client()
        {
            UserClient userClientToUpdate;

            using (var context = new DaOAuthContext(_dbContextOptions))
            {
                userClientToUpdate = context.UsersClients.Include(uc => uc.Client).FirstOrDefault(uc =>
                                                                                                  uc.IsActif && uc.User.UserName.Equals(GuiApiTestStartup.LoggedUserName));

                Assert.IsNotNull(userClientToUpdate);
            }

            var updateUserClientDto = new UpdateUserClientDto()
            {
                ClientPublicId = userClientToUpdate.Client.PublicId,
                IsActif        = false,
                UserName       = GuiApiTestStartup.LoggedUserName
            };

            var httpResponseMessage = await _client.PutAsJsonAsync("usersClients", updateUserClientDto);

            Assert.AreEqual(204, (int)httpResponseMessage.StatusCode);

            using (var context = new DaOAuthContext(_dbContextOptions))
            {
                var userClientFromDb = context.UsersClients.SingleOrDefault(uc => uc.IsActif.Equals(false) &&
                                                                            uc.Client.PublicId.Equals(userClientToUpdate.Client.PublicId) &&
                                                                            uc.User.UserName.Equals(GuiApiTestStartup.LoggedUserName));

                Assert.IsNotNull(userClientFromDb);
            }
        }
Exemplo n.º 2
0
        public void UpdateUserClient(UpdateUserClientDto toUpdate)
        {
            IList <ValidationResult> ExtendValidation(UpdateUserClientDto toValidate)
            {
                var resource = this.GetErrorStringLocalizer();
                IList <ValidationResult> result = new List <ValidationResult>();

                using (var context = RepositoriesFactory.CreateContext())
                {
                    var ucRepo = RepositoriesFactory.GetUserClientRepository(context);
                    var myUc   = ucRepo.GetUserClientByClientPublicIdAndUserName(toValidate.ClientPublicId, toValidate.UserName);

                    if (myUc == null)
                    {
                        result.Add(new ValidationResult(resource["UpdateUserClientUserOrClientNotFound"]));
                    }

                    if (myUc != null && (myUc.User == null || !myUc.User.IsValid))
                    {
                        result.Add(new ValidationResult(resource["UpdateUserClientUserNotValid"]));
                    }

                    if (myUc != null && (myUc.Client == null || !myUc.Client.IsValid))
                    {
                        result.Add(new ValidationResult(resource["UpdateUserClientClientNotValid"]));
                    }
                }

                return(result);
            }

            this.Validate(toUpdate, ExtendValidation);

            using (var context = RepositoriesFactory.CreateContext())
            {
                var ucRepo = RepositoriesFactory.GetUserClientRepository(context);
                var myUc   = ucRepo.GetUserClientByClientPublicIdAndUserName(toUpdate.ClientPublicId, toUpdate.UserName);
                myUc.IsActif = toUpdate.IsActif;
                ucRepo.Update(myUc);
                context.Commit();
            }
        }
Exemplo n.º 3
0
 public IActionResult Put(UpdateUserClientDto toUpdate)
 {
     toUpdate.UserName = User.Identity.Name;
     _service.UpdateUserClient(toUpdate);
     return(StatusCode(204));
 }