public async Task ComplexTypeListTestAsync() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); await collection.InsertOneAsync(testModel); var kidList = new List <TestModel> { new TestModel { Id = Guid.NewGuid() }, new TestModel { Id = Guid.NewGuid() }, new TestModel { Id = Guid.NewGuid() } }; var result = await collection.UpdateManyAsync(t => t.Id == testModel.Id, () => new TestModel { KidList = kidList }); Assert.Equal(1L, result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.True(Comparer.Compare(kidList.Select(p => p.Id), modifyModel.KidList.Select(p => p.Id))); Assert.Equal(1L, (await collection.DeleteOneAsync(t => t.Id == testModel.Id)).DeletedCount); }
public void ComplexTypeArrayTest() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); collection.InsertOne(testModel); var kidArray = new[] { new TestModel { Id = Guid.NewGuid() }, new TestModel { Id = Guid.NewGuid() }, new TestModel { Id = Guid.NewGuid() } }; var result = collection.UpdateMany(t => t.Id == testModel.Id, () => new TestModel { KidArray = kidArray }); Assert.Equal(1L, result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.True(Comparer.Compare(kidArray.Select(p => p.Id), modifyModel.KidArray.Select(p => p.Id))); Assert.Equal(1L, collection.DeleteOne(t => t.Id == testModel.Id).DeletedCount); }
public async Task EnumUShortTestAsync(EnumUShort value) { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); await collection.InsertOneAsync(testModel); var result = await collection.UpdateManyAsync(t => t.Id == testModel.Id, () => new TestModel { EnumUShort = value }); Assert.Equal(1L, testModel.EnumUShort == value ? result.MatchedCount : result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.Equal(value, modifyModel.EnumUShort); Assert.Equal(1L, (await collection.DeleteOneAsync(t => t.Id == testModel.Id)).DeletedCount); }
public void UIntTest(uint value) { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); collection.InsertOne(testModel); var result = collection.UpdateMany(t => t.Id == testModel.Id, () => new TestModel { UInt = value }); Assert.Equal(1L, result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.Equal(value, modifyModel.UInt); Assert.Equal(1L, collection.DeleteOne(t => t.Id == testModel.Id).DeletedCount); }
public void EnumSByteTest(EnumSByte value) { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); collection.InsertOne(testModel); var result = collection.UpdateMany(t => t.Id == testModel.Id, () => new TestModel { EnumSByte = value }); Assert.Equal(1L, testModel.EnumSByte == value ? result.MatchedCount : result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.Equal(value, modifyModel.EnumSByte); Assert.Equal(1L, collection.DeleteOne(t => t.Id == testModel.Id).DeletedCount); }
public async Task ComplexTypeTestAsync() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); await collection.InsertOneAsync(testModel); var value = new TestModel(); var result = await collection.UpdateManyAsync(t => t.Id == testModel.Id, () => new TestModel { Kid = value }); Assert.Equal(1L, result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.Equal(value.ToJson(), modifyModel.Kid.ToJson()); Assert.Equal(1L, (await collection.DeleteOneAsync(t => t.Id == testModel.Id)).DeletedCount); }
public async Task ULongArrayTestAsync() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); await collection.InsertOneAsync(testModel); var ulongArray = new[] { ulong.MinValue, 0UL, ulong.MaxValue / 2 }; var result = await collection.UpdateManyAsync(t => t.Id == testModel.Id, () => new TestModel { ULongArray = ulongArray }); Assert.Equal(1L, result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.True(Comparer.Compare(ulongArray, modifyModel.ULongArray)); Assert.Equal(1L, (await collection.DeleteOneAsync(t => t.Id == testModel.Id)).DeletedCount); }
public async Task StringTestAsync() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); await collection.InsertOneAsync(testModel); var value = DateTime.Now.ToString("yy-MM-dd HH:mm:ss"); var result = await collection.UpdateManyAsync(t => t.Id == testModel.Id, () => new TestModel { String = value }); Assert.Equal(1L, result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.Equal(value, modifyModel.String); Assert.Equal(1L, (await collection.DeleteOneAsync(t => t.Id == testModel.Id)).DeletedCount); }
public void StringArrayTest() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); collection.InsertOne(testModel); var stringArray = new[] { Guid.NewGuid().ToString(), 0.ToString(), Guid.NewGuid().ToString() }; var result = collection.UpdateMany(t => t.Id == testModel.Id, () => new TestModel { StringArray = stringArray }); Assert.Equal(1L, result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.True(Comparer.Compare(stringArray, modifyModel.StringArray)); Assert.Equal(1L, collection.DeleteOne(t => t.Id == testModel.Id).DeletedCount); }
public async Task EnumUShortArrayTestAsync() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); await collection.InsertOneAsync(testModel); var enumUShortArray = new[] { EnumUShort.Apple, EnumUShort.Banana, EnumUShort.Pear }; var result = await collection.UpdateManyAsync(t => t.Id == testModel.Id, () => new TestModel { EnumUShortArray = enumUShortArray }); Assert.Equal(1L, result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.True(Comparer.Compare(enumUShortArray, modifyModel.EnumUShortArray)); Assert.Equal(1L, (await collection.DeleteOneAsync(t => t.Id == testModel.Id)).DeletedCount); }
public async Task GuidArrayTestAsync() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); await collection.InsertOneAsync(testModel); var guidArray = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; var result = await collection.UpdateManyAsync(t => t.Id == testModel.Id, () => new TestModel { GuidArray = guidArray }); Assert.Equal(1L, result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.True(Comparer.Compare(guidArray, modifyModel.GuidArray)); Assert.Equal(1L, (await collection.DeleteOneAsync(t => t.Id == testModel.Id)).DeletedCount); }
public async Task DateTimeArrayTestAsync() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); await collection.InsertOneAsync(testModel); var dateTimeArray = new[] { DateTime.Now.AddDays(-1), DateTime.Now, DateTime.Now.AddDays(1) }; var result = await collection.UpdateManyAsync(t => t.Id == testModel.Id, () => new TestModel { DateTimeArray = dateTimeArray }); Assert.Equal(1L, result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.True(Comparer.Compare(dateTimeArray, modifyModel.DateTimeArray)); Assert.Equal(1L, (await collection.DeleteOneAsync(t => t.Id == testModel.Id)).DeletedCount); }
public void GuidTest() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); collection.InsertOne(testModel); var guid = Guid.NewGuid(); var result = collection.UpdateMany(t => t.Id == testModel.Id, () => new TestModel { Guid = guid }); Assert.Equal(1L, result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.Equal(guid, modifyModel.Guid); Assert.Equal(1L, collection.DeleteOne(t => t.Id == testModel.Id).DeletedCount); }
public void UIntArrayTest() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); collection.InsertOne(testModel); var uintArray = new[] { uint.MinValue, uint.MaxValue / 2 }; var result = collection.UpdateMany(t => t.Id == testModel.Id, () => new TestModel { UIntArray = uintArray }); Assert.Equal(1L, result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.True(Comparer.Compare(uintArray, modifyModel.UIntArray)); Assert.Equal(1L, collection.DeleteOne(t => t.Id == testModel.Id).DeletedCount); }
public void DateTimeTest() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); collection.InsertOne(testModel); var value = DateTime.Now.AddDays(1); var result = collection.UpdateMany(t => t.Id == testModel.Id, () => new TestModel { DateTime = value }); Assert.Equal(1L, result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.True(Comparer.Compare(value, modifyModel.DateTime)); Assert.Equal(1L, collection.DeleteOne(t => t.Id == testModel.Id).DeletedCount); }
public void EnumSByteArrayTest() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); collection.InsertOne(testModel); var enumSByteArray = new[] { EnumSByte.Apple, EnumSByte.Banana, EnumSByte.Pear }; var result = collection.UpdateMany(t => t.Id == testModel.Id, () => new TestModel { EnumSByteArray = enumSByteArray }); Assert.Equal(1L, result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.True(Comparer.Compare(enumSByteArray, modifyModel.EnumSByteArray)); Assert.Equal(1L, collection.DeleteOne(t => t.Id == testModel.Id).DeletedCount); }
public async Task UIntListTestAsync() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); await collection.InsertOneAsync(testModel); var uintList = new List <uint> { uint.MinValue, uint.MaxValue / 2 }; var result = await collection.UpdateManyAsync(t => t.Id == testModel.Id, () => new TestModel { UIntList = uintList }); Assert.Equal(1L, result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.True(Comparer.Compare(uintList, modifyModel.UIntList)); Assert.Equal(1L, (await collection.DeleteOneAsync(t => t.Id == testModel.Id)).DeletedCount); }
public async Task StringListTestAsync() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); await collection.InsertOneAsync(testModel); var stringList = new List <string> { Guid.NewGuid().ToString(), 0.ToString(), Guid.NewGuid().ToString() }; var result = await collection.UpdateManyAsync(t => t.Id == testModel.Id, () => new TestModel { StringList = stringList }); Assert.Equal(1L, result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.True(Comparer.Compare(stringList, modifyModel.StringList)); Assert.Equal(1L, (await collection.DeleteOneAsync(t => t.Id == testModel.Id)).DeletedCount); }
public void UShortListTest() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); collection.InsertOne(testModel); var ushortList = new List <ushort> { ushort.MinValue, ushort.MaxValue }; var result = collection.UpdateMany(t => t.Id == testModel.Id, () => new TestModel { UShortList = ushortList }); Assert.Equal(1L, result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.True(Comparer.Compare(ushortList, modifyModel.UShortList)); Assert.Equal(1L, collection.DeleteOne(t => t.Id == testModel.Id).DeletedCount); }
public void DateTimeUtcListTest() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); collection.InsertOne(testModel); var dateTimeUtcList = new List <DateTime> { DateTime.UtcNow.AddDays(-1), DateTime.UtcNow, DateTime.UtcNow.AddDays(1) }; var result = collection.UpdateMany(t => t.Id == testModel.Id, () => new TestModel { DateTimeUtcList = dateTimeUtcList }); Assert.Equal(1L, result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.True(Comparer.Compare(dateTimeUtcList, modifyModel.DateTimeUtcList)); Assert.Equal(1L, collection.DeleteOne(t => t.Id == testModel.Id).DeletedCount); }
public async Task ComplexTypeListInitTestAsync() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); await collection.InsertOneAsync(testModel); var timeString = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); var result = await collection.UpdateManyAsync(t => t.Id == testModel.Id, () => new TestModel { KidList = new List <TestModel> { new TestModel { String = timeString }, new TestModel { String = timeString }, new TestModel { String = timeString } } }); Assert.Equal(1L, result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.Equal(new List <TestModel> { new TestModel { String = timeString }, new TestModel { String = timeString }, new TestModel { String = timeString } }.ToJson(), modifyModel.KidList.ToJson()); Assert.Equal(1L, (await collection.DeleteOneAsync(t => t.Id == testModel.Id)).DeletedCount); }
public void ComplexTypeArrayInitTest() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); collection.InsertOne(testModel); var timeString = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); var result = collection.UpdateMany(t => t.Id == testModel.Id, () => new TestModel { KidArray = new[] { new TestModel { String = timeString }, new TestModel { String = timeString }, new TestModel { String = timeString } } }); Assert.Equal(1L, result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.Equal(new[] { new TestModel { String = timeString }, new TestModel { String = timeString }, new TestModel { String = timeString } }.ToJson(), modifyModel.KidArray.ToJson()); Assert.Equal(1L, collection.DeleteOne(t => t.Id == testModel.Id).DeletedCount); }