Esempio n. 1
0
        public async void FindUserByRandomString_ShouldReturnNull()
        {
            // Arrange
            ApplicationIdentityService applicationIdentityService =
                new ApplicationIdentityService(_dbContext, _graphService, _httpContextAccessor);

            // Act
            ApplicationUser retrievedUser = await applicationIdentityService.FindUserAsync(u => u.AzureAdObjectIdentifier == Guid.NewGuid().ToString());

            // Assert
            Assert.Null(retrievedUser);
        }
Esempio n. 2
0
        public async void LoadAssets_ShouldNotReturnArchivedAssets()
        {
            // Arrange
            var newProjectId = await _projectsService.CreateProject(CreateTestProject(), "127.0.1.1");

            var newCredential         = CreateTestCredential();
            var newCredentialArchived = CreateTestCredential();

            // Act - get and add assets
            var retrievedProject = await _projectsService.GetProject(newProjectId);

            await _assetService.AddAssetToProjectAsync(newProjectId, newCredential, "127.0.1.1");

            await _assetService.AddAssetToProjectAsync(newProjectId, newCredentialArchived, "127.0.1.1");

            // Act - archive and retrieve
            await _assetService.ArchiveAssetAsync(newProjectId, newCredentialArchived.Id, "127.0.1.1");

            var archivedAsset = await _assetService.GetAssetAsync(newProjectId, newCredentialArchived.Id, "127.0.1.1");

            // Act - reload project (it is already populated) by refreshing the context and load assets (should exlude archived)
            _dbContext.Dispose();
            _dbContext = GetDbContext();
            _applicationIdentityService = new ApplicationIdentityService(_dbContext, _graphService, _httpContextAccessor, _fakeHttpContextItems);
            _projectsService            = new ProjectsService(_dbContext, _encryptionService, _eventService, _applicationIdentityService, _permissionService);
            _assetService = new AssetService(_dbContext, _projectsService, _encryptionService, _eventService, _applicationIdentityService);
            _testUser     = _applicationIdentityService.FindUserAsync(u => u.AzureAdObjectIdentifier == "TestAdObjectId11234567890").Result;

            var retrievedProjectAfterArchive = await _projectsService.GetProject(newProjectId);

            await _assetService.LoadAssetsAsync(retrievedProjectAfterArchive);

            // Assert
            Assert.Null(archivedAsset);
            Assert.Equal(1, retrievedProjectAfterArchive.Assets.Count());
            Assert.Equal(false, retrievedProjectAfterArchive.Assets.Any(a => a.Id == newCredentialArchived.Id && a.IsArchived == true));

            // Cleanup
            //_dbContext = GetDbContext();
            //_applicationIdentityService = new ApplicationIdentityService(_dbContext, _graphService, _httpContextAccessor, _fakeHttpContextItems);
            //_projectsService = new ProjectsService(_dbContext, _encryptionService, _eventService, _applicationIdentityService, _permissionService);

            var rr = _dbContext.Entry(_testUser).State;
            var retrievedProjectAfterArchiveForCleanup = await _projectsService.GetProject(newProjectId);

            await _projectsService.ArchiveProject(retrievedProjectAfterArchiveForCleanup, "127.0.1.1", _testUser);

            var archivedProject = await _projectsService.GetProject(newProjectId);

            Assert.Null(archivedProject);
        }