public async Task ConfirmUserAccountAsyncWorkCorrectly()
        {
            var context                      = ApplicationDbContextInMemoryFactory.InitializeContext();
            var testUserRepository           = new EfDeletableEntityRepository <ApplicationUser>(context);
            var testNotConfirmedUsers        = TestDataHelpers.GetTestNotConfirmedUsers();
            var testAccountManagementService = new AccountManagementService(this.userManager.Object, testUserRepository, this.accountRepository.Object, this.positionService.Object, this.feePaymentsRepository.Object);

            foreach (var tester in testNotConfirmedUsers)
            {
                await testUserRepository.AddAsync(tester);

                await testUserRepository.SaveChangesAsync();
            }

            var user = new ClientToBeConfirmedViewModel
            {
                UserId     = "11",
                Username   = "******",
                Email      = "[email protected]",
                Balance    = 5000,
                TradeFee   = 50,
                MonthlyFee = 100,
                Notes      = null,
            };

            var testUser = testUserRepository.All().FirstOrDefault(u => u.Id == "11");

            Assert.IsNull(testUser.Account);

            await testAccountManagementService.ConfirmUserAccountAsync(user);

            Assert.IsNotNull(testUser.Account);
        }
        public async Task ConfirmUserAccountAsyncShouldCallUserManager()
        {
            var context                      = ApplicationDbContextInMemoryFactory.InitializeContext();
            var testUserRepository           = new EfDeletableEntityRepository <ApplicationUser>(context);
            var testNotConfirmedUsers        = TestDataHelpers.GetTestNotConfirmedUsers();
            var testAccountManagementService = new AccountManagementService(this.userManager.Object, testUserRepository, this.accountRepository.Object, this.positionService.Object, this.feePaymentsRepository.Object);

            foreach (var tester in testNotConfirmedUsers)
            {
                await testUserRepository.AddAsync(tester);

                await testUserRepository.SaveChangesAsync();
            }

            var user = new ClientToBeConfirmedViewModel
            {
                UserId     = "11",
                Username   = "******",
                Email      = "[email protected]",
                Balance    = 5000,
                TradeFee   = 50,
                MonthlyFee = 100,
                Notes      = null,
            };

            await testAccountManagementService.ConfirmUserAccountAsync(user);

            this.userManager.Verify(u => u.RemoveFromRoleAsync(It.IsAny <ApplicationUser>(), GlobalConstants.NotConfirmedUserRoleName), Times.Once);
            this.userManager.Verify(u => u.AddToRoleAsync(It.IsAny <ApplicationUser>(), GlobalConstants.ConfirmedUserRoleName), Times.Once);
        }
Ejemplo n.º 3
0
        public void TestClearAbschnitteInSummarischeModus()
        {
            using (var scope = new NHibernateTestScope())
            {
                var erfassungsPeriod = scope.Session.Query <ErfassungsPeriod>().Single(m => !m.IsClosed);

                erfassungsPeriod.NetzErfassungsmodus = NetzErfassungsmodus.Summarisch;

                scope.Session.Save(erfassungsPeriod);

                var belastungskategorie = TestDataHelpers.GetBelastungskategorie(scope, "IA");

                var strassenabschnittOne = TestDataHelpers.GetStrassenabschnitt(erfassungsPeriod, "SA0", belastungskategorie, EigentuemerTyp.Gemeinde);
                scope.Session.Save(strassenabschnittOne);

                var zustandsabschnittOne = TestDataHelpers.GetZustandsabschnitt(strassenabschnittOne, 1);
                scope.Session.Save(zustandsabschnittOne);
            }

            DoJahresabschluss();

            using (var scope = new NHibernateTestScope())
            {
                var erfassungsPeriod = scope.Session.Query <ErfassungsPeriod>().Single(m => !m.IsClosed);

                var strassenabschnittCount = scope.Session.Query <Strassenabschnitt>().Count(sa => sa.ErfassungsPeriod == erfassungsPeriod);
                var zustandsabschnittCount = scope.Session.Query <Zustandsabschnitt>().Count(za => za.Strassenabschnitt.ErfassungsPeriod == erfassungsPeriod);

                Assert.AreEqual(0, strassenabschnittCount);
                Assert.AreEqual(0, zustandsabschnittCount);
            }
        }
        public async Task RestoreUserAccountAsyncShouldCallUserManager()
        {
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var testAccountRepository = new EfDeletableEntityRepository <Account>(context);

            var testAccounts = TestDataHelpers.GetTestData();

            foreach (var testAccount in testAccounts)
            {
                if (testAccount.Id == 1)
                {
                    testAccount.IsDeleted = true;
                }

                await testAccountRepository.AddAsync(testAccount);

                await testAccountRepository.SaveChangesAsync();
            }

            var testAccountManagementService = new AccountManagementService(this.userManager.Object, this.userRepository.Object, testAccountRepository, this.positionService.Object, this.feePaymentsRepository.Object);

            await testAccountManagementService.RestoreUserAccountAsync("1", 1);

            this.userManager.Verify(u => u.RemoveFromRoleAsync(It.IsAny <ApplicationUser>(), It.IsAny <string>()), Times.Once);
            this.userManager.Verify(u => u.AddToRoleAsync(It.IsAny <ApplicationUser>(), It.IsAny <string>()), Times.Once);
        }
        public async Task ImportDataShouldUpdateRepositoriesWithNewData()
        {
            await this.stockService.ImportData(TestDataHelpers.GetNewDateJSON(), GlobalConstants.StockTicker);

            this.metadataRepository.Verify(x => x.SaveChangesAsync(), Times.Once);
            this.datasetRepository.Verify(x => x.SaveChangesAsync(), Times.AtLeastOnce);
        }
        public void Setup()
        {
            this.stockRepository    = new Mock <IDeletableEntityRepository <Stock> >();
            this.datasetRepository  = new Mock <IDeletableEntityRepository <DataSet> >();
            this.metadataRepository = new Mock <IDeletableEntityRepository <MetaData> >();
            this.intervalRepository = new Mock <IDeletableEntityRepository <Interval> >();
            this.memoryCache        = new MemoryCache(new MemoryCacheOptions());

            var mockStocks = TestDataHelpers.GetTestStocks().AsQueryable().BuildMock();

            this.stockRepository
            .Setup(s => s.All())
            .Returns(mockStocks.Object);
            this.stockRepository
            .Setup(d => d.SaveChangesAsync());

            var mockIntervals = TestDataHelpers.GetTestIntervals().AsQueryable().BuildMock();

            this.intervalRepository
            .Setup(i => i.All())
            .Returns(mockIntervals.Object);

            var mockDatasets = TestDataHelpers.GetTestDataSets().AsQueryable().BuildMock();

            this.datasetRepository
            .Setup(d => d.All())
            .Returns(mockDatasets.Object);

            var mockMetaData = new List <MetaData>().AsQueryable().BuildMock();

            this.datasetRepository
            .Setup(d => d.SaveChangesAsync());

            this.stockService = new StockService(this.stockRepository.Object, this.intervalRepository.Object, this.datasetRepository.Object, this.metadataRepository.Object, this.memoryCache);
        }
Ejemplo n.º 7
0
        private void InsertTestData()
        {
            using (var scope = new NHibernateTestScope())
            {
                var belastungskategorie = TestDataHelpers.GetBelastungskategorie(scope, "IA");

                var entityThree = TestDataHelpers.GetStrassenabschnittGIS(GetCurrentErfassungsPeriod(scope), "SA01", belastungskategorie, EigentuemerTyp.Gemeinde);
                scope.Session.Save(entityThree);

                var entityTwo = TestDataHelpers.GetStrassenabschnittGIS(GetCurrentErfassungsPeriod(scope), "SA02", belastungskategorie, EigentuemerTyp.Kanton);
                scope.Session.Save(entityTwo);

                var entiyThree = TestDataHelpers.GetStrassenabschnittGIS(GetClosedErfassungPeriod(scope), "SA03", belastungskategorie, EigentuemerTyp.Korporation);
                scope.Session.Save(entiyThree);

                var entityOtherMandant = TestDataHelpers.GetStrassenabschnittGIS(GetOtherErfassungPeriod(scope), "SA01", belastungskategorie, EigentuemerTyp.Gemeinde);
                scope.Session.Save(entityOtherMandant);

                var inspektionsRouteGISOne = TestDataHelpers.GetInspektionsRouteGIS(GetCurrentErfassungsPeriod(scope), "IR01", null, entityThree);
                scope.Session.Save(inspektionsRouteGISOne);

                var inspektionsRouteGISTwo = TestDataHelpers.GetInspektionsRouteGIS(GetCurrentErfassungsPeriod(scope), "IR02", new DateTime(2010, 10, 10), entityTwo);
                scope.Session.Save(inspektionsRouteGISTwo);

                var inspektionsRouteGISThree = TestDataHelpers.GetInspektionsRouteGIS(GetClosedErfassungPeriod(scope), "IR03", null, entiyThree);
                scope.Session.Save(inspektionsRouteGISThree);

                var inspektionsRouteGISFour = TestDataHelpers.GetInspektionsRouteGIS(GetOtherErfassungPeriod(scope), "IR01", null, entityOtherMandant);
                scope.Session.Save(inspektionsRouteGISFour);
            }
        }
        public async Task RestoreUserAccountAsyncShouldWorkCorrectly()
        {
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var testAccountRepository = new EfDeletableEntityRepository <Account>(context);

            var testAccounts = TestDataHelpers.GetTestData();

            foreach (var testAccount in testAccounts)
            {
                if (testAccount.Id == 1)
                {
                    testAccount.IsDeleted = true;
                }

                await testAccountRepository.AddAsync(testAccount);

                await testAccountRepository.SaveChangesAsync();
            }

            var testAccountManagementService = new AccountManagementService(this.userManager.Object, this.userRepository.Object, testAccountRepository, this.positionService.Object, this.feePaymentsRepository.Object);

            await testAccountManagementService.RestoreUserAccountAsync("1", 1);

            var account = testAccountRepository
                          .AllWithDeleted()
                          .FirstOrDefault(a => a.Id == 1);

            Assert.IsFalse(account.IsDeleted);
        }
        public void Setup()
        {
            this.mock = TestDataHelpers.GetTestData().AsQueryable().BuildMock();

            this.accountRepository = new Mock <IDeletableEntityRepository <Account> >();

            this.accountRepository
            .Setup(a => a.All())
            .Returns(this.mock.Object);

            this.positionService = new Mock <IPositionsService>();

            this.positionService
            .Setup(p => p.OpenPosition(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <decimal>(), It.IsAny <bool>()));

            this.positionService
            .Setup(p => p.UpdatePosition(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <decimal>(), It.IsAny <bool>()));

            this.positionService
            .Setup(p => p.GetAccountClosedPositions(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(TestDataHelpers.GetTestPositionsTradeHistory);

            this.positionService
            .Setup(x => x.GetOpenPosition(1))
            .ReturnsAsync(TestDataHelpers.GetTestPosition());

            this.positionService
            .Setup(x => x.GetOpenPosition(2))
            .ReturnsAsync(() => null);

            this.accountService = new AccountService(this.accountRepository.Object, this.positionService.Object);
        }
        public void ModTitleConstructor_WhenTitleIsTooLong_ThrowsArgumentException()
        {
            var exception = Assert.Throws <ArgumentOutOfRangeException>(() => new ModTitle(
                                                                            Language: LanguageTestData.EnglishWithoutId,
                                                                            Title: TestDataHelpers.GetRandomizedUnicodeCharacterString(ModTitle.TitleLength + 1)));

            Assert.Equal($"Title must not exceed {ModTitle.TitleLength.ToString()} characters. (Parameter 'Title')", exception.Message);
        }
        public void ModConstructor_WhenNameIsTooLong_ThrowsArgumentException()
        {
            var exception = Assert.Throws <ArgumentOutOfRangeException>(() => new Mod(
                                                                            Name: TestDataHelpers.GetRandomCharacterStringFromSet(Mod.ValidModNameCharacters, Mod.NameLength + 1),
                                                                            Titles: ModTitleTestData.TestModTitles,
                                                                            Releases: ReleaseTestData.TestModReleases));

            Assert.Equal($"Name must not exceed {Mod.NameLength.ToString()} characters. (Parameter 'Name')", exception.Message);
        }
        public void Init()
        {
            _clients = TestDataHelpers.GetTestClients(3);
            _client  = _clients.First();
            var dbpath = $@"{TestContext.CurrentContext.TestDirectory}\livehts.db";

            _database    = new SQLiteConnection(dbpath);
            _liveSetting = new LiveSetting(_database.DatabasePath);
            Console.WriteLine(dbpath);
        }
Ejemplo n.º 13
0
        public async Task Deserialise_Correctly()
        {
            var formatters   = _container.Resolve <MediaTypeFormatterCollection>();
            var formatter    = formatters.FindReader(typeof(ResponseWrapper <ServerStatus>), new MediaTypeHeaderValue("application/xml"));
            var httpResponse = TestDataHelpers.GetServerStatus();
            var stream       = await httpResponse.Content.ReadAsStreamAsync();

            var result = await formatter.ReadFromStreamAsync(typeof(ResponseWrapper <ServerStatus>), stream, httpResponse.Content, null)
                         as ResponseWrapper <ServerStatus>;

            Assert.AreEqual(34999, result.Result.OnlinePlayers);
            Assert.AreEqual("True", result.Result.ServerOpen);
        }
        private static async Task <EfDeletableEntityRepository <Account> > GetTestAcctRepository()
        {
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var testAccountRepository = new EfDeletableEntityRepository <Account>(context);

            var testAccounts = TestDataHelpers.GetTestData();

            foreach (var testAccount in testAccounts)
            {
                await testAccountRepository.AddAsync(testAccount);

                await testAccountRepository.SaveChangesAsync();
            }

            return(testAccountRepository);
        }
        public async Task GetAccountClosedPositionsWorkCorrectly()
        {
            var positions = TestDataHelpers.GetTestPositions();

            foreach (var position in positions)
            {
                await this.positionRepository.AddAsync(position);

                await this.positionRepository.SaveChangesAsync();
            }

            var result =
                await this.positionsService.GetAccountClosedPositions(1, DateTime.Parse("01.01.2019").ToShortDateString(), DateTime.Parse("01.01.2020").ToShortDateString());

            CollectionAssert.IsNotEmpty(result);
        }
        public void Setup()
        {
            this.mock          = TestDataHelpers.GetTestData().AsQueryable().BuildMock();
            this.mockPositions = TestDataHelpers.GetTestHistoryPositions().AsQueryable().BuildMock();

            this.accountRepository = new Mock <IDeletableEntityRepository <Account> >();
            this.accountRepository
            .Setup(a => a.All())
            .Returns(this.mock.Object);

            this.positionService = new Mock <IPositionsService>();
            this.positionService
            .Setup(p => p.GetAccountClosedPositions(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(this.mockPositions.Object);

            this.userService = new UserService(this.accountRepository.Object, this.positionService.Object);
        }
Ejemplo n.º 17
0
        private void InsertTestData()
        {
            using (var scope = new NHibernateTestScope())
            {
                var entityOne = TestDataHelpers.GetMassnahmenvorschlagTeilsystemeGIS(GetCurrentErfassungsPeriod(scope), "MT01", StatusTyp.Abgeschlossen, DringlichkeitTyp.Mittelfristig, TeilsystemTyp.Strassen);
                scope.Session.Save(entityOne);

                var entiyTwo = TestDataHelpers.GetMassnahmenvorschlagTeilsystemeGIS(GetCurrentErfassungsPeriod(scope), "MT02", StatusTyp.Vorgeschlagen, DringlichkeitTyp.Dringlich, TeilsystemTyp.Beleuchtungsanlagen);
                scope.Session.Save(entiyTwo);

                var entiyThree = TestDataHelpers.GetMassnahmenvorschlagTeilsystemeGIS(GetClosedErfassungPeriod(scope), "MT03", StatusTyp.InKoordination, DringlichkeitTyp.Langfristig, TeilsystemTyp.Gruenanlagen);
                scope.Session.Save(entiyThree);

                var entityOtherMandant = TestDataHelpers.GetMassnahmenvorschlagTeilsystemeGIS(GetOtherErfassungPeriod(scope), "MT01", StatusTyp.Abgeschlossen, DringlichkeitTyp.Mittelfristig, TeilsystemTyp.Strassen);
                scope.Session.Save(entityOtherMandant);
            }
        }
        private void InsertTestData()
        {
            using (var scope = new NHibernateTestScope())
            {
                var entiyOne = TestDataHelpers.GetKoordinierteMassnahmeGIS(GetCurrentErfassungsPeriod(scope), "KM01", StatusTyp.Abgeschlossen, new DateTime(2012, 06, 04));
                scope.Session.Save(entiyOne);

                var entiyTwo = TestDataHelpers.GetKoordinierteMassnahmeGIS(GetCurrentErfassungsPeriod(scope), "KM02", StatusTyp.Vorgeschlagen, new DateTime(2012, 06, 8));
                scope.Session.Save(entiyTwo);

                var entiyThree = TestDataHelpers.GetKoordinierteMassnahmeGIS(GetClosedErfassungPeriod(scope), "KM03", StatusTyp.InKoordination, null);
                scope.Session.Save(entiyThree);

                var entityOtherMandant = TestDataHelpers.GetKoordinierteMassnahmeGIS(GetOtherErfassungPeriod(scope), "KM01", StatusTyp.Abgeschlossen, new DateTime(2012, 06, 04));
                scope.Session.Save(entityOtherMandant);
            }
        }
        public void Setup()
        {
            this.mockNotConfirmedUsers = TestDataHelpers.GetTestNotConfirmedUsers();
            this.userStoreMock         = new Mock <IUserStore <ApplicationUser> >();
            this.userManager           = new Mock <UserManager <ApplicationUser> >(this.userStoreMock.Object, null, null, null, null, null, null, null, null);
            this.userManager
            .Setup(u => u.GetUsersInRoleAsync(GlobalConstants.NotConfirmedUserRoleName))
            .ReturnsAsync(this.mockNotConfirmedUsers);
            this.userManager
            .Setup(
                u => u.RemoveFromRoleAsync(It.IsAny <ApplicationUser>(), It.IsAny <string>()))
            .ReturnsAsync(IdentityResult.Success);
            this.userManager
            .Setup(
                u => u.AddToRoleAsync(It.IsAny <ApplicationUser>(), It.IsAny <string>()))
            .ReturnsAsync(IdentityResult.Success);

            this.mock = TestDataHelpers.GetTestData().AsQueryable().BuildMock();
            this.accountRepository = new Mock <IDeletableEntityRepository <Account> >();
            this.accountRepository
            .Setup(a => a.All())
            .Returns(this.mock.Object);
            this.accountRepository
            .Setup(a => a.AllWithDeleted())
            .Returns(this.mock.Object);

            this.mockUsers      = TestDataHelpers.GetTestUsers().AsQueryable().BuildMock();
            this.userRepository = new Mock <IDeletableEntityRepository <ApplicationUser> >();
            this.userRepository
            .Setup(a => a.AllWithDeleted())
            .Returns(this.mockUsers.Object);

            this.mockFees = TestDataHelpers.GetTestFeePayments().AsQueryable().BuildMock();
            this.feePaymentsRepository = new Mock <IRepository <FeePayment> >();
            this.feePaymentsRepository
            .Setup(f => f.All())
            .Returns(this.mockFees.Object);

            this.positionService = new Mock <IPositionsService>();
            this.positionService
            .Setup(p => p.ClosePosition(It.IsAny <int>()));

            this.accountManagementService = new AccountManagementService(this.userManager.Object, this.userRepository.Object, this.accountRepository.Object, this.positionService.Object, this.feePaymentsRepository.Object);
        }
        public async Task DeleteUserAsyncShouldThrowException()
        {
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var testUserRepository = new EfDeletableEntityRepository <ApplicationUser>(context);
            var testUsers          = TestDataHelpers.GetTestUsers();

            foreach (var tester in testUsers)
            {
                await testUserRepository.AddAsync(tester);

                await testUserRepository.SaveChangesAsync();
            }

            var testAccountRepository = new Mock <IDeletableEntityRepository <Account> >();

            var testAccountManagementService = new AccountManagementService(this.userManager.Object, testUserRepository, testAccountRepository.Object, this.positionService.Object, this.feePaymentsRepository.Object);

            Assert.ThrowsAsync <NullReferenceException>(async() => await testAccountManagementService.DeleteUserAsync("-1", 1));
        }
        public void Setup()
        {
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            this.positionRepository = new EfDeletableEntityRepository <Position>(context);

            this.mockAccounts = TestDataHelpers.GetTestData().AsQueryable().BuildMock();
            this.mockStocks   = TestDataHelpers.GetTestStocks().AsQueryable().BuildMock();

            this.accountRepository = new Mock <IDeletableEntityRepository <Account> >();
            this.stockRepository   = new Mock <IDeletableEntityRepository <Stock> >();
            this.datasetRepository = new Mock <IDeletableEntityRepository <DataSet> >();

            this.accountRepository
            .Setup(a => a.All())
            .Returns(this.mockAccounts.Object);

            this.stockRepository
            .Setup(s => s.All())
            .Returns(this.mockStocks.Object);

            this.datasetRepository
            .Setup(d => d.All())
            .Returns(new List <DataSet>()
            {
                new DataSet()
                {
                    DateAndTime = DateTime.Now,
                    ClosePrice  = 100.00M,
                },
                new DataSet()
                {
                    DateAndTime = DateTime.Parse("31.12.2018"),
                    ClosePrice  = 100.00M,
                },
            }.AsQueryable());

            this.positionsService = new PositionsService(this.positionRepository, this.accountRepository.Object, this.stockRepository.Object, this.datasetRepository.Object);
        }
        private void InsertTestData()
        {
            using (var scope = new NHibernateTestScope())
            {
                var belastungskategorie = TestDataHelpers.GetBelastungskategorie(scope, "IA");

                var strassenabschnittOne = TestDataHelpers.GetStrassenabschnitt(GetCurrentErfassungsPeriod(scope), "SA01", belastungskategorie, EigentuemerTyp.Gemeinde);
                scope.Session.Save(strassenabschnittOne);
                scope.Session.Save(TestDataHelpers.GetZustandsabschnitt(strassenabschnittOne, 1));

                var strassenabschnittTwo = TestDataHelpers.GetStrassenabschnitt(GetCurrentErfassungsPeriod(scope), "SA02", belastungskategorie, EigentuemerTyp.Kanton);
                scope.Session.Save(strassenabschnittTwo);
                scope.Session.Save(TestDataHelpers.GetZustandsabschnitt(strassenabschnittTwo, 2));

                var strassenabschnittThree = TestDataHelpers.GetStrassenabschnitt(GetClosedErfassungPeriod(scope), "SA03", belastungskategorie, EigentuemerTyp.Korporation);
                scope.Session.Save(strassenabschnittThree);
                scope.Session.Save(TestDataHelpers.GetZustandsabschnitt(strassenabschnittThree, 3));

                var strassenabschnittOtherMandant = TestDataHelpers.GetStrassenabschnitt(GetOtherErfassungPeriod(scope), "SA01", belastungskategorie, EigentuemerTyp.Gemeinde);
                scope.Session.Save(strassenabschnittOtherMandant);
                scope.Session.Save(TestDataHelpers.GetZustandsabschnitt(strassenabschnittOtherMandant, 1));
            }
        }
Ejemplo n.º 23
0
        public async Task TestExecuteReader()
        {
            var d = new SQLiteConnection("Data Source=:memory:");

            d.Open();

            d.ExecuteSql("CREATE TABLE Test123 ( Col1 int, Col2 decimal(3,4), Col3 varchar(255) )");

            var dr = TestDataHelpers.GetSampleDataReader(DataReaderSource.ObjectReader, 3);

            await dr.BulkInsertUsingInsertStatements(d, "Test123", DatabaseEngine.Sqlite);

            var dr2 = d.ExecuteReader("SELECT * FROM Test123");



            var rr = dr2.SelectStrict <Test123>().ToArray();

            Assert.AreEqual(3, rr.Length);

            d.Close();
            d.Dispose();
        }
        public async Task Setup()
        {
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            this.userRepository = new EfDeletableEntityRepository <ApplicationUser>(context);

            var mockUsers = TestDataHelpers.GetTestUsers();

            foreach (var user in mockUsers)
            {
                await this.userRepository.AddAsync(user);

                await this.userRepository.SaveChangesAsync();
            }

            var userStoreMock = new Mock <IUserStore <ApplicationUser> >();

            this.userManager = new Mock <UserManager <ApplicationUser> >(
                userStoreMock.Object, null, null, null, null, null, null, null, null);
            this.userManager
            .Setup(m => m.GetUsersInRoleAsync(GlobalConstants.AccountManagerRoleName))
            .ReturnsAsync(mockUsers);
            this.userManager
            .Setup(u => u.RemoveFromRoleAsync(It.IsAny <ApplicationUser>(), GlobalConstants.AccountManagerRoleName))
            .ReturnsAsync(IdentityResult.Success);
            this.userManager
            .Setup(u => u.AddToRoleAsync(It.IsAny <ApplicationUser>(), GlobalConstants.AccountManagerRoleName))
            .ReturnsAsync(IdentityResult.Success);
            this.userManager
            .Setup(u => u.CreateAsync(It.IsAny <ApplicationUser>(), It.IsAny <string>()))
            .ReturnsAsync(IdentityResult.Success);
            this.userManager
            .Setup(u => u.UpdateAsync(It.IsAny <ApplicationUser>()))
            .ReturnsAsync(IdentityResult.Success);

            this.administratorService = new AdministratorService(this.userManager.Object, this.userRepository);
        }
        public async Task DeleteUserAsyncShouldDeleteUserAccountCorrectly()
        {
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var testAccountRepository = new EfDeletableEntityRepository <Account>(context);
            var testAccounts          = TestDataHelpers.GetTestData();

            foreach (var acc in testAccounts)
            {
                await testAccountRepository.AddAsync(acc);

                await testAccountRepository.SaveChangesAsync();
            }

            var testUserRepository = new Mock <IDeletableEntityRepository <ApplicationUser> >();

            testUserRepository
            .Setup(a => a.GetByIdWithDeletedAsync(It.IsAny <string>()))
            .ReturnsAsync(new ApplicationUser()
            {
                Id        = "1",
                IsDeleted = false,
            });
            testUserRepository
            .Setup(a => a.Delete(It.IsAny <ApplicationUser>()));
            testUserRepository
            .Setup(a => a.SaveChangesAsync());

            var testAccountManagementService = new AccountManagementService(this.userManager.Object, testUserRepository.Object, testAccountRepository, this.positionService.Object, this.feePaymentsRepository.Object);

            await testAccountManagementService.DeleteUserAsync("1", 1);

            var account = testAccountRepository.AllWithDeleted().FirstOrDefault(a => a.Id == 1);

            Assert.IsTrue(account.IsDeleted);
        }
        public static String GenerateRandomizedReleaseDownloadUrlTokenTooLong()
        {
            var random = new Random();

            return(TestDataHelpers.GetRandomCharacterStringFromSet(ReleaseDownloadUrl.ValidReleaseTokenCharacters, ReleaseDownloadUrl.ReleaseTokenLength + random.Next(1, 100)));
        }
 public static String GenerateValidRandomizedReleaseDownloadUrlToken()
 {
     return(TestDataHelpers.GetRandomCharacterStringFromSet(ReleaseDownloadUrl.ValidReleaseTokenCharacters, ReleaseDownloadUrl.ReleaseTokenLength));
 }
        public async Task ImportDataShouldNotUpdateMetadataRepositoryWithUpToDateData()
        {
            await this.stockService.ImportData(TestDataHelpers.GetUpToDateJSON(), GlobalConstants.StockTicker);

            this.metadataRepository.Verify(x => x.SaveChangesAsync(), Times.Never);
        }
        public void LanguageConstructor_WhenLanguageTagIsTooLong_ThrowsArgumentException()
        {
            var exception = Assert.Throws <ArgumentOutOfRangeException>(() => new Language(
                                                                            EnglishName: "English",
                                                                            LanguageTag: TestDataHelpers.GetRandomCharacterStringFromSet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-", Language.LanguageTagLength + 1),
                                                                            IsDefault: false));

            Assert.Equal($"LanguageTag must not exceed {Language.LanguageTagLength.ToString()} characters. (Parameter 'LanguageTag')", exception.Message);
        }
        private void InsertTestData()
        {
            ErfassungsPeriod oldErfassungPeriod;

            using (var scope = new NHibernateTestScope())
            {
                var current = scope.Session.Get <ErfassungsPeriod>(GetClosedErfassungPeriod(scope).Id);
                oldErfassungPeriod                = DbHandlerUtils.CreateErfassungsPeriod(scope.Session, current.Mandant, Erfassungmodus);
                oldErfassungPeriod.IsClosed       = true;
                oldErfassungPeriod.Erfassungsjahr = new DateTime(2009, 1, 1);
            }

            using (var scope = new NHibernateTestScope())
            {
                var entiyOne = TestDataHelpers.GetRealisierteMassnahmeGIS(GetCurrentErfassungsPeriod(scope), "RMG01", "ORG1", "BeschreibungGIS1");
                scope.Session.Save(entiyOne);

                var entiyTwo = TestDataHelpers.GetRealisierteMassnahmeGIS(GetCurrentErfassungsPeriod(scope), "RMG02", "ORG2", "BeschreibungGIS2");
                scope.Session.Save(entiyTwo);

                var entiyThree = TestDataHelpers.GetRealisierteMassnahmeGIS(GetClosedErfassungPeriod(scope), "RMG03", "ORG3", "BeschreibungGIS3");
                scope.Session.Save(entiyThree);

                var entityOtherMandant = TestDataHelpers.GetRealisierteMassnahmeGIS(GetOtherErfassungPeriod(scope), "RMGO01", "ORG1", "BeschreibungGIS4");
                scope.Session.Save(entityOtherMandant);

                var oldEntity = TestDataHelpers.GetRealisierteMassnahmeGIS(oldErfassungPeriod, "RMG01", "ORG1", "BeschreibungGIS5");
                scope.Session.Save(oldEntity);
            }

            using (var scope = new NHibernateTestScope())
            {
                var entiyOne = TestDataHelpers.GetRealisierteMassnahmeSummarisch(GetCurrentErfassungsPeriod(scope), "RMS01", "BeschreibungSum1");
                scope.Session.Save(entiyOne);

                var entiyTwo = TestDataHelpers.GetRealisierteMassnahmeSummarisch(GetCurrentErfassungsPeriod(scope), "RMS02", "BeschreibungSum2");
                scope.Session.Save(entiyTwo);

                var entiyThree = TestDataHelpers.GetRealisierteMassnahmeSummarisch(GetClosedErfassungPeriod(scope), "RMS03", "BeschreibungSum3");
                scope.Session.Save(entiyThree);

                var entityOtherMandant = TestDataHelpers.GetRealisierteMassnahmeSummarisch(GetOtherErfassungPeriod(scope), "RMSO01", "BeschreibungSum4");
                scope.Session.Save(entityOtherMandant);

                var oldEntity = TestDataHelpers.GetRealisierteMassnahmeSummarisch(GetOtherErfassungPeriod(scope), "RMS01", "BeschreibungSum5");
                scope.Session.Save(oldEntity);
            }

            using (var scope = new NHibernateTestScope())
            {
                var entiyOne = TestDataHelpers.GetRealisierteMassnahme(GetCurrentErfassungsPeriod(scope), "RMT01", "BeschreibungTab1");
                scope.Session.Save(entiyOne);

                var entiyTwo = TestDataHelpers.GetRealisierteMassnahme(GetCurrentErfassungsPeriod(scope), "RMT02", "BeschreibungTab2");
                scope.Session.Save(entiyTwo);

                var entiyThree = TestDataHelpers.GetRealisierteMassnahme(GetClosedErfassungPeriod(scope), "RMT03", "BeschreibungTab3");
                scope.Session.Save(entiyThree);

                var entityOtherMandant = TestDataHelpers.GetRealisierteMassnahme(GetOtherErfassungPeriod(scope), "RMTO01", "BeschreibungTab4");
                scope.Session.Save(entityOtherMandant);

                var oldEntity = TestDataHelpers.GetRealisierteMassnahme(GetOtherErfassungPeriod(scope), "RMT01", "BeschreibungTab5");
                scope.Session.Save(oldEntity);
            }
        }