public void CustomerMasterRepositoryTest002_CreateFindDeleteSync_ExpectNoExceptions()
        {
            if (repo.Count() > 0)
            {
                repo.DeleteAll();
            }

            Customer entity = new Customer("CustomerMasterRepositoryTest002_cname", "1-800-start");

            repo.Add(entity);

            long newCount = repo.Count();

            Assert.Equal(1, newCount);

            var fetch = repo.GetByEntityId(entity.entityid);

            Assert.NotNull(fetch);
            // Assert.Equal(fetch,entity);

            // Test search API
            var searchresult = repo.Get(e => e.phone == "1-800-start");

            Assert.Equal(1, searchresult.Count);

            // Test Update API
            entity.phone = "1-800-updated";
            repo.Update(entity);
            Assert.Equal(1, (repo.Get(e => e.phone == "1-800-updated")).Count);

            repo.Delete(entity.entityid);

            Assert.Throws <Exception>(() => fetch = repo.GetByEntityId(entity.entityid));
        }
Esempio n. 2
0
        public void CanDeleteAllDocuments()
        {
            var customerRepository = new MongoRepository <Customer>();

            customerRepository.Add(this.TestCustomers);

            customerRepository.DeleteAll();
            customerRepository.Count().ShouldBe(0);
        }
Esempio n. 3
0
        public void AddAndUpdateTest()
        {
            var customerRepository = new MongoRepository <Customer>();
            var customerManager    = new MongoRepositoryManager <Customer>();

            //_customerManager.Exists.ShouldBeFalse();

            var customer = new Customer();

            customer.FirstName   = "Bob";
            customer.LastName    = "Dillon";
            customer.Phone       = "0900999899";
            customer.Email       = new CustomerEmail("*****@*****.**");
            customer.HomeAddress = new Address
            {
                Address1 = "North kingdom 15 west",
                Address2 = "1 north way",
                City     = "George Town",
                Country  = "Alaska",
                PostCode = "40990"
            };

            customerRepository.Add(customer);

            customerManager.Exists.ShouldBeTrue();
            customer.Id.ShouldNotBeNullOrWhiteSpace();

            // fetch it back
            var alreadyAddedCustomer = customerRepository.Where(c => c.FirstName == "Bob").Single();

            alreadyAddedCustomer.ShouldNotBeNull();
            customer.FirstName.ShouldBe(alreadyAddedCustomer.FirstName);
            customer.HomeAddress.Address1.ShouldBe(alreadyAddedCustomer.HomeAddress.Address1);

            alreadyAddedCustomer.Phone = "10110111";
            alreadyAddedCustomer.Email = new CustomerEmail("*****@*****.**");

            customerRepository.Update(alreadyAddedCustomer);

            // fetch by id now
            var updatedCustomer = customerRepository.GetById(customer.Id);

            updatedCustomer.ShouldNotBeNull();
            alreadyAddedCustomer.Phone.ShouldBe(updatedCustomer.Phone);
            alreadyAddedCustomer.Email.Value.ShouldBe(updatedCustomer.Email.Value);
            customerRepository.Exists(c => c.HomeAddress.Country == "Alaska").ShouldBeTrue();

            customerRepository.Delete(updatedCustomer);

            var exists = customerRepository.GetById(updatedCustomer.Id);

            exists.ShouldBeNull();

            customerRepository.DeleteAll();
        }
Esempio n. 4
0
        public void CustomIDTest()
        {
            var customIdRepository = new MongoRepository <CustomIDEntity>();
            var customIdManager    = new MongoRepositoryManager <CustomIDEntity>();

            customIdRepository.DeleteAll();

            customIdRepository.Add(new CustomIDEntity()
            {
                Id = "aaa"
            });

            customIdManager.Exists.ShouldBeTrue();
            customIdRepository.GetById("aaa").ShouldBeOfType(typeof(CustomIDEntity));
            customIdRepository.GetById("aaa").Id.ShouldBe("aaa");

            customIdRepository.Delete("aaa");
            customIdRepository.Count().ShouldBe(0);

            var y  = new MongoRepository <CustomIDEntityCustomCollection>();
            var ym = new MongoRepositoryManager <CustomIDEntityCustomCollection>();

            y.DeleteAll();

            y.Add(new CustomIDEntityCustomCollection()
            {
                Id = "xyz"
            });

            ym.Exists.ShouldBeTrue();
            ym.Name.ShouldBe("MyTestCollection");
            y.CollectionName.ShouldBe("MyTestCollection");
            y.GetById("xyz").ShouldBeOfType(typeof(CustomIDEntityCustomCollection));

            y.Delete("xyz");
            y.Count().ShouldBe(0);

            customIdRepository.DeleteAll();
        }
Esempio n. 5
0
        public void CustomIDTypeTest()
        {
            var intRepository = new MongoRepository <IntCustomer, int>();

            intRepository.DeleteAll();

            intRepository.Add(new IntCustomer()
            {
                Id = 1, Name = "Test A"
            });
            intRepository.Add(new IntCustomer()
            {
                Id = 2, Name = "Test B"
            });

            var yint = intRepository.GetById(2);

            yint.Name.ShouldBe("Test B");

            intRepository.Delete(2);
            intRepository.Count().ShouldBe(1);

            intRepository.DeleteAll();
        }
Esempio n. 6
0
        private static void MigrateNetworkVehiclesToMarketRepresentation()
        {
            var networkVehicles = new MongoRepository <NetworkVehicle>();

            if (!networkVehicles.Any())
            {
                // Migration already done
                return;
            }

            var allMarketsDefinedInNetworkSettings = new MongoRepository <TaxiHailNetworkSettings>().Select(x => x.Market).Distinct();
            var allMarketsDefinedInNetworkVehicles = networkVehicles.Select(x => x.Market).Distinct();
            var allMarketsDefined = new List <string>();

            allMarketsDefined.AddRange(allMarketsDefinedInNetworkSettings);
            allMarketsDefined.AddRange(allMarketsDefinedInNetworkVehicles);
            allMarketsDefined = allMarketsDefined.Distinct().ToList();

            var marketRepo = new MongoRepository <Market>();

            foreach (var market in allMarketsDefined)
            {
                var vehiclesForThisMarket = networkVehicles
                                            .Where(x => x.Market == market)
                                            .Select(x => new Vehicle
                {
                    Id                  = x.Id,
                    Name                = x.Name,
                    LogoName            = x.LogoName,
                    MaxNumberPassengers = x.MaxNumberPassengers,
                    NetworkVehicleId    = x.NetworkVehicleId
                })
                                            .ToList();

                var newMarket = new Market
                {
                    Id       = Guid.NewGuid().ToString(),
                    Name     = market,
                    Vehicles = vehiclesForThisMarket
                };

                marketRepo.Add(newMarket);
            }

            networkVehicles.DeleteAll();
            networkVehicles.Collection.Drop();
        }
Esempio n. 7
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);


            MongoRepository.MongoRepository<Basla> repo = new MongoRepository<Basla>();
            repo.DeleteAll();
            Basla b = new Basla();
            FlowAction a = new FlowAction();
            b.SonrakiEleman = a;
            repo.Add(b);

            var txxx = repo.Where(t => t.Id != null).ToList();

        }
Esempio n. 8
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);


            MongoRepository.MongoRepository <Basla> repo = new MongoRepository <Basla>();
            repo.DeleteAll();
            Basla      b = new Basla();
            FlowAction a = new FlowAction();

            b.SonrakiEleman = a;
            repo.Add(b);

            var txxx = repo.Where(t => t.Id != null).ToList();
        }
Esempio n. 9
0
        private static void Main(string[] args)
        {
            repository.DeleteAll();

            var dtCompanies = GetData("Select * from MKConfig.Company", "Company");
            var dtIBS       = GetData("Select * from MKConfig.IBSServer", "IBS");

            foreach (DataRow dr in dtCompanies.Rows)
            {
                if (dr["Name"].ToString() != String.Empty)
                {
                    var company = new Company();
                    foreach (DataRow drIBS in dtIBS.Rows)
                    {
                        if (dr[1].ToString() == drIBS[1].ToString())
                        {
                            company.IBS.ServiceUrl = drIBS["Url"].ToString();
                            company.IBS.Username   = drIBS["Username"].ToString();
                            company.IBS.Password   = drIBS["Password"].ToString();
                        }
                    }

                    company.Id          = dr["Id"].ToString();
                    company.CompanyName = dr["Name"].ToString();

                    var settings       = FromXml(dr["DictionaryAsXml"].ToString());
                    var mobileSettings = FromXml(dr["MobileDictionaryAsXml"].ToString());
//                    foreach (KeyValuePair<string, string> setting in settings)
//                    {
//                        company.Settings.Add(setting.Key, setting.Value);
//                    }
//                    foreach (KeyValuePair<string, string> setting in mobileSettings)
//                    {
//                        if (!company.Settings.ContainsKey(setting.Key))
//                            company.Settings.Add(setting.Key, setting.Value);
//                    }
                    company.CompanyKey = settings["TaxiHail.ServerCompanyName"];
                    repository.Add(company);
                }
            }
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            //Add customers
            var john = new Customer()
            {
                FirstName = "John", LastName = "Doe"
            };
            var jane = new Customer()
            {
                FirstName = "Jane", LastName = "Doe"
            };
            var jerry = new Customer()
            {
                FirstName = "Jerry", LastName = "Maguire"
            };

            customerrepo.Add(new[] { john, jane, jerry });

            //Show contents of DB
            DumpData();

            //Update customers
            john.FirstName = "Johnny";  //John prefers Johnny
            customerrepo.Update(john);

            jane.LastName = "Maguire";  //Jane divorces John and marries Jerry
            customerrepo.Update(jane);

            //Delete customers
            customerrepo.Delete(jerry.Id);  //Jerry passes away

            //Add some products to John and Jane
            john.Products.AddRange(new[] {
                new Product()
                {
                    Name = "Fony DVD Player XY1299", Price = 35.99M
                },
                new Product()
                {
                    Name = "Big Smile Toothpaste", Price = 1.99M
                }
            });
            jane.Products.Add(new Product()
            {
                Name = "Life Insurance", Price = 2500
            });
            customerrepo.Update(john);
            customerrepo.Update(jane);
            //Or, alternatively: customerrepo.Update(new [] { john, jane });

            //Show contents of DB
            DumpData();

            //Finally; demonstrate GetById and First
            var mysterycustomer1 = customerrepo.GetById(john.Id);
            var mysterycustomer2 = customerrepo.First(c => c.FirstName == "Jane");

            Console.WriteLine("Mystery customer 1: {0} (having {1} products)",
                              mysterycustomer1.FirstName, mysterycustomer1.Products.Count);
            Console.WriteLine("Mystery customer 2: {0} (having {1} products)",
                              mysterycustomer2.FirstName, mysterycustomer2.Products.Count);

            //Delete all customers
            customerrepo.DeleteAll();

            //Halt for user
            Console.WriteLine("Press any key...");
            Console.ReadKey();
        }
Esempio n. 11
0
        public void CollectionNamesTest()
        {
            // animal
            var a  = new MongoRepository <Animal>();
            var am = new MongoRepositoryManager <Animal>();

            a.DeleteAll();

            var va = new Dog();

            am.Exists.ShouldBeFalse();
            a.Update(va);
            am.Exists.ShouldBeTrue();
            a.GetById(va.Id).ShouldBeOfType(typeof(Dog));
            am.Name.ShouldBe("AnimalsTest");
            a.CollectionName.ShouldBe("AnimalsTest");

            // cat
            var cl  = new MongoRepository <CatLike>();
            var clm = new MongoRepositoryManager <CatLike>();

            cl.DeleteAll();

            var vcl = new Lion();

            clm.Exists.ShouldBeFalse();
            cl.Update(vcl);
            clm.Exists.ShouldBeTrue();
            cl.GetById(vcl.Id).ShouldBeOfType(typeof(Lion));
            clm.Name.ShouldBe("Catlikes");
            cl.CollectionName.ShouldBe("Catlikes");

            // bird
            var b  = new MongoRepository <Bird>();
            var bm = new MongoRepositoryManager <Bird>();

            b.DeleteAll();

            var vb = new Bird();

            bm.Exists.ShouldBeFalse();
            b.Update(vb);
            bm.Exists.ShouldBeTrue();
            b.GetById(vb.Id).ShouldBeOfType(typeof(Bird));
            bm.Name.ShouldBe("Birds");
            b.CollectionName.ShouldBe("Birds");

            // lion
            var l  = new MongoRepository <Lion>();
            var lm = new MongoRepositoryManager <Lion>();

            l.DeleteAll();

            var vl = new Lion();

            //Assert.IsFalse(lm.Exists);   //Should already exist (created by cl)
            l.Update(vl);
            lm.Exists.ShouldBeTrue();
            l.GetById(vl.Id).ShouldBeOfType(typeof(Lion));
            lm.Name.ShouldBe("Catlikes");
            l.CollectionName.ShouldBe("Catlikes");

            // dog
            var d  = new MongoRepository <Dog>();
            var dm = new MongoRepositoryManager <Dog>();

            d.DeleteAll();

            var vd = new Dog();

            //Assert.IsFalse(dm.Exists);
            d.Update(vd);
            dm.Exists.ShouldBeTrue();
            d.GetById(vd.Id).ShouldBeOfType(typeof(Dog));
            dm.Name.ShouldBe("AnimalsTest");
            d.CollectionName.ShouldBe("AnimalsTest");

            // bird
            var m  = new MongoRepository <Bird>();
            var mm = new MongoRepositoryManager <Bird>();

            m.DeleteAll();

            var vm = new Macaw();

            m.Update(vm);
            mm.Exists.ShouldBeTrue();
            m.GetById(vm.Id).ShouldBeOfType(typeof(Macaw));
            mm.Name.ShouldBe("Birds");
            m.CollectionName.ShouldBe("Birds");

            // whale
            var w  = new MongoRepository <Whale>();
            var wm = new MongoRepositoryManager <Whale>();

            w.DeleteAll();

            var vw = new Whale();

            wm.Exists.ShouldBeFalse();
            w.Update(vw);
            wm.Exists.ShouldBeTrue();
            w.GetById(vw.Id).ShouldBeOfType(typeof(Whale));
            wm.Name.ShouldBe("Whale");
            w.CollectionName.ShouldBe("Whale");

            // cleanup
            am.Drop();
            clm.Drop();
            bm.Drop();
            lm.Drop();
            dm.Drop();
            mm.Drop();
            wm.Drop();
        }
Esempio n. 12
0
        public void BatchTest()
        {
            var customerRepository = new MongoRepository <Customer>();

            var custlist = new List <Customer>(new Customer[] {
                new Customer()
                {
                    FirstName = "Customer A"
                },
                new Customer()
                {
                    FirstName = "Client B"
                },
                new Customer()
                {
                    FirstName = "Customer C"
                },
                new Customer()
                {
                    FirstName = "Client D"
                },
                new Customer()
                {
                    FirstName = "Customer E"
                },
                new Customer()
                {
                    FirstName = "Client F"
                },
                new Customer()
                {
                    FirstName = "Customer G"
                },
            });

            //Insert batch
            customerRepository.Add(custlist);

            var count = customerRepository.Count();

            count.ShouldBe(7);
            foreach (Customer c in custlist)
            {
                c.Id.ShouldNotBe(new string('0', 24));
            }

            //Update batch
            foreach (Customer c in custlist)
            {
                c.LastName = c.FirstName;
            }
            customerRepository.Update(custlist);

            foreach (Customer c in customerRepository)
            {
                c.FirstName.ShouldBe(c.LastName);
            }

            //Delete by criteria
            customerRepository.Delete(f => f.FirstName.StartsWith("Client"));

            count = customerRepository.Count();
            count.ShouldBe(4);

            //Delete specific object
            customerRepository.Delete(custlist[0]);

            //Test AsQueryable
            var selectedcustomers = from cust in customerRepository
                                    where cust.LastName.EndsWith("C") || cust.LastName.EndsWith("G")
                                    select cust;

            selectedcustomers.ToList().Count.ShouldBe(2);

            count = customerRepository.Count();
            count.ShouldBe(3);

            //Drop entire repo
            customerRepository.DeleteAll();
            count = customerRepository.Count();
            count.ShouldBe(0);
        }
Esempio n. 13
0
        public void ComplexEntityTest()
        {
            var customerRepository = new MongoRepository <Customer>();
            var productRepository  = new MongoRepository <Product>();

            var customer = new Customer();

            customer.FirstName   = "Erik";
            customer.LastName    = "Swaun";
            customer.Phone       = "123 99 8767";
            customer.Email       = new CustomerEmail("*****@*****.**");
            customer.HomeAddress = new Address
            {
                Address1 = "Main bulevard",
                Address2 = "1 west way",
                City     = "Tempare",
                Country  = "Arizona",
                PostCode = "89560"
            };

            var order = new Order();

            order.PurchaseDate = DateTime.Now.AddDays(-2);
            var orderItems = new List <OrderItem>();

            var shampoo = productRepository.Add(new Product()
            {
                Name = "Palmolive Shampoo", Price = 5
            });
            var paste = productRepository.Add(new Product()
            {
                Name = "Mcleans Paste", Price = 4
            });


            var item1 = new OrderItem {
                Product = shampoo, Quantity = 1
            };
            var item2 = new OrderItem {
                Product = paste, Quantity = 2
            };

            orderItems.Add(item1);
            orderItems.Add(item2);

            order.Items = orderItems;

            customer.Orders = new List <Order>
            {
                order
            };

            customerRepository.Add(customer);

            customer.Id.ShouldNotBeNull();
            customer.Orders[0].Items[0].Product.Id.ShouldNotBeNullOrWhiteSpace();

            // get the orders
            var theCustomer = customerRepository.Where(c => c.Id == customer.Id).SingleOrDefault();

            var theOrders = customerRepository.Where(c => c.Id == customer.Id).Select(c => c.Orders).ToList();

            theOrders.ShouldNotBeNull();
            theOrders.ShouldNotBeEmpty();

            var theOrderItems = theOrders[0].Select(o => o.Items);

            theOrderItems.ShouldNotBeNull();

            customerRepository.DeleteAll();
            productRepository.DeleteAll();
        }
Esempio n. 14
0
        public RepositoryTests() : base()
        {
            var customerRepository = new MongoRepository <Customer>();

            customerRepository.DeleteAll();
        }
Esempio n. 15
0
 public IActionResult DeleteWords(string categoryhash)
 {
     _repo.DeleteAll(categoryhash);
     return(RedirectToAction("Explore", "Home", categoryhash));
 }
        private static void schoolReimport()
        {
            bool   wipe     = false;
            string filename = string.Empty;

            if (string.IsNullOrEmpty(dbConnectionString))
            {
                Console.WriteLine("> ERROR: You need to specify a connection string first.");
                Thread.Sleep(3000);
            }
            else
            {
                Console.WriteLine("> Connecting to database...");
                MongoDbConnection        dbConnection     = new MongoDbConnection(dbConnectionString);
                MongoRepository <School> schoolRepository = new MongoRepository <School>(dbConnection);

                Console.Write("Enter filename to import (must be a JSON file): ");
                filename = Console.ReadLine();

                if (!string.IsNullOrEmpty(filename))
                {
                    Console.WriteLine($"> Attempting to load {filename}");
                    // Verify that the file exists
                    if (File.Exists(filename))
                    {
                        // Attempt to load the file
                        try
                        {
                            using (StreamReader importFile = new StreamReader(filename))
                            {
                                // Attempt to deserialize the file
                                List <School> importedSchools = new List <School>();
                                importedSchools = System.Text.Json.JsonSerializer.Deserialize <List <School> >(importFile.ReadToEnd());

                                Console.WriteLine($"> Loaded {importedSchools.Count} School objects from file");

                                Console.WriteLine("Dump JSON to console window [yN]?: ");
                                if (Console.ReadLine().ToLower() == "y")
                                {
                                    Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(importedSchools, new JsonSerializerOptions()
                                    {
                                        WriteIndented = true
                                    }));
                                }

                                Console.Write("\nWipe existing school data [Yn]: ");
                                wipe = !(Console.ReadLine().ToLower() == "n");

                                Console.WriteLine("Perform the import [yN]?: ");
                                if (Console.ReadLine().ToLower() == "y")
                                {
                                    Console.WriteLine("> Performing import...");
                                    // Perform the import
                                    if (wipe)
                                    {
                                        Console.WriteLine("> Wiping existing data...");
                                        schoolRepository.DeleteAll();
                                    }

                                    Console.WriteLine("> Importing...");
                                    schoolRepository.Insert(importedSchools);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("> ERROR: " + ex.Message);
                            Console.WriteLine("(Press any key to continue...)");
                            Console.ReadKey();
                        }
                    }
                    else
                    {
                        Console.WriteLine("> ERROR: File not found");
                        Thread.Sleep(3000);
                    }
                }
                else
                {
                    Console.WriteLine("> ERROR: Filename empty");
                    Thread.Sleep(3000);
                }
            }
        }