Exemplo n.º 1
0
        public void TestMethod1()
        {
            var             unitOfWork     = new MongoUnitOfWork();
            var             context        = new MongoRepositoryContext();
            IUserRepository userRepository = new UserRepository(context);

            userRepository.Create(new User()
            {
                UserName      = "******",
                NickName      = "坏坏男孩",
                RealName      = "吴丹",
                PhoneNum      = "18916765826",
                Email         = "*****@*****.**",
                Status        = UserStatus.Enabled,
                PassWord      = "******",
                RegisterTime  = DateTime.Now,
                LastLogonTime = DateTime.Now
            });
            userRepository.Create(new User()
            {
                UserName      = "******",
                NickName      = "坏坏男孩1",
                RealName      = "吴丹1",
                PhoneNum      = "18916765000",
                Email         = "*****@*****.**",
                Status        = UserStatus.Disabled,
                PassWord      = "******",
                RegisterTime  = DateTime.Now,
                LastLogonTime = DateTime.Now
            });

            var result = context.Commit();
            //var result = unitOfWork.Commit();
        }
Exemplo n.º 2
0
 public void CreateUnitOfWorkBsonRepository()
 {
     using (var unitOfWork = new MongoUnitOfWork(new MongoDbContext(new DataContextConfigurationAccessor(_settings), new DefaultCollectionNameSelector(), null)))
     {
         Assert.NotNull(unitOfWork);
     }
 }
Exemplo n.º 3
0
 public void CreateUnitOfWorkSelectBson()
 {
     using (var unitOfWork = new MongoUnitOfWork(new MongoDbContext(new DataContextConfigurationAccessor(_settings), new DefaultCollectionNameSelector(), null)))
     {
         var logs = unitOfWork.Repository <DefterLog>().ToList();
         Assert.True(logs.Count > 0);
     }
 }
Exemplo n.º 4
0
        public async Task StartTransactionAsync_should_return_MongoTransaction_if_transactions_supported()
        {
            var session = NSubstitute.Substitute.For <IClientSessionHandle>();
            var client  = NSubstitute.Substitute.For <IMongoClient>();

            client.StartSession()
            .ReturnsForAnyArgs(session);

            var logger = NSubstitute.Substitute.For <ILogger <MongoUnitOfWork> >();
            var sut    = new MongoUnitOfWork(client, logger);

            var result = await sut.StartTransactionAsync();

            result.Should().BeOfType <MongoTransaction>();
        }
Exemplo n.º 5
0
        public async Task StartTransactionAsync_should_return_NullTransaction_if_transactions_not_supported()
        {
            var session = NSubstitute.Substitute.For <IClientSessionHandle>();

            session.When(s => s.StartTransaction(Arg.Any <TransactionOptions>()))
            .Throw <NotSupportedException>();
            var client = NSubstitute.Substitute.For <IMongoClient>();

            client.StartSession()
            .ReturnsForAnyArgs(session);

            var logger = NSubstitute.Substitute.For <ILogger <MongoUnitOfWork> >();
            var sut    = new MongoUnitOfWork(client, logger);

            var result = await sut.StartTransactionAsync();

            result.Should().BeOfType <NullTransaction>();
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            IUnitOfWork _unitOfWork = new MongoUnitOfWork();
            //var _tagService = new TagService(_unitOfWork);
            var _quesService = new QuestionService(_unitOfWork);
            // var tag = new Tag("Java");
            //_tagService.SaveAsync(tag).Wait();
            // Console.WriteLine(tag.ToString());
            // Console.WriteLine("Hello Naveen World!");
            //Console.ReadKey();
            //Func<string> f = ()=> {return "Heelo";};
            // Expression<Func<Question, List<Answer>>> action = (x)=>x.Answers;

            // Console.WriteLine(GetFiledName(action));

            // var ntag1 = new Tag("Question tag Test 1");
            // //tag.Id = "5977844c30656d5f7b1b1364";
            // var tag =  _tagService.SaveAsync(ntag1).Result;

            //Question ques = new Question();
            //ques.Value = "What is ur C#?";
            // ques.TagIds.Add(tag.Id);

            //_quesService.SaveAsync(ques).Wait();
            //var newQuestion =  _quesService.FindOneAsync(x => x.Value == "What is ur C#?").Result;
            //9EEA4136-0E14-F241-86AC-DED566A24293
            var ans = new Answer();

            ans.Value = "Ans 1";
            _quesService.AddAnswer("5984c325d699ce20c1605a50", ans).Wait();
            // var ntag2 = new Tag("Question tag Test 2");
            // var tag2 =   _tagService.SaveAsync(ntag2).Result;

            //newQuestion.TagIds.Add(tag2.Id);
            //_quesService.UpdateAsync(newQuestion);

            //var newQuestion2 =  await _quesService.FindOneAsync(x => x.Value == "What is ur C#?");

            //var newQues =  _quesService.A

            Console.WriteLine("Added");
        }
Exemplo n.º 7
0
        public void GetDefterLogAndParse()
        {
            using (var unitOfWork = new MongoUnitOfWork(new MongoDbContext(new DataContextConfigurationAccessor(_settings), new DefaultCollectionNameSelector(), null)))
            {
                var log = unitOfWork.Repository <DefterLog>().FirstOrDefault();
                if (log == null)
                {
                    return;
                }

                string requestContent  = Encoding.UTF8.GetString(Convert.FromBase64String(log.RequestContent));
                string responseContent = Encoding.UTF8.GetString(Convert.FromBase64String(log.ResponseContent));

                XmlDocument requetXml   = new XmlDocument();
                XmlDocument responseXml = new XmlDocument();

                requetXml.LoadXml(requestContent);
                responseXml.LoadXml(responseContent);

                Assert.True(true);
            }
        }