public async Task Update_User_RevokeCosts_Does_Exist_Elastic_Updated()
        {
            //Setup
            var gdamUserId = Guid.NewGuid().ToString();
            var a5User     = new GdamUser
            {
                _id = gdamUserId,
                _cm = new Cm
                {
                    View = new View
                    {
                        Access = new Access
                        {
                            adcost  = false,
                            folders = true
                        }
                    },
                    Common = new User {
                        Disabled = false
                    }
                }
            };

            var costUser = new CostUser
            {
                GdamUserId     = gdamUserId,
                Disabled       = false,
                Id             = Guid.NewGuid(),
                Created        = DateTime.Now,
                UserUserGroups = new List <UserUserGroup>
                {
                    new UserUserGroup
                    {
                        Id        = Guid.NewGuid(),
                        Created   = DateTime.Now,
                        UserGroup = new UserGroup
                        {
                            Name     = "name",
                            Created  = DateTime.Now,
                            Disabled = false,
                            Role     = new Role()
                        }
                    }
                },
                Agency = new Agency()
            };

            _efContext.Add(costUser);
            _efContext.SaveChanges();

            //Act
            await _userService.AddUserToDb(a5User);

            //Assert
            _mapper.Verify(a => a.Map <CostUserSearchItem>(It.IsAny <CostUser>()), Times.Once);
            _elasticSearchServiceMock.Verify(a => a.CreateSearchItem(It.IsAny <CostUserSearchItem>(), Constants.ElasticSearchIndices.CostUsersIndexName), Times.Never);
            _elasticSearchServiceMock.Verify(a => a.UpdateSearchItem(It.IsAny <CostUserSearchItem>(), Constants.ElasticSearchIndices.CostUsersIndexName), Times.Once);
            _logger.Verify(a => a.Information($"Disabling User with gdam Id {a5User._id} since access was revoked!"), Times.Once);
            _logger.Verify(a => a.Information($"Updated user with Id {costUser.Id}"), Times.Once);
        }
        public async Task Update_User_Doesnt_Exist()
        {
            //Setup

            var a5User = new GdamUser
            {
                _id = Guid.NewGuid().ToString(),
                _cm = new Cm
                {
                    View = new View
                    {
                        Access = new Access
                        {
                            adcost  = false,
                            folders = true
                        }
                    },
                    Common = new User {
                        Disabled = false
                    }
                }
            };

            //Act
            await _userService.AddUserToDb(a5User);

            //Assert
            _mapper.Verify(a => a.Map <CostUserSearchItem>(It.IsAny <CostUser>()), Times.Never);
            _elasticSearchServiceMock.Verify(a => a.CreateSearchItem(It.IsAny <CostUserSearchItem>(), Constants.ElasticSearchIndices.CostUsersIndexName), Times.Never);
            _elasticSearchServiceMock.Verify(a => a.UpdateSearchItem(It.IsAny <CostUserSearchItem>(), Constants.ElasticSearchIndices.CostUsersIndexName), Times.Never);
            _logger.Verify(a => a.Information($"Disabling User with gdam Id {a5User._id} since access was revoked!"), Times.Never);
        }
        public async Task AddUserToDb_WhenUserHasBeenDisabled_ShouldMarkUserAsDisableInDb_AndIncrementVersion_AndReplicateToElastic()
        {
            //Setup
            var gdamUserId = Guid.NewGuid().ToString();
            var a5User     = new GdamUser
            {
                _id = gdamUserId,
                _cm = new Cm
                {
                    View = new View
                    {
                        Access = new Access
                        {
                            adcost  = false,
                            folders = true
                        }
                    },
                    Common = new User {
                        Disabled = false
                    }
                }
            };

            var costUser = new CostUser
            {
                GdamUserId     = gdamUserId,
                Disabled       = false,
                Id             = Guid.NewGuid(),
                Created        = DateTime.Now,
                UserUserGroups = new List <UserUserGroup>
                {
                    new UserUserGroup
                    {
                        Id        = Guid.NewGuid(),
                        Created   = DateTime.Now,
                        UserGroup = new UserGroup
                        {
                            Name     = "name",
                            Created  = DateTime.Now,
                            Disabled = false,
                            Role     = new Role()
                        }
                    }
                },
                Version = 0,
                Agency  = new Agency()
            };

            _efContext.Add(costUser);
            _efContext.SaveChanges();

            //Act
            await _userService.AddUserToDb(a5User);

            //Assert
            costUser.Disabled.Should().BeTrue();
            costUser.Version.Should().Be(1);
            _elasticSearchServiceMock.Verify(es =>
                                             es.UpdateSearchItem(It.IsAny <CostUserSearchItem>(), Constants.ElasticSearchIndices.CostUsersIndexName),
                                             Times.Once
                                             );
        }
 public void CreateUser(GdamUser user)
 {
     Users.Add(user);
 }