public void EnumLongArrayTest() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); collection.InsertOne(testModel); var enumLongArray = new[] { EnumLong.Apple, EnumLong.Banana, EnumLong.Pear }; var result = collection.UpdateMany(t => t.Id == testModel.Id, () => new TestModel { EnumLongArray = enumLongArray }); Assert.Equal(1L, result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.True(Comparer.Compare(enumLongArray, modifyModel.EnumLongArray)); Assert.Equal(1L, collection.DeleteOne(t => t.Id == testModel.Id).DeletedCount); }
public async Task EnumUShortListTestAsync() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); await collection.InsertOneAsync(testModel); var enumUShortList = new List <EnumUShort> { EnumUShort.Apple, EnumUShort.Banana, EnumUShort.Pear }; var result = await collection.UpdateManyAsync(t => t.Id == testModel.Id, () => new TestModel { EnumUShortList = enumUShortList }); Assert.Equal(1L, result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.True(Comparer.Compare(enumUShortList, modifyModel.EnumUShortList)); Assert.Equal(1L, (await collection.DeleteOneAsync(t => t.Id == testModel.Id)).DeletedCount); }
public void GuidListTest() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); collection.InsertOne(testModel); var guidList = new List <Guid> { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; var result = collection.UpdateMany(t => t.Id == testModel.Id, () => new TestModel { GuidList = guidList }); Assert.Equal(1L, result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.True(Comparer.Compare(guidList, modifyModel.GuidList)); Assert.Equal(1L, collection.DeleteOne(t => t.Id == testModel.Id).DeletedCount); }
public void DateTimeListTest() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); collection.InsertOne(testModel); var dateTimeList = new List <DateTime> { DateTime.Now.AddDays(-1), DateTime.Now, DateTime.Now.AddDays(1) }; var result = collection.UpdateMany(t => t.Id == testModel.Id, () => new TestModel { DateTimeList = dateTimeList }); Assert.Equal(1L, result.ModifiedCount); var modifyModel = collection.AsQueryable().First(p => p.Id == testModel.Id); Assert.True(Comparer.Compare(dateTimeList, modifyModel.DateTimeList)); Assert.Equal(1L, collection.DeleteOne(t => t.Id == testModel.Id).DeletedCount); }
public void UIntListTest() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); collection.InsertOne(testModel); var uintList = new List <uint> { uint.MinValue, uint.MaxValue / 2 }; var result = collection.UpdateMany(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, collection.DeleteOne(t => t.Id == testModel.Id).DeletedCount); }
public async Task UShortListTestAsync() { var collection = MongoDatabase.GetCollection <TestModel>("TestModel"); var testModel = TestModelFactory.GetModel(); await collection.InsertOneAsync(testModel); var ushortList = new List <ushort> { ushort.MinValue, ushort.MaxValue }; var result = await collection.UpdateManyAsync(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, (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 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); }
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); }