Exemplo n.º 1
0
        public void TestRepositoryInMemoryDirectAccess()
        {
            var queryRepository = new RepositoryInMemory<Query>();
            var newQuery = new Query()
                               {
                                   DbType = EnumDatabase.Oracle,
                                   Description = "Qurey to fetch all planning changes",
                                   Name = "Planning Change",
                                   Text = "SELECT Id FROM DUAL"
                               };

            var newQuery2 = new Query()
            {
                DbType = EnumDatabase.Oracle,
                Description = "Qurey to fetch all rail req changes",
                Name = "Rail Reqs",
                Text = "SELECT Id FROM DUAL"
            };

            var q1 = queryRepository.Save(newQuery);
            var q2 = queryRepository.Save(newQuery2);

            Assert.IsNotNull(q1);
            Assert.AreNotEqual(0, q1.Id);
            Console.WriteLine("Query Id (1) " + q1.Id);

            Assert.IsNotNull(q2);
            Assert.AreNotEqual(q1.Id, q2.Id);

            Console.WriteLine("Query Id (2) " + q2.Id);
        }
Exemplo n.º 2
0
        public void CanRetrieveLookUp()
        {
            var repo   = new RepositoryInMemory <ConfigItem>();
            var config = new ConfigSourceDb("stockapp", "dev.config", repo, false);

            config["app", "name"]         = "my app name";
            config["app", "pagesize"]     = 10;
            config["app", "enableEmails"] = false;
            config["app", "businessdate"] = DateTime.Today.Date;
            config["app", "maxAmount"]    = 20.5;

            config.Save();

            // Load from the repo/datasource.
            var lookup = repo.ToLookUpMulti <string>("Key");

            Assert.AreEqual("my app name", lookup["name"].Val);
            Assert.AreEqual("10", lookup["pagesize"].Val);
            Assert.AreEqual("False", lookup["enableEmails"].Val);
            // (20.5).ToString() allows for different locales.
            Assert.AreEqual((20.5).ToString(), lookup["maxAmount"].Val);
            Assert.AreEqual(DateTime.Today.Date.ToString(), lookup["businessdate"].Val);
        }
Exemplo n.º 3
0
        public void CanSaveToRepo()
        {
            var repo   = new RepositoryInMemory <ConfigItem>();
            var config = new ConfigSourceDb("stockapp", "dev.config", repo, false);

            config["app", "name"]         = "my app name";
            config["app", "pagesize"]     = 10;
            config["app", "enableEmails"] = false;
            config["app", "businessdate"] = DateTime.Today.Date;
            config["app", "maxAmount"]    = 20.5;

            config.Save();

            var config2 = new ConfigSourceDb("stockapp", "dev.config", repo, true);

            // Load from the repo/datasource.
            Assert.AreEqual(config2.Name, "dev.config");
            Assert.AreEqual("my app name", config2["app", "name"]);
            Assert.AreEqual(10, config2["app", "pagesize"]);
            Assert.AreEqual(false, config2["app", "enableEmails"]);
            Assert.AreEqual(20.5, config2["app", "maxAmount"]);
            Assert.AreEqual(DateTime.Today.Date, config2["app", "businessdate"]);
        }
Exemplo n.º 4
0
        public void CanNotDeleteOthersEntryWithoutSettings()
        {
            var repo = new RepositoryInMemory <Blog>();

            Blog.Init(() => repo, new EntitySettings <Blog>()
            {
                EnableAuthentication = true
            }, false);
            Auth.Init(new AuthWin("admin", new UserPrincipal(1, "kishore", "normaluser", "windows", true)));

            var blog = new Blog();

            blog.Title       = "title";
            blog.Description = "description";
            blog.Content     = "content";
            blog.Save();

            Auth.Init(new AuthWin("admin", new UserPrincipal(1, "john", "normaluser", "windows", true)));
            Blog.Delete(blog.Id);
            var blog2 = Blog.Get(blog.Id);

            Assert.IsNotNull(blog2);
        }
Exemplo n.º 5
0
        public LocationServiceTests()
        {
            IRepository <City>    cityRepo        = new RepositoryInMemory <City>("Id,Name,StateId,CountryId");
            IRepository <State>   stateRepo       = new RepositoryInMemory <State>("Id,Name,StateId,CountryId");
            IRepository <Country> countryRepo     = new RepositoryInMemory <Country>("Id,Name,StateId,CountryId");
            ILocationService      locationService = new LocationService(() => countryRepo, () => stateRepo, () => cityRepo);

            Location.Init(locationService);


            CountryId_Italy = Location.CreateCountry("Italy").Item.Id;
            CountryId_USA   = Location.CreateCountry("United States").Item.Id;
            Location.CreateCountry("Spain");
            Location.CreateCountry("India");
            Location.CreateCountry("United States", "USA", true);
            Location.CreateCountry("United States", "America", true);
            Location.CreateCountry("United States", "U.S.A", true);
            IList <Country> countries = Location.Countries.GetAll();

            StateId_NY          = Location.CreateState("New York", "NY", "USA").Item.Id;
            StateId_NJ          = Location.CreateState("New Jersey", "NJ", "USA").Item.Id;
            StateId_CT          = Location.CreateState("Connecticut", "CT", "USA").Item.Id;
            StateId_ItalyState1 = Location.CreateState("ItalianState1", "IT1", "Italy").Item.Id;
            Location.CreateState("Florida", "FL", "USA");
            Location.CreateState("California", "CA", "USA");
            IList <State> states = Location.States.GetAll();

            Location.CreateCity("New York", "New York", "USA");
            Location.CreateCity("Brooklyn", "New York", "USA");
            Location.CreateCity("Bronx", "Connecticut", "USA");
            Location.CreateCity("Bronx", "New York", "USA");
            Location.CreateCity("San Francisco", "California", "USA");
            Location.CreateCity("Trenton", "New Jersey", "USA");
            Location.CreateCity("Miami", "Florida", "USA");
            Location.CreateCity("Venice", "ItalianState1", "Italy");
            IList <City> cities = Location.Cities.GetAll();
        }
        /// <summary>
        /// Run the application.
        /// </summary>
        public override BoolMessageItem Execute()
        {
            // Create In-Memory repository.
            IRepository <Product> repo = new RepositoryInMemory <Product>("Id,Name,Model,IsInStock,Cost");
            var products = GetSampleProducts();

            products.ForEach(p => repo.Create(p));

            // NOTE: I will not show the Sum, Min, Max, Distinct methods here, please refer to base class
            //       example Example_Repository1_Queryable.
            Product product = new Product("Porsche", "boxster", 10, true);

            // 1. Create
            repo.Create(product);

            // 2. Get
            product = repo.Get(product.Id);

            // 3. Update
            product.Name = "Ford2";
            repo.Update(product);

            // 4. Delete
            repo.Delete(product.Id);

            // 5. Get all
            IList <Product> all = repo.GetAll();

            // 6. Get first using filter.
            Product prod = repo.First("name = 'Honda'");

            // 7. Get by page using sql
            PagedList <Product> page = repo.Find("cost = 20", 1, 3);

            // 8. Get by page using criteria.
            var criteria1 = Query <Product> .New().Where("cost").Is(20);

            PagedList <Product> page2 = repo.Find(criteria1, 1, 3);

            // 9. Delete using criteria.
            var criteria2 = Query <Product> .New().Where(p => p.Name).Is("Skateboard");

            repo.Delete(criteria2);

            // 10. Aggregate using column name, expression, and filter.
            var t = repo.Count(Query <Product> .New().Where(p => p.Name).Null());

            // GROUPING
            var groups1 = repo.Group <int>(e => e.Cost);

            // DISTINCT
            var names = repo.Distinct <string>(e => e.Name);

            // MIN, MAX, AVG, SUM using the Entity properties.
            double min = repo.Min(e => e.Cost);
            double max = repo.Max(e => e.Cost);
            double sum = repo.Sum(e => e.Cost);
            double avg = repo.Avg(e => e.Cost);

            return(BoolMessageItem.True);
        }
Exemplo n.º 7
0
 public void SetUp()
 {
     _context            = new MemoryContext();
     _servicioRepository = new RepositoryInMemoryFactory <Servicio>(_context).Instance;
 }
Exemplo n.º 8
0
        private void ConfigureRepositoriesInMemory(UserSettings userSettings, IDictionary<string, object> ctx)
        {
            // Log and Config need to be passed back to caller.
            var logrepo = new RepositoryInMemory<LogEventEntity>("Id,CreateDate,UserName,LogLevel") { TableName = "logs" };
            var configRepo = new RepositoryInMemory<ConfigItem>() { TableName = "configs" };
            var userRepo = new RepositoryInMemory<User>();
            ctx["logRepo"] = logrepo;
            ctx["configRepo"] = configRepo;

            LogEventEntity.Init(new EntityService<LogEventEntity>(logrepo, null, new EntitySettings<LogEventEntity>()));
            ConfigItem.Init(() => configRepo, true);            
            ComLib.Account.User.Init(() => new UserService(), () => userRepo, () => new UserValidator(), userSettings, true, null);
            WidgetInstance.Init(new RepositoryInMemory<WidgetInstance>() { OnRowsMappedCallBack = new Action<IList<WidgetInstance>>(WidgetHelper.ReloadState) }, true);
            Widget.Init(new RepositoryInMemory<Widget>(), true);
            MediaFolder.Init(new RepositoryInMemory<MediaFolder>(), true);
            MediaFile.Init(new RepositoryInMemory<MediaFile>(), true);
            Feedback.Init(new RepositoryInMemory<Feedback>(), true);
            Favorite.Init(new RepositoryInMemory<Favorite>(), true);
            OptionDef.Init(new RepositoryInMemory<OptionDef>(), true);
            Resource.Init(new RepositoryInMemory<Resource>(), true);
            MenuEntry.Init(new RepositoryInMemory<MenuEntry>(), true);
            Profile.Init(new RepositoryInMemory<Profile>(), true);
            Category.Init(new RepositoryInMemory<Category>(), true);
            Comment.Init(new RepositoryInMemory<Comment>(), true);
            Theme.Init(new RepositoryInMemory<Theme>(), true);
            Link.Init(new RepositoryInMemory<Link>(), true);
            Event.Init(new RepositoryInMemory<Event>("Id,CreateUser,Title,StartDate") { OnRowsMappedCallBack = (events) => EventHelper.ApplyCategories(events) }, true);
            Post.Init(new RepositoryInMemory<Post>() { OnRowsMappedCallBack = (posts) => PostHelper.ApplyCategories(posts) }, true);
            Page.Init(new RepositoryInMemory<Page>(), true);
            Part.Init(new RepositoryInMemory<Part>(), true);
            Flag.Init(new RepositoryInMemory<Flag>(), true);
            Tag.Init(new RepositoryInMemory<Tag>(), true);
            EntityRegistration.Register<Country>(new LocationEntityService<Country>(new RepositoryInMemory<Country>()), true);
            EntityRegistration.Register<State>(new LocationEntityService<State>(new RepositoryInMemory<State>()), true);
            EntityRegistration.Register<City>(new LocationEntityService<City>(new RepositoryInMemory<City>()), true);
        }
 public void SetUp()
 {
     _context            = new MemoryContext();
     _repositoryServicio = new RepositoryInMemory <Servicio>(_context);
     _repositoryVehiculo = new RepositoryInMemory <Vehiculo>(_context);
 }
Exemplo n.º 10
0
        /// <summary>
        /// Run the application.
        /// </summary>
        public override BoolMessageItem Execute()
        {
            // First create some test data for the queries.
            IRepository <Product> repoCrud = new RepositoryInMemory <Product>();
            var products = GetSampleProducts();

            products.ForEach(p => repoCrud.Create(p));

            // NOTES:
            // 1. The Repository<T>'s base class is RepositoryQueryable.
            // 2. We are only using a IRepository<T> here initially for adding in-memory test data.
            // 3. But this could be initialized via new RepositoryQuerable(...) constructors against a real Database.
            // 4. Notice that IRepositoryQueryable does not know anything about the entity(Product).
            IRepositoryQueryable repo = (IRepositoryQueryable)repoCrud;

            // 0. Named filters first, to show their example in each section min, max, group, etc.
            repo.AddNamedFilter("InStock Filter", Query <object> .New().Where("IsInStock").Is(true));
            repo.AddNamedFilter("Expensive", Query <object> .New().Where("Cost").MoreThan(20));

            // 1. GROUPING
            var groups  = repo.Group <int>("Cost");
            var groups2 = repo.Group <int>("Cost", Query <object> .New().Where("Make").Not("Honda"));
            var groups3 = repo.Group <int>("Cost", "Expensive"); // same as groups2.

            // 2. DISTINCT
            var names  = repo.Distinct <string>("Make");
            var names2 = repo.Distinct <string>("Make", Query <object> .New().Where("Cost").MoreThan(30).OrderByDescending("Make"));
            var names3 = repo.Distinct <string>("Make", "Expensive");

            // 3. COUNT
            var count1 = repo.Count();
            var count2 = repo.Count(Query <object> .New().Where("IsInStock").Is(true));
            var count3 = repo.Count("InStock Filter");

            // 4. MIN, MAX, AVG, SUM
            int    count = repo.Count();
            double min   = repo.Min("Cost");
            double min2  = repo.Min("Cost", Query <object> .New().Where("Make").In <string>("Bmw", "Lexus"));
            double min3  = repo.Min("Cost", "InStock Filter");

            double max  = repo.Max("Cost");
            double max2 = repo.Max("Cost", Query <object> .New().Where("Make").NotIn <string>("Bmw", "Lexus"));
            double max3 = repo.Max("Cost", "InStock Filter");

            double sum  = repo.Sum("Cost");
            double sum2 = repo.Sum("Cost", Query <object> .New().Where("Make").In <string>("Honda", "Toyota").And("IsInStock").Is(true));
            double sum3 = repo.Sum("Cost", "InStock Filter");

            double avg  = repo.Avg("Cost");
            double avg2 = repo.Avg("Cost", Query <object> .New().Where("Make").Like("Nissan"));
            double avg3 = repo.Avg("Cost", "InStock Filter");

            // 5. To Table
            DataTable all  = repo.ToTable();
            DataTable all2 = repo.ToTable(Query <object> .New().Where("Make").Is("Honda"));
            DataTable all3 = repo.ToTable("InStock Filter");

            // 6. Exists
            bool any1 = repo.Any(Query <object> .New().Where("IsInStock").Is(true));
            bool any2 = repo.Any("InStock Filter");

            // 7. Limit number of records.
            repo.ToTable(Query <object> .New().Limit(2));
            var table1 = repo.ToTable(Query <object> .New().Select("Make", "Model").Where("Cost").MoreThan(30).Limit(2));

            return(BoolMessageItem.True);
        }
Exemplo n.º 11
0
        public void Setup()
        {
            var repo = new RepositoryInMemory <Blog>();

            Blog.Init(() => repo, false);
        }