public async Task AfterLogInReturnsToken() { // Arrage Guid guid = Guid.NewGuid(); var _userRepositoryMock = new Mock <IUserRepository>(); var _mapperMock = new Mock <IMapper>(); var _ioptions = new OptionsMock <JwtSettings>(); _ioptions.Value = new JwtSettings() { ExpiryMinutes = 120, Issuer = "http://*****:*****@poczta.pl", "123qweASD!@#"); // zmienic kolejnosc parametów w konstruktorze objektu User var _accountDto = new AccountDto { Id = _user.Id, Email = _user.Email, Name = _user.Name, Role = _user.Role, Password = _user.Password, CreatesAt = _user.CreatesAt }; var _jwtDto = new TokenDto { Token = "12345-qwer-4567-@@@##$", Expires = 120000, Role = "user" }; var _userService = new UserService(_userRepositoryMock.Object, _jwtHandler, _mapperMock.Object); _userRepositoryMock.Setup(x => x.GetForEmailAsync("*****@*****.**")).ReturnsAsync(_user); _mapperMock.Setup(x => x.Map <AccountDto>(_user)).Returns(_accountDto); // _jwtHandlerMock.Setup(x => x.CreateToken(_user.Id, _user.Role)).Returns(_jwtDto); // Act // await _userService.RegistryAsync(guid, "*****@*****.**", "test", "123qweASD!@#", "user"); var existingAcountDto = await _userService.GetAccountAsync("*****@*****.**"); var token = await _userService.LoginAsync("*****@*****.**", "123qweASD!@#"); // Assert token.Should().NotBeNull(); Assert.Same(_user.Role, token.Role); token.Expires.Should().BeGreaterThan(0); token.Token.Length.Should().Equals(543); token.Token.Should().Contain("."); _userRepositoryMock.Verify(x => x.GetForEmailAsync("*****@*****.**"), Times.Exactly(2)); }
public async Task ShouldSendMail() { var smtpClientMock = new Mock <ISmtpClient>(); smtpClientMock.Setup(x => x.SendMailAsync(It.IsAny <MailMessage>())).Returns(Task.CompletedTask); var interpolationService = new StringInterpolationService(new ReflectionService()); var mailOptionsMock = new OptionsMock <FsMail>(new FsMail { FromAddress = "*****@*****.**", Host = "123", Port = 123 }); var mailService = new MailService(mailOptionsMock, interpolationService, smtpClientMock.Object); var message = new MailMessage <TestModel>("*****@*****.**", "test subject", "test body {Test}", new TestModel()); await mailService.SendMail(message); }
public EventSuffleMicrosoftSqlDbContext CreateDbContext(string[] args) { var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", false, true) .AddJsonFile($"appsettings.{environment}.json", false, true) .AddEnvironmentVariables() .AddUserSecrets <Startup>() .Build(); var builder = new DbContextOptionsBuilder <EventSuffleDbContext>(); var dbOptions = new OptionsMock <DatabaseOptions>(new DatabaseOptions() { DatabaseType = DbType, DatabaseConnectionString = configuration[Constants.Keys.ConnectionString(DbType)], }); Console.WriteLine($"Database connectionstring: {dbOptions.Value.DatabaseConnectionString}"); return((EventSuffleMicrosoftSqlDbContext)Activator.CreateInstance(typeof(EventSuffleMicrosoftSqlDbContext), builder.Options, dbOptions)); }
private void SetupOptionsMock() { var fakeConfig = Fixture.Create <AppConfig>(); OptionsMock.Setup(m => m.Value).Returns(fakeConfig); }