Exemple #1
0
        /// <summary>
        /// Sample Add method
        /// </summary>
        /// <param name="dto1">Object 1</param>
        /// <param name="dto2">Object 2</param>
        /// <returns></returns>
        public Task AddAsync(Dto1 dto1, Dto2 dto2)
        {
            _entity1Repository.Add(new Entity1
            {
                Id    = Guid.NewGuid().ToString(),
                Prop1 = dto1.Prop1,
                Prop2 = dto1.Prop2
            });

            _entity2Repository.Add(new Entity2
            {
                Id    = Guid.NewGuid().ToString(),
                Prop1 = dto2.Prop1,
                Prop2 = dto2.Prop2
            });

            return(_repositoryContext.CommitAsync());
        }
Exemple #2
0
        public async Task MongoDBRepositoryTests_InsertDocumentAsync()
        {
            List <Customer> customers = new List <Customer>();

            for (int i = 0; i < 100; i++)
            {
                customers.Add(new Customer
                {
                    FirstName = "sunny" + i.ToString(),
                    LastName  = "chen" + i.ToString(),
                    Birth     = DateTime.Now.AddDays(-i),
                    Email     = "sunnychen" + i.ToString() + "@163.com",
                    Password  = i.ToString(),
                    Sequence  = i,
                    ID        = Guid.NewGuid(),
                    Username  = "******" + i.ToString()
                });
            }
            IRepositoryContext     context            = ServiceLocator.Instance.GetService <IRepositoryContext>();
            IRepository <Customer> customerRepository = ServiceLocator.Instance.GetService <IRepository <Customer> >(new { context = context });

            foreach (var customer in customers)
            {
                customerRepository.Add(customer);
            }
            await context.CommitAsync();

            MongoClient client = new MongoClient(Helper.MongoDB_ConnectionString);
            //MongoServer server = MongoServer.Create(Helper.MongoDB_ConnectionString);
            //MongoServer server = client.GetServer();
            var database   = client.GetDatabase(Helper.MongoDB_Database);
            var collection = database.GetCollection <Customer>("Customer");
            var count      = await collection.CountAsync(c => true);

            Assert.AreEqual(100, count);
        }