public void FirstTest()
        {
            var repository = new MongoRepository<ClassTest>(Configuration.TestCollection);

            var count = repository.Count();

            Assert.AreEqual(0, count);
        }
        public void TestCountOne()
        {
            var repository = new MongoRepository<ClassTest>(Configuration.TestCollection);
            repository.Add(new ClassTest());

            var count = repository.Count();

            Assert.AreEqual(1, count);
        }
예제 #3
0
        public void CustomIDTypeTest()
        {
            var xint = new MongoRepository <IntCustomer, int>();

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

            var yint = xint.GetById(2);

            Assert.AreEqual(yint.Name, "Test B");

            xint.Delete(2);
            Assert.AreEqual(1, xint.Count());
        }
예제 #4
0
        public void Discussion572382()
        {
            var repo = new MongoRepository <ClassA>()
            {
                new ClassB()
                {
                    Prop1 = "A", Prop2 = "B"
                },
                new ClassC()
                {
                    Prop1 = "A", Prop3 = "C"
                }
            };

            Assert.AreEqual(2, repo.Count());

            Assert.AreEqual(2, repo.OfType <ClassA>().Count());
            Assert.AreEqual(1, repo.OfType <ClassB>().Count());
            Assert.AreEqual(1, repo.OfType <ClassC>().Count());
        }
        public void TestCountOne()
        {
            var repository = new MongoRepository<ClassTest>(Configuration.TestCollection);

            var classTest = new ClassTest()
                {
                    IntProperty = 10,
                    ChildClassTests = new List<ChildClassTest>()
                        {
                            new ChildClassTest() {StringProperty = "first string"},
                            new ChildClassTest() {StringProperty = "second string"}
                        }
                };

            repository.Add(classTest);

            var count = repository.Count();

            Assert.AreEqual(1, count);
        }
예제 #6
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();
        }
예제 #7
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();
        }
        public async Task CustomerMasterRepositoryTest001_CreateFindDeleteAsync_ExpectNoExceptions()
        {
            // Test cases for async API

            await repo.DeleteAllAsync();

            Assert.Equal(0, repo.Count());

            // Add an entity
            Customer entity = new Customer("CustomerMasterRepositoryTest001_cname", "1-800-start");
            await repo.AddAsync(entity);

            this.testLogger.LogDebug($"New entity: {entity.ToJson()}");

            // Count should increase by 1
            Assert.Equal(1, await repo.CountAsync());

            // Test get by id
            var fetch = await repo.GetByEntityIdAsync(entity.entityid);

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

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

            Assert.Equal(1, searchresult.Count);

            // Test Update API
            entity.phone = "1-800-updated";
            await repo.UpdateAsync(entity);

            Assert.Equal(1, (await repo.GetAsync(e => e.phone == "1-800-updated")).Count);

            await repo.DeleteAsync(entity.entityid);

            await Assert.ThrowsAsync <Exception>(async() => fetch = await repo.GetByEntityIdAsync(entity.entityid));
        }
        public void BatchTest()
        {
            IRepository<Customer> _customerRepo = 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
            _customerRepo.Add(custlist);

            var count = _customerRepo.Count();
            Assert.AreEqual(7, count);
            foreach (Customer c in custlist)
                Assert.AreNotEqual(new string('0', 24), c.Id);

            //Update batch
            foreach (Customer c in custlist)
                c.LastName = c.FirstName;
            _customerRepo.Update(custlist);

            foreach (Customer c in _customerRepo)
                Assert.AreEqual(c.FirstName, c.LastName);

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

            count = _customerRepo.Count();
            Assert.AreEqual(4, count);

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

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

            Assert.AreEqual(2, selectedcustomers.ToList().Count);

            count = _customerRepo.Count();
            Assert.AreEqual(3, count);

            //Drop entire repo
            new MongoRepositoryManager<Customer>().Drop();

            count = _customerRepo.Count();
            Assert.AreEqual(0, count);
        }
        public void CustomIDTypeTest()
        {
            var xint = new MongoRepository<IntCustomer, int>();
            xint.Add(new IntCustomer() { Id = 1, Name = "Test A" });
            xint.Add(new IntCustomer() { Id = 2, Name = "Test B" });

            var yint = xint.GetById(2);
            Assert.AreEqual(yint.Name, "Test B");

            xint.Delete(2);
            Assert.AreEqual(1, xint.Count());
        }
        public void CustomIDTest()
        {
            var x = new MongoRepository<CustomIDEntity>();
            var xm = new MongoRepositoryManager<CustomIDEntity>();

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

            Assert.IsTrue(xm.Exists);
            Assert.IsInstanceOfType(x.GetById("aaa"), typeof(CustomIDEntity));

            Assert.AreEqual("aaa", x.GetById("aaa").Id);

            x.Delete("aaa");
            Assert.AreEqual(0, x.Count());

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

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

            Assert.IsTrue(ym.Exists);
            Assert.AreEqual(ym.Name, "MyTestCollection");
            Assert.AreEqual(y.CollectionName, "MyTestCollection");
            Assert.IsInstanceOfType(y.GetById("xyz"), typeof(CustomIDEntityCustomCollection));

            y.Delete("xyz");
            Assert.AreEqual(0, y.Count());
        }
        public void BatchTest()
        {
            IRepository <Customer> _customerRepo = 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
            _customerRepo.Add(custlist);

            var count = _customerRepo.Count();

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

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

            foreach (Customer c in _customerRepo)
            {
                Assert.AreEqual(c.FirstName, c.LastName);
            }

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

            count = _customerRepo.Count();
            Assert.AreEqual(4, count);

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

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

            Assert.AreEqual(2, selectedcustomers.ToList().Count);

            count = _customerRepo.Count();
            Assert.AreEqual(3, count);

            //Drop entire repo
            new MongoRepositoryManager <Customer>().Drop();

            count = _customerRepo.Count();
            Assert.AreEqual(0, count);
        }
예제 #13
0
 public int GetIncomeRecordCount()
 {
     return(mRepo.Count(x => x.MoneyType == "income"));
 }
예제 #14
0
 /// <summary>
 /// get the count of actived user
 /// </summary>
 /// <returns></returns>
 public int GetAllActiveUserCount()
 {
     return(repo.Count(x => x.UserState == 1));
 }
예제 #15
0
        public void Discussion572382()
        {
            var repo = new MongoRepository<ClassA>() { 
                new ClassB() { Prop1 = "A", Prop2 = "B" } ,
                new ClassC() { Prop1 = "A", Prop3 = "C" }
            };

            Assert.AreEqual(2, repo.Count());

            Assert.AreEqual(2, repo.OfType<ClassA>().Count());
            Assert.AreEqual(1, repo.OfType<ClassB>().Count());
            Assert.AreEqual(1, repo.OfType<ClassC>().Count());
        }
        private static void recordExplore <T>() where T : IGUIDable
        {
            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 <T> repository   = new MongoRepository <T>(dbConnection);

                Console.WriteLine($"Exploring {typeof(T).Name} objects");
                long objCount = repository.Count();
                Console.WriteLine($"Total count: {objCount}");

                Console.Write("Dump to console [yN]?");
                if (Console.ReadLine().ToLower() == "y")
                {
                    foreach (T obj in repository.GetAll())
                    {
                        Console.WriteLine(System.Text.Json.JsonSerializer.Serialize <T>(obj, new JsonSerializerOptions()
                        {
                            WriteIndented = true
                        }));
                    }

                    Console.WriteLine("\n\nPress any key to continue...");
                    Console.ReadKey();
                }

                Console.Write("Dump to json files? [yN]?");
                if (Console.ReadLine().ToLower() == "y")
                {
                    Console.WriteLine("Name of new directory where json files will be stored (if exists it will be deleted)");
                    Console.Write($"Directory name: [{typeof(T).Name}]: ");
                    string dirname = Console.ReadLine();
                    if (string.IsNullOrEmpty(dirname))
                    {
                        dirname = typeof(T).Name;
                    }
                    Console.WriteLine($"Creating folder {dirname}");

                    if (Directory.Exists(dirname))
                    {
                        Directory.Delete(dirname, true);
                    }

                    if (!Directory.Exists(dirname))
                    {
                        Directory.CreateDirectory(dirname);
                    }

                    Console.WriteLine("Dumping objects...");

                    foreach (T obj in repository.GetAll())
                    {
                        using (StreamWriter fileStream = File.CreateText(Path.Combine(dirname, $"{obj.Id}.json")))
                        {
                            Newtonsoft.Json.JsonSerializer serializer = new Newtonsoft.Json.JsonSerializer();
                            serializer.Formatting = Formatting.Indented;
                            serializer.Serialize(fileStream, obj, typeof(T));
                        }
                    }

                    Console.WriteLine("Done!");

                    Console.WriteLine("\n\nPress any key to go back to main menu...");
                    Console.ReadKey();
                }
            }
        }
예제 #17
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);
        }