public SubscribeHandlerTests() { fixture = new Fixture(); cryptService = Substitute.For <ICryptService>(); cryptServiceOutput = fixture.Create <string>(); cryptService.Crypt(Arg.Any <string>()).Returns(cryptServiceOutput); userFactory = new WriteModelUserFactory(cryptService); userReadRepository = Substitute.For <IReadModelUserRepository>(); readModelUnitOfWork = Substitute.For <IReadModelUnitOfWork>(); readModelUnitOfWork.UserRepository.Returns(userReadRepository); userWriteRepository = Substitute.For <IWriteModelUserRepository>(); writeModelUnitOfWork = Substitute.For <IWriteModelUnitOfWork>(); writeModelUnitOfWork.UserRepository.Returns(userWriteRepository); eventPublisher = Substitute.For <IEventPublisher>(); handler = new SubscribeHandler( userFactory, readModelUnitOfWork, writeModelUnitOfWork, eventPublisher ); }
public MongoDbWriteModelUnitOfWorkTests() { fixture = new Fixture(); //Setup mongo configuration configuration = fixture.Create <MongoDbConfiguration>(); //Setup client factory client = Substitute.For <IMongoClient>(); sessionHandle = Substitute.For <IClientSessionHandle>(); database = Substitute.For <IMongoDatabase>(); clientFactory = Substitute.For <IMongoClientFactory>(); client.StartSession().Returns(sessionHandle); client.GetDatabase(Arg.Any <string>()).Returns(database); clientFactory.CreateClient(Arg.Any <MongoDbConfiguration>()).Returns(client); //Setup user factory cryptService = Substitute.For <ICryptService>(); cryptService.Crypt(Arg.Any <string>()).Returns(args => args[0]); userFactory = new WriteModelUserFactory(cryptService); //Create unit of work unitOfWork = new MongoDbWriteModelUnitOfWork(configuration, clientFactory, userFactory); }
public AuthenticationService(IUnitOfWork unitOfWork, ICryptService cryptService, IAuthenticationTokenService authenticationTokenService) { _unitOfWork = unitOfWork; _cryptService = cryptService; _authenticationTokenService = authenticationTokenService; }
public UsersController(IUserRepository repository, IOptions <AppSettings> appSettings, ICryptService cryptService, IEmailSender emailSender) { _repository = repository; _appSettings = appSettings.Value; _cryptService = cryptService; _emailSender = emailSender; }
public RegisterUserHandler(IEntityRepository <User> repository, ICryptService cryptService, IMapper mapper, IAccountService accountService) { _repository = repository; _cryptService = cryptService; _mapper = mapper; _accountService = accountService; }
public UserService(VideoServiceDbContext context, ICryptService cryptService, IOptions <AuthSettings> settings, ILogger <UserService> logger, IMapper mapper) : base(context, logger, mapper) { _cryptService = cryptService; _logger = logger; _settings = settings.Value; }
public AuthService(bool isDevelopment, StoreContext db, ICryptService crypt, IHttpContextAccessor httpContextAccessor) { _isDevelopment = isDevelopment; _db = db; _crypt = crypt; _httpContextAccessor = httpContextAccessor; }
public AuthenticateWithCredentialsHandler( IReadModelUnitOfWork readModel, IWriteModelUnitOfWork writeModel, ICryptService cryptService ) { ReadModel = readModel; WriteModel = writeModel; CryptService = cryptService; }
public WriteModelUserFactoryTests() { fixture = new Fixture(); cryptService = Substitute.For <ICryptService>(); cryptServiceOutput = fixture.Create <string>(); cryptService.Crypt(Arg.Any <string>()).Returns(cryptServiceOutput); factory = new WriteModelUserFactory(cryptService); }
public AccountManager( SunUserManager userManager, IEmailSenderService emailSenderService, DataBaseConnection db, ICryptService cryptService, IOptionsMonitor <UrlPathsOptions> urlsOptions) : base(db) { this.userManager = userManager; this.urlsOptions = urlsOptions; this.emailSenderService = emailSenderService; this.cryptService = cryptService; }
public CaptchaService( IOptions <CaptchaOptions> captchaOptions, ICryptService cryptService) { this.cryptService = cryptService; // Init Font (font name: Gunny Rewritten) FontCollection fontCollection = new FontCollection(); fontCollection.Install(Path.GetFullPath("Resources/gunnyrewritten.ttf")); font = fontCollection.Families.First().CreateFont(46); }
public InMemoryUserRepositoryTests() { fixture = new Fixture(); cryptService = Substitute.For <ICryptService>(); cryptService.Crypt(Arg.Any <string>()).Returns(args => args[0]); userFactory = new WriteModelUserFactory(cryptService); data = new InMemoryUserWriteData(); repository = new InMemoryWriteModelUserRepository(userFactory, data); }
public AccountManager( SunUserManager userManager, IEmailSenderService emailSenderService, DataBaseConnection db, ICryptService cryptService, IOptions <GlobalOptions> globalOptions, IOptions <JweOptions> jwtOptions) : base(db) { this.jweOptions = jwtOptions.Value; this.userManager = userManager; this.globalOptions = globalOptions.Value; this.emailSenderService = emailSenderService; this.cryptService = cryptService; }
public JwtService( DataBaseConnection db, SunUserManager userManager, IRolesCache rolesCache, ICryptService cryptService, IOptions <JwtOptions> jwtOptions, ILoggerFactory loggerFactory) : base(db) { this.userManager = userManager; this.cryptService = cryptService; this.jwtOptions = jwtOptions.Value; logger = loggerFactory.CreateLogger <AccountController>(); this.rolesCache = rolesCache; }
public MongoDbWriteModelUserRepositoryTests() { fixture = new Fixture(); fixture.Customize <UserSubscribed>(composer => composer.With(u => u.Email, "*****@*****.**")); database = Substitute.For <IMongoDatabase>(); userCollection = Substitute.For <IMongoCollection <User> >(); database.GetCollection <User>(Arg.Is(MongoDbWriteModelUserRepository.collectionName)).Returns(userCollection); cryptService = Substitute.For <ICryptService>(); cryptService.Crypt(Arg.Any <string>()).Returns(args => args[0]); userFactory = new WriteModelUserFactory(cryptService); repository = new MongoDbWriteModelUserRepository(database, userFactory); }
public JweService( DataBaseConnection db, SunUserManager userManager, IRolesCache rolesCache, ICryptService cryptService, IOptionsMonitor <SecurityOptions> securityOptions, IOptionsMonitor <UrlPathsOptions> urlsOptions, ILoggerFactory loggerFactory) : base(db) { this.userManager = userManager; this.cryptService = cryptService; this.urlsOptions = urlsOptions; this.securityOptions = securityOptions; logger = loggerFactory.CreateLogger <AccountController>(); this.rolesCache = rolesCache; }
public JweService( DataBaseConnection db, SunUserManager userManager, IRolesCache rolesCache, ICryptService cryptService, IOptionsMonitor <JweOptions> jweOptions, IOptionsMonitor <GlobalOptions> globalOptions, ILoggerFactory loggerFactory) : base(db) { this.userManager = userManager; this.cryptService = cryptService; this.globalOptions = globalOptions; this.jweOptions = jweOptions; logger = loggerFactory.CreateLogger <AccountController>(); this.rolesCache = rolesCache; }
public AuthenticateWithCredentialsHandlerTests() { fixture = new Fixture(); readModel = Substitute.For <IReadModelUnitOfWork>(); readModelUserRepository = Substitute.For <IReadModelUserRepository>(); readModel.UserRepository.Returns(readModelUserRepository); writeModel = Substitute.For <IWriteModelUnitOfWork>(); writeModelUserRepository = Substitute.For <IWriteModelUserRepository>(); writeModel.UserRepository.Returns(writeModelUserRepository); cryptService = Substitute.For <ICryptService>(); cryptService.Crypt(Arg.Any <string>()).Returns(args => args[0]); writeModelUserFactory = new WriteModelUserFactory(cryptService); handler = new AuthenticateWithCredentialsHandler(readModel, writeModel, cryptService); }
public CypherSecretsAdminController( ICryptService cryptService, IServiceProvider serviceProvider) : base(serviceProvider) { this.cryptService = cryptService; }
public AuthService(IAuthDataProvider authDataProvider, ICryptService cryptService, ITokenService tokenService) { this.authDataProvider = authDataProvider; this.cryptService = cryptService; this.tokenService = tokenService; }
public LoggedInForm() { this.InitializeComponent(); this._cryptService = new CryptService(); }
public WriteModelUserFactory(ICryptService cryptService) { CryptService = cryptService; }
public void Seed(ICryptService cryptService) { Randomizer.Seed = new Random(1938); var adminSalt = cryptService.GenerateSecret(256); var admin = new User( username: "******", salt: adminSalt, passwordHash: cryptService.GenerateHash(adminSalt, "1234"), usertype: Usertype.Admin); Users.Add(admin); SaveChanges(); var i = 0; var stores = new Faker <Store>("de").CustomInstantiator(f => { var name = f.Company.CompanyName(); var salt = cryptService.GenerateSecret(256); var username = $"store{++i:000}"; return(new Store( name: f.Company.CompanyName(), closeDate: new DateTime(2021, 1, 1).AddDays(f.Random.Int(0, 365)).OrNull(f, 0.5f), url: f.Internet.Url().OrDefault(f, 0.25f), manager: new User( username: username, salt: salt, passwordHash: cryptService.GenerateHash(salt, "1234"), usertype: Usertype.Owner))); }) .Generate(10) .GroupBy(s => s.Name).Select(g => g.First()) .ToList(); Stores.AddRange(stores); SaveChanges(); var productCategories = new Faker <ProductCategory>("de").CustomInstantiator(f => { return(new ProductCategory( name: f.Commerce.ProductAdjective(), nameEn: f.Commerce.ProductAdjective().OrDefault(f, 0.5f))); }) .Generate(10) .GroupBy(p => p.Name).Select(g => g.First()) .ToList(); ProductCategories.AddRange(productCategories); SaveChanges(); var products = new Faker <Product>("de").CustomInstantiator(f => { return(new Product( ean: f.Random.Int(100000, 999999), name: f.Commerce.ProductName(), productCategory: f.Random.ListItem(productCategories), recommendedPrice: (f.Random.Int(1000, 100000) / 100M).OrNull(f, 0.3f), availableFrom: new DateTime(2022, 1, 1).AddDays(f.Random.Int(0, 300)).OrNull(f, 0.8f) )); }) .Generate(100) .GroupBy(p => p.Ean).Select(g => g.First()) .ToList(); Products.AddRange(products); SaveChanges(); var offers = new Faker <Offer>("de").CustomInstantiator(f => { var store = f.Random.ListItem(stores); var lastUpdate = (store.CloseDate ?? new DateTime(2022, 1, 1)).AddDays(-f.Random.Int(0, 365)); return(new Offer( product: f.Random.ListItem(products), store: store, price: f.Random.Int(1000, 99900) / 100M, soldOut: f.Random.Bool(0.25f), lastUpdate: lastUpdate)); }) .Generate(500) .GroupBy(o => new { o.StoreId, o.ProductEan }).Select(g => g.First()) .ToList(); Offers.AddRange(offers); SaveChanges(); }
public UserRepository(StoreContext db, ICryptService cryptService) : base(db) { _cryptService = cryptService; }
public SessionManagerService(ISessionStorageService sessionStorageService, ILDAPService ldapService, ICryptService cryptService) { _sessionStorageService = sessionStorageService; _ldapService = ldapService; _cryptService = cryptService; }
public void Seed(ICryptService cryptService) { Randomizer.Seed = new Random(1938); var faker = new Faker("de"); var adminSalt = cryptService.GenerateSecret(256); var admin = new User( username: "******", salt: adminSalt, passwordHash: cryptService.GenerateHash(adminSalt, "1234"), usertype: Usertype.Admin); Users.Add(admin); SaveChanges(); var i = 0; var stores = new Faker <Store>("de").CustomInstantiator(f => { var name = f.Company.CompanyName(); var salt = cryptService.GenerateSecret(256); var username = $"store{++i:000}"; return(new Store( name: f.Company.CompanyName(), closeDate: new DateTime(2021, 1, 1).AddDays(f.Random.Int(0, 365)).OrNull(f, 0.5f), url: f.Internet.Url().OrDefault(f, 0.25f), manager: new User( username: username, salt: salt, passwordHash: cryptService.GenerateHash(salt, "1234"), usertype: Usertype.Owner))); }) .Generate(10) .GroupBy(s => s.Name).Select(g => g.First()) .ToList(); Stores.AddRange(stores); SaveChanges(); var productCategories = new Faker <ProductCategory>("de").CustomInstantiator(f => { return(new ProductCategory( name: f.Commerce.ProductAdjective(), nameEn: f.Commerce.ProductAdjective().OrDefault(f, 0.5f))); }) .Generate(10) .GroupBy(p => p.Name).Select(g => g.First()) .ToList(); ProductCategories.AddRange(productCategories); SaveChanges(); var products = new Faker <Product>("de").CustomInstantiator(f => { return(new Product( ean: f.Random.Int(100000, 999999), name: f.Commerce.ProductName(), productCategory: f.Random.ListItem(productCategories), recommendedPrice: (f.Random.Int(1000, 100000) / 100M).OrNull(f, 0.3f), availableFrom: new DateTime(2022, 1, 1).AddDays(f.Random.Int(0, 300)).OrNull(f, 0.8f) )); }) .Generate(100) .GroupBy(p => p.Ean).Select(g => g.First()) .ToList(); Products.AddRange(products); SaveChanges(); var offers = new Faker <Offer>("de").CustomInstantiator(f => { var store = f.Random.ListItem(stores); var lastUpdate = (store.CloseDate ?? new DateTime(2022, 1, 1)).AddDays(-f.Random.Int(0, 365)); return(new Offer( product: f.Random.ListItem(products), store: store, price: f.Random.Int(1000, 99900) / 100M, soldOut: f.Random.Bool(0.25f), lastUpdate: lastUpdate)); }) .Generate(500) .GroupBy(o => new { o.StoreId, o.ProductEan }).Select(g => g.First()) .ToList(); Offers.AddRange(offers); SaveChanges(); // Tägliche Preise generieren. Dabei wird eine Schwankung von bis zu 5 % // alle 20 - 40 Tage in die Tabelle priceTrends geschrieben. var priceTrends = new List <PriceTrend>(); foreach (var offer in offers) { var start = new DateTime(2021, 12, 31); var end = new DateTime(2021, 1, 1); var priceCent = (int)(offer.Price * 100); for (var date = start; date >= end; date = date.AddDays(-faker.Random.Int(20, 40))) { priceTrends.Add(new PriceTrend( offer: offer, date: date, price: priceCent / 100M)); var diff = (int)(priceCent * 0.05); priceCent = faker.Random.Int(priceCent - diff, priceCent + diff); } } PriceTrends.AddRange(priceTrends); SaveChanges(); }
public LoginUserHandler(IEntityRepository <User> repository, IAuthenticationService authenticationService, ICryptService cryptService) { _repository = repository; _authenticationService = authenticationService; _cryptService = cryptService; }
public void Seed(ICryptService crypt) { Randomizer.Seed = new Random(1035); var faker = new Faker("de"); var teachers = new Faker <Teacher>("de") .CustomInstantiator(f => { var lastname = f.Name.LastName(); var shortname = lastname.Left(3).ToUpper(); return(new Teacher( shortname: shortname, firstname: f.Name.FirstName(), lastname: lastname, email: f.Internet.Email())); }) .Generate(50) .GroupBy(t => t.Shortname) .Select(g => g.First()) .Take(30) .ToList(); Teachers.AddRange(teachers); SaveChanges(); var users = new Faker <User>("de") .CustomInstantiator(f => { var teacher = f.Random.ListItem(teachers); var salt = crypt.GenerateSecret(256); return(new User( username: teacher.Email, salt: salt, passwordHash: crypt.GenerateHash(salt, "1234"), teacher: teacher)); }) .Generate(20) .GroupBy(u => u.TeacherId).Select(g => g.First()) .ToList(); Users.AddRange(users); SaveChanges(); var subjects = new Faker <Subject>("de") .CustomInstantiator(f => { var name = f.Commerce.ProductMaterial(); var shortname = name.Left(3).ToUpper(); return(new Subject( shortname: shortname, name: name)); }) .Generate(50) .GroupBy(t => t.Shortname) .Select(g => g.First()) .Take(10) .ToList(); Subjects.AddRange(subjects); SaveChanges(); var departments = new string[] { "HIF", "HBGM", "HMNA" }; var classes = new Faker <SchoolClass>("de") .CustomInstantiator(f => { var name = $"{f.Random.Int(1, 5)}{f.Random.String2(1, "ABCDE")}{f.Random.ListItem(departments)}"; return(new SchoolClass(name, f.Random.ListItem(teachers))); }) .Rules((f, sc) => { var room = $"{f.Random.String2(1, "ABCD")}{f.Random.String2(1, "E1234")}.{f.Random.String2(1, "01")}{f.Random.Int(1, 9)}"; sc.Room = room.OrDefault(f, 0.2f); int i = 100; var students = new Faker <Student>("de") .CustomInstantiator(f2 => { var lastname = f2.Name.LastName(); var firstname = f2.Name.FirstName(); var account = $"{(lastname.Length < 3 ? lastname : lastname.Substring(0, 3)).ToUpper()}{i:0000}"; var dateOfBirth = new DateTime(2000, 1, 1) .AddDays(f2.Random.Int(0, 5 * 365)); i++; var home = new Address( f2.Address.City(), f2.Random.Int(1000, 9999).ToString(), f2.Address.StreetAddress()); return(new Student( account: account, lastname: lastname, firstname: firstname, home: home, dateOfBirth: dateOfBirth, schoolClass: sc)); }) .Rules((f2, s) => { s.Email = f2.Internet.Email(); var parents = new Address( f2.Address.City(), f2.Random.Int(1000, 9999).ToString(), f2.Address.StreetAddress()); s.Parents = parents.OrDefault(f2, 0.25f); }) .Generate(20) .ToList(); sc.Students.AddRange(students); }) .Generate(20) .GroupBy(s => s.Name) .Select(g => g.First()) .Take(10) .ToList(); SchoolClasses.AddRange(classes); SaveChanges(); // 20 exams per class -> 200 exams var exams = new Faker <Exam>("de") .CustomInstantiator(f => { return(new Exam( teacher: f.Random.ListItem(teachers), subject: f.Random.ListItem(subjects), date: new DateTime(2021, 10, 1) .AddDays(f.Random.Int(0, 30 * 9)) .AddHours(f.Random.Int(8, 16)), schoolClass: f.Random.ListItem(classes))); }) .Generate(200) .ToList(); Exam.AddRange(exams.Take(100)); SaveChanges(); CommitedExams.AddRange(exams .Skip(100) .Select(e => { var room = $"{faker.Random.String2(1, "ABCD")}{faker.Random.String2(1, "E1234")}.{faker.Random.String2(1, "01")}{faker.Random.Int(1, 9)}"; return(new CommitedExam(e, room)); })); SaveChanges(); }