Esempio n. 1
0
        public async Task when_invoking_get_async_it_sholud_be_invoke_get_async_on_user_repository()
        {
            //Arrange
            var user       = new User(Guid.NewGuid(), "user", "test", "*****@*****.**", "secret", "salt");
            var accountDto = new AccountDto
            {
                Id    = user.Id,
                Role  = user.Role,
                Email = user.Email,
                Name  = user.Name
            };
            var userRepositoryMock = new Mock <IUserRepository>();
            var jwtHandlerMock     = new Mock <IJwtHandler>();
            var mapperMock         = new Mock <IMapper>();
            var encrypter          = new Mock <Encrypter>();

            mapperMock.Setup(x => x.Map <AccountDto>(user)).Returns(accountDto);
            var userService = new UserService(userRepositoryMock.Object, jwtHandlerMock.Object,
                                              encrypter.Object, mapperMock.Object);

            userRepositoryMock.Setup(x => x.GetAsync(user.Id)).ReturnsAsync(user);

            //Act
            var existingAccountDto = await userService.GetAccountAsync(user.Id);

            //Assert
            userRepositoryMock.Verify(x => x.GetAsync(user.Id), Times.Once());
            accountDto.Should().NotBeNull();
            accountDto.Email.ShouldAllBeEquivalentTo(user.Email);
            accountDto.Name.ShouldAllBeEquivalentTo(user.Name);
            accountDto.Role.ShouldAllBeEquivalentTo(user.Role);
        }
Esempio n. 2
0
        public async Task when_invoking_get_async_it_should_invoke__get_async_on_user_repository()
        {
            // ARRANGE
            // testujemy UserService
            // user service wymaga w konstruktorze 3 instancji, dlatego je moqujemy
            var user       = new User(Guid.NewGuid(), "user", "test", "*****@*****.**", "secret");
            var accountDto = new AccountDto
            {
                Id    = user.Id,
                Role  = user.Role,
                Email = user.Email,
                Name  = user.Name
            };
            var userRepositoryMock = new Mock <IUserRepository>();
            var jwtHandlerMock     = new Mock <IJwtHandler>();
            var mapperMock         = new Mock <IMapper>();

            mapperMock.Setup(Xunit => Xunit.Map <AccountDto>(user)).Returns(accountDto);

            var userService = new UserService(userRepositoryMock.Object, jwtHandlerMock.Object,
                                              mapperMock.Object);

            userRepositoryMock.Setup(x => x.GetAsync(It.IsAny <Guid>())).ReturnsAsync(user);

            // ACT
            var existingAccountDto = await userService.GetAccountAsync(user.Id);

            // ASSERT
            userRepositoryMock.Verify(x => x.GetAsync(It.IsAny <Guid>()), Times.Once());
            accountDto.Should().NotBeNull();
            accountDto.Email.ShouldAllBeEquivalentTo(user.Email);
            accountDto.Role.ShouldAllBeEquivalentTo(user.Role);
            accountDto.Name.ShouldAllBeEquivalentTo(user.Name);
        }
Esempio n. 3
0
        internal AccountAssert AssertAccountExistsWithEmail(string adminEmail)
        {
            _account = _connection.GetAccountByEmail(adminEmail);

            _account.Should().NotBeNull();

            return(this);
        }