Пример #1
0
        public void GetAll_Returns_1DistinctRole()
        {
            var roles = AppRoles.GetAll();

            Assert.AreEqual(1, roles.Distinct().Count());
        }
Пример #2
0
        /// <summary>
        /// Inserts master data and other static data required by the api/app to be functional.
        /// </summary>
        /// <param name="context"></param>
        private void InsertMandatoryData(AppDatabaseContext context)
        {
            #region UserRoles

            var userRoles = new List <AppRole>();
            foreach (var role in AppRoles.GetAll())
            {
                userRoles.Add(new AppRole {
                    Name = role
                });
            }
            ;

            foreach (var role in userRoles)
            {
                context.Roles.AddOrUpdate(r => r.Name, role);
                context.SaveChanges();
            }

            #endregion

            #region Countries

            foreach (var countryName in _countries)
            {
                var country = new Country {
                    Name = countryName
                };
                context.Countries.AddOrUpdate(c => c.Name, country);
                context.SaveChanges();
            }

            #endregion

            #region India - states

            var india = context.Countries.FirstOrDefault(c => c.Name == "India");
            foreach (var stateName in _indiaStates)
            {
                var state = new State {
                    Name = stateName, CountryId = india.Id
                };
                context.States.AddOrUpdate(c => c.Name, state);
                context.SaveChanges();
            }

            #endregion

            #region India - Maharashtra - cities

            var indiaMahrashtra = context.States.FirstOrDefault(c => c.Name == "Maharashtra");
            foreach (var cityName in _indiaMaharashtraCities)
            {
                var city = new City {
                    Name = cityName, StateId = indiaMahrashtra.Id
                };
                context.Cities.AddOrUpdate(c => c.Name, city);
                context.SaveChanges();
            }

            #endregion

            #region Clients

            var activeClient = new Client();
            activeClient.Id                   = "AngularWebApp";
            activeClient.AllowedOrigin        = "*"; // TODO: replace with the actual client url.
            activeClient.ClientType           = ClientType.JavaScript;
            activeClient.IsActive             = true;
            activeClient.Name                 = "Website";
            activeClient.RefreshTokenLifeTime = 365 * 24 * 60;                                             // 1 year
            activeClient.Secret               = Encryptor.GetHash("11902180-A110-4DE1-808E-1729E5FF9A5C"); // Ideally this must not be hard coded but generated at client side, while adding new client

            // For integration tests only
            var inactiveClient = new Client();
            inactiveClient.Id                   = "Tests-InactiveWebApp";
            inactiveClient.AllowedOrigin        = "*";
            inactiveClient.ClientType           = ClientType.JavaScript;
            inactiveClient.IsActive             = false;
            inactiveClient.Name                 = " Website inactive";
            inactiveClient.RefreshTokenLifeTime = 365 * 24 * 60; // 1 year
            inactiveClient.Secret               = Encryptor.GetHash("DB7DDCC5-BDBD-4F39-88D5-6CC1D58AD792");

            var nativeActiveClient = new Client();
            nativeActiveClient.Id                   = "AndroidApp";
            nativeActiveClient.AllowedOrigin        = "*";
            nativeActiveClient.ClientType           = ClientType.NativeConfidential;
            nativeActiveClient.IsActive             = true;
            nativeActiveClient.Name                 = "Android App";
            nativeActiveClient.RefreshTokenLifeTime = 180 * 24 * 60; //  6 months
            nativeActiveClient.Secret               = Encryptor.GetHash(Guid.NewGuid().ToString());

            context.Clients.AddOrUpdate(c => c.Id, activeClient);
            context.Clients.AddOrUpdate(c => c.Id, inactiveClient);
            context.Clients.AddOrUpdate(c => c.Id, nativeActiveClient);

            context.SaveChanges();

            #endregion
        }