public async Task UpdatePersonalDataShouldUpdateUser()
        {
            var dbContext         = MockServices.DbContextMock();
            var authService       = MockServices.AuthenticationServiceMock().Object;
            var userId            = authService.UserId;
            var unmodifiedUser    = dbContext.Users.Single(x => x.Id == userId);
            var expectedFirstName = unmodifiedUser.FirstName;

            dbContext.Entry(unmodifiedUser).State = Microsoft.EntityFrameworkCore.EntityState.Detached;

            var target = CreateAccountManagementService(dbContext);


            var userUpdateModel = new UserUpdateModel
            {
                Email    = "*****@*****.**",
                LastName = "12343"
            };

            var actual = await target.UpdatePersonalData(userUpdateModel);

            var user = dbContext.Users.Single(x => x.Id == userId);

            Assert.AreEqual(userUpdateModel.Email, actual.Email);
            Assert.AreEqual(userUpdateModel.LastName, actual.LastName);
            Assert.AreEqual(expectedFirstName, user.FirstName);
        }
        public async Task CreatingVaultForAuthenticatedUserShouldSucceed()
        {
            var dbContext = MockServices.DbContextMock();

            var authenticationService = MockServices.AuthenticationServiceMock().Object;

            var target = new VaultCreationService(authenticationService, MockServices.EntityRepositoryMock(dbContext), dbContext, MockServices.HashServiceMock().Object);

            var vaultCreateModel = new VaultCreateModel
            {
                MasterKey = "555",
                Name      = "555"
            };

            var vaultId = await target.CreateVaultForAuthenticatedUser(vaultCreateModel);

            var vault      = dbContext.Vaults.Single(x => x.Id == vaultId);
            var vaultOwner = dbContext.VaultOwners.Single(x => x.VaultId == vaultId);
            var user       = dbContext.Users.Single(x => x.OwnerId == vaultOwner.OwnerId);

            var vaultOwnerRightsCount = dbContext.VaultOwnerRights.Where(x => x.VaultOwnerId == vaultOwner.Id).Count();

            Assert.AreEqual(authenticationService.UserId, user.Id);
            Assert.AreEqual(4, vaultOwnerRightsCount);
            Assert.AreEqual(vaultCreateModel.MasterKey, vault.MasterKey);
            Assert.AreEqual(vaultCreateModel.Name, vault.Name);
        }
Beispiel #3
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);
        }
Beispiel #4
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));
        }
        private static AccountManagementService CreateAccountManagementService(Domain.FsDbContext dbContext, IVerificationService verificationService = null)
        {
            var entityRepostitory       = MockServices.EntityRepositoryMock(dbContext);
            var hashServiceMock         = MockServices.HashServiceMock().Object;
            var mailService             = MockServices.MailServiceMock().Object;
            var authenticationService   = MockServices.AuthenticationServiceMock().Object;
            var verificationServiceMock = verificationService ?? MockServices.VerificationServiceMock().Object;

            var target = new AccountManagementService(
                entityRepostitory,
                hashServiceMock,
                mailService,
                dbContext,
                authenticationService,
                verificationServiceMock);

            return(target);
        }
        public async Task CreatingVaultForUnAuthenticatedUserShouldFail()
        {
            var dbContext = MockServices.DbContextMock();

            var authenticationServiceMock = MockServices.AuthenticationServiceMock();

            authenticationServiceMock.Setup(x => x.IsAuthenticated).Returns(false);

            var target = new VaultCreationService(authenticationServiceMock.Object, MockServices.EntityRepositoryMock(dbContext), dbContext, MockServices.HashServiceMock().Object);

            var vaultCreateModel = new VaultCreateModel
            {
                MasterKey = "555",
                Name      = "555"
            };

            await Assert.ThrowsExceptionAsync <StatusCodeException>(async() => await target.CreateVaultForAuthenticatedUser(vaultCreateModel));
        }
Beispiel #7
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);
        }