Exemple #1
0
        public async Task ValidVaultForUserShouldReturn()
        {
            var dbContext = MockServices.DbContextMock();

            var authenticationService = MockServices.AuthenticationServiceMock().Object;

            var target = new VaultInformationService(authenticationService, dbContext);

            var validVaultId = MockEntities.TestVault().Id;

            var actual = await target.GetVaultForAuthorizedUser(validVaultId);

            Assert.AreEqual(validVaultId, actual.Id);
        }
Exemple #2
0
        public async Task ValidVaultForDifferentUserShouldNotFound()
        {
            var dbContext = MockServices.DbContextMock();

            var authenticationService = MockServices.AuthenticationServiceMock();

            authenticationService.Setup(x => x.UserId).Returns(777);

            var target = new VaultInformationService(authenticationService.Object, dbContext);

            var validVaultId = MockEntities.TestVault().Id;
            var validUserId  = MockEntities.TestUser().Id;

            await Assert.ThrowsExceptionAsync <StatusCodeException>(async() => await target.GetVaultForAuthorizedUser(validVaultId));
        }
Exemple #3
0
        public async Task ShouldReturnAllVaultForUser()
        {
            var dbContext = MockServices.DbContextMock();

            var authenticationService = MockServices.AuthenticationServiceMock().Object;


            var target = new VaultInformationService(authenticationService, dbContext);

            var validVaultId = MockEntities.TestVault().Id;
            var validUserId  = MockEntities.TestUser().Id;

            var vaults = await target.GetVaultsForAuthorizedUser();

            var expectedids = await dbContext.Vaults.Where(x => x.Owners.Any(y => y.OwnerId == authenticationService.UserId)).Select(x => x.Id).ToListAsync();

            var actualIds = vaults.Select(x => x.Id).ToList();

            CollectionAssert.AreEqual(expectedids, actualIds);
        }