Exemplo n.º 1
0
 public UserRoleCountryService(IUserRoleCountryRepository repository, ILocalizationRepository localizationRepository,
                               ILogger <UserRoleCountryService> logger, UserManager <ApplicationUser> userManager)
 {
     _localizationRepository = localizationRepository;
     _repository             = repository;
     _logger      = logger;
     _userManager = userManager;
 }
Exemplo n.º 2
0
        public void Init()
        {
            var services = new ServiceCollection();

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "test_db")
                          .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
                          .Options;

            _memoryDbContext = new ApplicationDbContext(options);

            //Arrange
            var _localizationRepo = Substitute.For <ILocalizationRepository>();
            var _loggerRepo       = Substitute.For <ILogger <UserRoleCountryService> >();
            var _userStore        = Substitute.For <IUserStore <ApplicationUser> >();
            var _userManager      = Substitute.For <UserManager <ApplicationUser> >(_userStore, null, null, null, null, null, null, null, null);

            services.AddTransient <IUserRoleCountryRepository, UserRoleCountryRepository>();
            var serviceProvider = services.BuildServiceProvider();

            _urcRepository = new UserRoleCountryRepository(_memoryDbContext);
            _urcService    = Substitute.For <UserRoleCountryService>(_urcRepository, _localizationRepo,
                                                                     _loggerRepo, _userManager);

            _urcs = new FakeDbSet <UserRoleCountry>(
                Builder <UserRoleCountry> .CreateListOfSize(10)
                .All()
                .With(c => c.ApplicationUserId = UserId)
                .With(c => c.ID            = Guid.NewGuid())
                .With(cid => cid.CountryId = CountryId).Build());

            if (_memoryDbContext.UserRoleCountries.Count() == 0)
            {
                _memoryDbContext.UserRoleCountries.AddRange(_urcs);
                _memoryDbContext.SaveChanges();
            }
        }