コード例 #1
0
        public async Task NullExpressionOnReplaceTest()
        {
            MongodbConfig  mongodbConfig = MongoDbHelper.GetMongodbConfig();
            IMongoDatabase database      = MongodbProvider.GetDatabase(mongodbConfig);
            IMongodbSaveRepository <Test> saveRepository = new MongodbSaveRepository <Test>(database);

            await Assert.ThrowsAsync <ArgumentNullException>(() => saveRepository.ReplaceAsync(null, new Test()));
        }
コード例 #2
0
        public async Task NothingToReplaceTest()
        {
            MongodbConfig  mongodbConfig = MongoDbHelper.GetMongodbConfig();
            IMongoDatabase database      = MongodbProvider.GetDatabase(mongodbConfig);
            IMongodbSaveRepository <Test> saveRepository = new MongodbSaveRepository <Test>(database);

            await Assert.ThrowsAsync <ReplaceException>(() => saveRepository.ReplaceAsync(x => x.ObjectId == "non-existent-object", new Test()
            {
                StringField = "nothing-to-replace-test"
            }));
        }
コード例 #3
0
        public async Task SingleEntityIntegralTest()
        {
            MongodbConfig  mongodbConfig = MongoDbHelper.GetMongodbConfig();
            IMongoDatabase database      = MongodbProvider.GetDatabase(mongodbConfig);
            IMongodbSaveRepository <Test> saveRepository   = new MongodbSaveRepository <Test>(database);
            IGetRepository <Test>         getRepository    = new MongodbGetRepository <Test>(database);
            IDeleteRepository <Test>      deleteRepository = new MongodbDeleteRepository <Test>(database);

            Test newTest = new Test()
            {
                BoolField      = true,
                NumberField    = 1,
                ObjectId       = Guid.NewGuid().ToString(),
                StringField    = "new-single-object",
                TimestampField = DateTime.UtcNow
            };

            await saveRepository.InsertAsync(newTest);

            Test savedTest = await getRepository.GetFirstByConditionsAsync(x =>
                                                                           x.ObjectId == newTest.ObjectId &&
                                                                           x.BoolField == newTest.BoolField &&
                                                                           x.NumberField == newTest.NumberField &&
                                                                           x.StringField == newTest.StringField &&
                                                                           x.TimestampField == newTest.TimestampField);

            savedTest.BoolField      = false;
            savedTest.NumberField    = 2;
            savedTest.StringField    = "modified-single-object";
            savedTest.TimestampField = DateTime.UtcNow.AddDays(1);

            await saveRepository.ReplaceAsync(
                x =>
                x.ObjectId == newTest.ObjectId &&
                x.BoolField == newTest.BoolField &&
                x.NumberField == newTest.NumberField &&
                x.StringField == newTest.StringField &&
                x.TimestampField == newTest.TimestampField,
                savedTest);

            Test modifiedTest = (await getRepository.GetAllByConditionsAsync(x =>
                                                                             x.ObjectId == savedTest.ObjectId &&
                                                                             x.BoolField == savedTest.BoolField &&
                                                                             x.NumberField == savedTest.NumberField &&
                                                                             x.StringField == savedTest.StringField &&
                                                                             x.TimestampField == savedTest.TimestampField)).Single();

            await deleteRepository.DeleteAllByConditionsAsync(x =>
                                                              x.ObjectId == savedTest.ObjectId &&
                                                              x.BoolField == savedTest.BoolField &&
                                                              x.NumberField == savedTest.NumberField &&
                                                              x.StringField == savedTest.StringField &&
                                                              x.TimestampField == savedTest.TimestampField);

            Test deletedTest = await getRepository.GetFirstByConditionsAsync(x =>
                                                                             x.ObjectId == savedTest.ObjectId &&
                                                                             x.BoolField == savedTest.BoolField &&
                                                                             x.NumberField == savedTest.NumberField &&
                                                                             x.StringField == savedTest.StringField &&
                                                                             x.TimestampField == savedTest.TimestampField);

            Assert.Null(deletedTest);
        }