Ejemplo n.º 1
0
        public void DeleteShouldRemoveAndReturnUserRole()
        {
            var options = new DbContextOptionsBuilder <MoviesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(DeleteShouldRemoveAndReturnUserRole))
                          .EnableSensitiveDataLogging()
                          .Options;

            using (var context = new MoviesDbContext(options))
            {
                var userRoleService = new UserRoleService(context);
                var addUserRole     = userRoleService.Create(new ExamenNet.ViewModels.UserRolePostModel
                {
                    Name        = "Rol testare",
                    Description = "Creat pentru testare"
                });

                Assert.IsNotNull(addUserRole);
                Assert.AreEqual("Rol testare", context.UserRoles.Find(1).Name);

                var deletedUserRole = userRoleService.Delete(1);

                Assert.IsNotNull(deletedUserRole);
                Assert.AreEqual(addUserRole.Name, deletedUserRole.Name);
            }
        }
Ejemplo n.º 2
0
        public void DeleteShouldDeleteAndReturnTheDeletedUserRole()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(DeleteShouldDeleteAndReturnTheDeletedUserRole))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var userRoleService = new UserRoleService(context);
                var addUserRole     = new UserRolePostModel()
                {
                    Name        = "Newbegginer",
                    Description = "A role for a new guy..."
                };


                var actual               = userRoleService.Create(addUserRole);
                var afterDelete          = userRoleService.Delete(actual.Id);
                int numberOfUserRoleInDb = context.UserRoles.CountAsync().Result;
                var resultUR             = context.UserRoles.Find(actual.Id);


                Assert.IsNotNull(afterDelete);
                Assert.IsNull(resultUR);
                Assert.AreEqual(0, numberOfUserRoleInDb);
            }
        }
Ejemplo n.º 3
0
        public void ValidDeleteTest()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(ValidDeleteTest))// "ValidRegisterShouldCreateANewUser")
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                UserRoleService userRoleService = new UserRoleService(context);
                var             added           = new Labo2.ViewModels.UserRolePostModel
                {
                    Name        = "Regular",
                    Description = "regular description"
                };
                var result       = userRoleService.Create(added);
                var resultDelete = userRoleService.Delete(result.Id);
                var resultNull   = userRoleService.Delete(38743);
                Assert.IsNotNull(result);
                Assert.IsNull(resultNull);
            }
        }
Ejemplo n.º 4
0
 public ActionResult Delete(int id, FormCollection collection)
 {
     try
     {
         service.Delete(t => t.Id == id);
     }
     catch (Exception ex)
     {
         Success = false;
         Message = ex.Message;
     }
     return(EasyUIResult());
 }
Ejemplo n.º 5
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IUserRoleRepository>();
            var model = new ApiUserRoleRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask);
            var service = new UserRoleService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.UserRoleModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLUserRoleMapperMock,
                                              mock.DALMapperMockFactory.DALUserRoleMapperMock);

            ActionResponse response = await service.Delete(default(string));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>()));
            mock.ModelValidatorMockFactory.UserRoleModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>()));
        }
        public ActionResult UserAuthorizationEdit(int userId, AuthorizationModel authorizationModel)
        {
            try
            {
                var oldUserRoles = UserRoleService.GetAll(userId);
                foreach (var authorization in oldUserRoles)
                {
                    UserRoleService.Delete(authorization.Id);
                }

                var userModules = authorizationModel.UserModules?.ToList();
                if (userModules != null)
                {
                    foreach (var item in userModules)
                    {
                        var a = new UserRole
                        {
                            ModuleId = item,
                            UserId   = userId
                        };
                        UserRoleService.Add(a);
                    }
                }

                var userRoles = authorizationModel.UserRoles?.ToList();
                if (userRoles != null)
                {
                    foreach (var item in userRoles)
                    {
                        var a = new UserRole
                        {
                            RoleId = item,
                            UserId = userId
                        };
                        UserRoleService.Add(a);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error("Hata oluştu - " + new StackTrace().GetFrame(0).GetMethod().Name, e);
            }
            return(RedirectToAction("UserList"));
        }
Ejemplo n.º 7
0
        public void Delete()
        {
            var options = new DbContextOptionsBuilder <ExpensesDbContext>()
                          .UseInMemoryDatabase(databaseName: nameof(Delete))
                          .Options;

            using (var context = new ExpensesDbContext(options))
            {
                var roleService = new UserRoleService(context, config);
                var toAdd       = new UserRolePostDto
                {
                    Name = "GOD"
                };
                UserRole role = roleService.Create(toAdd);
                roleService.Delete(role.Id);

                Assert.IsNull(context.UserRoles.Find(role.Id));
            }
        }
Ejemplo n.º 8
0
        public async void DeleteRole(object sender, EventArgs e)
        {
            var mi = ((MenuItem)sender);

            try
            {
                if (int.TryParse(mi.CommandParameter.ToString(), out int IDint))
                {
                    UserRoleModel selectedUserRole = userRoles.Where(x => x.UserRoleID == IDint).First();
                    userRoles.Remove(selectedUserRole);
                    if (selectedUserRole != null)
                    {
                        if (await userRoleService.Delete(IDint))
                        {
                            await DisplayAlert("Succses", "Role removed.", "ok");

                            GetAllUsersRoles();
                        }
                        else
                        {
                            await DisplayAlert("Remuval failed.", " Try again.", "ok");
                        }
                    }
                    else
                    {
                        await DisplayAlert("Remuval failed.", " Try again.", "ok");
                    }
                }
                else
                {
                    await DisplayAlert("Remuval failed.", " Try again.", "ok");
                }
            }
            catch (Exception ex)
            {
                await DisplayAlert("Remuval failed.", " Try again." + ex.Message + ex.InnerException, "ok");
            }
        }
Ejemplo n.º 9
0
 public override void Delete(List <int> ids)
 {
     userService.Delete(ids);
     urService.Delete(ids);
     unService.Delete(ids);
 }