Exemplo n.º 1
0
        public async Task AssociateUserSystemAsync(string userId, string systemId)
        {
            var userEntity   = this.Repository.SelectIncludingSystems(userId);
            var systemEntity = await _systemRepository.SelectByIdAsync(systemId);

            if (userEntity != null && systemEntity != null)
            {
                bool systemAlreadyAssociated = userEntity.UserSystemLst.Where(us => us.SystemId == systemId).Count() > 0;
                if (!systemAlreadyAssociated)
                {
                    UserSystemEntity userSystemEntity = new UserSystemEntity()
                    {
                        User     = userEntity,
                        UserId   = userId,
                        System   = systemEntity,
                        SystemId = systemId
                    };
                    userEntity.UserSystemLst.Add(userSystemEntity);
                    this.Repository.Update(userEntity);
                    await _unitOfWork.CommitAsync();
                }
            }
            else
            {
                throw new WarningException(this.UserSystemIncorrect);
            }
        }
Exemplo n.º 2
0
        public async void UnassociateUserSystem_Ok()
        {
            _systemDto.Id = "Ts.UnassocUsSys.Ok.S";
            _userDto.Id   = "Ts.UnassocUsSys.Ok.U";
            UserSystemEntity userSystemEntity = new UserSystemEntity
            {
                SystemId = _systemDto.Id,
                System   = _fixture.MapperInstance.Map <SystemEntity>(_systemDto),
                UserId   = _userDto.Id,
                User     = _fixture.MapperInstance.Map <UserEntity>(_userDto)
            };
            await _fixture.AddEntity(userSystemEntity);

            var response = await _fixture.CreateAuthenticatedAsAdminClient().GetAsync("/api/Users/" + _userDto.Id + "/unassociate/" + _systemDto.Id);

            var obtainedEntiy = await _fixture.FindByEntityAsync <UserSystemEntity>(
                new UserSystemEntity()
            {
                SystemId = _systemDto.Id, UserId = _userDto.Id
            }
                );

            await this.GetOkAnswerChecked(response);

            obtainedEntiy.Should().BeNull();
        }
        public async void SelectIncludingUsers_ObtainOneWithUser()
        {
            using (var context = new AuthDbContext(CreateNewContextOptions()))
            {
                SystemRepository repo         = _baseRepository.GetNewRepository(context);
                SystemEntity     systemEntity = _baseRepository.GetNewValidEntity();
                await context.Systems.AddAsync(systemEntity);

                UserEntity userEntity = GetValidUserEntity();
                await context.Users.AddAsync(userEntity);

                UserSystemEntity userSysEntity = new UserSystemEntity()
                {
                    SystemId = systemEntity.Id,
                    UserId   = userEntity.Id
                };
                await context.UsersSystems.AddAsync(userSysEntity);

                await context.SaveChangesAsync();

                var entityWithUsers = repo.SelectIncludingUsers(systemEntity.Id);

                Assert.NotNull(entityWithUsers);
                _baseRepository.AssertAllProperties(systemEntity, entityWithUsers);
                Assert.Single(entityWithUsers.UserSystemLst);
                _baseRepository.AssertAllProperties(systemEntity, entityWithUsers.UserSystemLst.First().System);
                Assert.Equal(userEntity.Id, entityWithUsers.UserSystemLst.First().UserId);
                Assert.Equal(userEntity.Name, entityWithUsers.UserSystemLst.First().User.Name);
            }
        }
Exemplo n.º 4
0
        private UserSystemEntity GenerateUserSystemFormTest(string role)
        {
            _userDto.Id      = $"Test.Login.{role}";
            _systemDto.Id    = _userDto.Id;
            _userDto.IsAdmin = false;
            UserSystemEntity userSystemEntity = new UserSystemEntity
            {
                SystemId = _systemDto.Id,
                System   = _fixture.MapperInstance.Map <SystemEntity>(_systemDto),
                UserId   = _userDto.Id,
                User     = _fixture.MapperInstance.Map <UserEntity>(_userDto),
                Role     = (UserRole)Enum.Parse(typeof(UserRole), role)
            };

            return(userSystemEntity);
        }
Exemplo n.º 5
0
        private void ConfigureUserUser()
        {
            var userEntity = new UserEntity()
            {
                Id = "USER", Name = "System User", IsAdmin = false, Email = "*****@*****.**", Pass = "******"
            };
            var systemEntity = new SystemEntity()
            {
                Id = "TEST_SYSTEM_USER", Name = "System for User"
            };
            var userSystemEntity = new UserSystemEntity
            {
                SystemId = systemEntity.Id,
                System   = systemEntity,
                UserId   = userEntity.Id,
                User     = userEntity,
                Role     = UserRole.User
            };

            Task.Run(() => _repoHelper.InsertEntity <UserSystemEntity>(userSystemEntity)).Wait();
            this.UserUser = this.BuildUserLogged(userEntity, systemEntity.Id);
        }
Exemplo n.º 6
0
        public async void GetUserBySystem_ObtainOne()
        {
            _systemDto.Id = "Test.GetUserBySystem";
            _userDto.Id   = "Test.GetUserBySystem";
            UserSystemEntity userSystemEntity = new UserSystemEntity
            {
                SystemId = _systemDto.Id,
                System   = _fixture.MapperInstance.Map <SystemEntity>(_systemDto),
                UserId   = _userDto.Id,
                User     = _fixture.MapperInstance.Map <UserEntity>(_userDto)
            };
            await _fixture.AddEntity(userSystemEntity);

            var response = await _fixture.CreateAuthenticatedAsAdminClient().GetAsync("/api/Users/" + _userDto.Id + "/" + _systemDto.Id);

            var answer = await this.GetOkAnswerChecked <UserDto>(response);

            answer.Content.Id.Should().Be(_userDto.Id);
            answer.Content.Name.Should().Be(_userDto.Name);
            answer.Content.Description.Should().Be(_userDto.Description);
            answer.Content.Pass.Should().Be(_userDto.Pass);
            answer.Content.Email.Should().Be(_userDto.Email);
        }
Exemplo n.º 7
0
        public async void GetWithUsers_ObtainOneWithOneUserAtLeast()
        {
            _systemDto.Id = "Test.GetWithUsers.One";
            _userDto.Id   = "Test.GetWithUsers.One";
            UserSystemEntity userSystemEntity = new UserSystemEntity
            {
                SystemId = _systemDto.Id,
                System   = _fixture.MapperInstance.Map <SystemEntity>(_systemDto),
                UserId   = _userDto.Id,
                User     = _fixture.MapperInstance.Map <UserEntity>(_userDto)
            };
            await _fixture.AddEntity(userSystemEntity);

            var response = await _fixture.CreateAuthenticatedAsAdminClient().GetAsync("/api/Systems/" + _systemDto.Id + "/withUsers");

            var answer = await this.GetOkAnswerChecked <SystemDto>(response);

            answer.Content.Id.Should().Be(_systemDto.Id);
            answer.Content.Name.Should().Be(_systemDto.Name);
            answer.Content.Description.Should().Be(_systemDto.Description);
            answer.Content.Users.Should().NotBeNull();
            answer.Content.Users.Should().NotBeEmpty();
            answer.Content.Users.Should().Contain(u => u.UserId == _userDto.Id);
        }
Exemplo n.º 8
0
        public async Task UnassociateUserSystemAsync(string userId, string systemId)
        {
            var userEntity = this.Repository.SelectIncludingSystems(userId);
            UserSystemEntity systemToRemove = null;

            if (userEntity != null)
            {
                systemToRemove = userEntity.UserSystemLst
                                 .Where(s => s.SystemId == systemId)
                                 .FirstOrDefault();

                if (systemToRemove != null)
                {
                    userEntity.UserSystemLst.Remove(systemToRemove);
                    this.Repository.Update(userEntity);
                    await _unitOfWork.CommitAsync();
                }
            }

            if (userEntity == null || systemToRemove == null)
            {
                throw new WarningException(this.UserSystemIncorrect);
            }
        }
Exemplo n.º 9
0
 public void AddSystem(UserSystemEntity userSystem)
 {
     this.Context.UsersSystems.Add(userSystem);
 }
Exemplo n.º 10
0
 public void RemoveSystem(UserSystemEntity userSystem)
 {
     this.Context.UsersSystems.Remove(userSystem);
 }