Permalink
Browse files

Merge remote branch 'samus/master' into 090beta2

Conflicts:
	source/MongoDB.GridFS/GridFile.cs
	source/MongoDB/Configuration/Mapping/Auto/ClassOverrides.cs
	source/MongoDB/Configuration/Mapping/Auto/IdOverrides.cs
  • Loading branch information...
lanwin committed Jun 28, 2010
2 parents cd7f622 + 112651a commit eb2badc00b5db108ef04d8d3cf1cc5a6637fa494
@@ -68,9 +68,11 @@ public class GridFileInfoTest : GridTestBase
String filename = "gfi-delete.txt";
GridFile gf = new GridFile(DB,"gfdelete");
GridFileInfo gfi = new GridFileInfo(DB,"gfdelete", filename);
+ var id = gfi.Id;
GridFileStream gfs = gfi.Create(); //TODO Expand Test to make sure that chunks for the file got deleted too.
gfi.Delete();
Assert.IsFalse(gf.Exists(filename), "File should have been deleted.");
+ Assert.IsTrue(0 == gf.Chunks.Count(new Document("_id", id)));
}
[Test]
@@ -54,6 +54,23 @@ public class GridFileTest : GridTestBase
tw.Close();
}
Assert.AreEqual(1, CountChunks("gfcreate", id));
- }
+ }
+
+ [Test]
+ public void TestDeleteRemovesChunks(){
+ Object id;
+ string filename = "deletebyname.txt";
+ string fs = "fs";
+ GridFile gf = new GridFile(DB,fs);
+ using(GridFileStream gfs = gf.Create(filename, FileMode.CreateNew)){
+ id = gfs.GridFileInfo.Id;
+ TextWriter tw = new StreamWriter(gfs);
+ tw.WriteLine("test");
+ tw.Close();
+ }
+ Assert.AreEqual(1, CountChunks(fs, id), "Chunks not found");
+ gf.Delete("deletebyname.txt");
+ Assert.AreEqual(0, CountChunks(fs, id), "Chunks found");
+ }
}
}
@@ -54,12 +54,12 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
- <Reference Include="nunit.framework, Version=2.4.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
+ <Reference Include="System" />
+ <Reference Include="System.Xml" />
+ <Reference Include="nunit.framework, Version=2.4.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\redist\nunit.framework.dll</HintPath>
</Reference>
- <Reference Include="System" />
- <Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="GridFileInfoTest.cs" />
@@ -71,6 +71,7 @@
</None>
<None Include="..\MongoDB.Tests\App.config">
<Link>App.config</Link>
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="MongoDB.GridFS.Tests.csproj" />
</ItemGroup>
@@ -55,7 +55,8 @@ public IMongoCollection Chunks
this.db = db;
this.files = db[bucket + ".files"];
this.chunks = db[bucket + ".chunks"];
- this.chunks.Metadata.CreateIndex(new Document().Add("files_id", 1).Add("n", 1), true);
+ this.chunks.MetaData.CreateIndex(new Document().Add("files_id", 1).Add("n", 1), true);
+ this.files.MetaData.CreateIndex(new Document().Add("filename", 1).Add("n", 1), false);
this.name = bucket;
}
@@ -199,7 +200,7 @@ public ICursor ListFiles(Document query)
/// Permanently removes a file from the database.
/// </summary>
public void Delete(String filename){
- files.Remove(new Document().Add("filename", filename));
+ this.Delete(new Document().Add("filename", filename));
}
/// <summary>
@@ -10,7 +10,7 @@ namespace MongoDB.IntegrationTests.Linq
public class MongoQueryProviderTests : LinqTestsBase
{
[Test]
- public void Boolean_Test1()
+ public void Boolean1()
{
var people = Collection.Linq().Where(x => x.PrimaryAddress.IsInternational);
@@ -19,14 +19,23 @@ public void Boolean_Test1()
}
[Test]
- public void Boolean_Test2()
+ public void Boolean_Inverse()
{
var people = Collection.Linq().Where(x => !x.PrimaryAddress.IsInternational);
var queryObject = ((IMongoQueryable)people).GetQueryObject();
Assert.AreEqual(new Document("$not", new Document("PrimaryAddress.IsInternational", true)), queryObject.Query);
}
+ [Test]
+ public void Boolean_In_Conjunction()
+ {
+ var people = Collection.Linq().Where(x => x.PrimaryAddress.IsInternational && x.Age > 21);
+
+ var queryObject = ((IMongoQueryable)people).GetQueryObject();
+ Assert.AreEqual(new Document("PrimaryAddress.IsInternational", true).Add("Age", Op.GreaterThan(21)), queryObject.Query);
+ }
+
[Test]
public void Chained()
{
@@ -64,21 +64,29 @@ public override void TestSetup()
}
[Test]
- public void Boolean_Test1()
+ public void Boolean()
{
var people = Enumerable.ToList(Collection.Linq().Where(x => x.PrimaryAddress.IsInternational));
Assert.AreEqual(3, people.Count);
}
[Test]
- public void Boolean_Test2()
+ public void Boolean_Inverse()
{
var people = Enumerable.ToList(Collection.Linq().Where(x => !x.PrimaryAddress.IsInternational));
Assert.AreEqual(0, people.Count);
}
+ [Test]
+ public void Boolean_In_Conjunction()
+ {
+ var people = Enumerable.ToList(Collection.Linq().Where(x => x.PrimaryAddress.IsInternational && x.Age > 21));
+
+ Assert.AreEqual(2, people.Count);
+ }
+
[Test]
public void Chained()
{
@@ -1,37 +1,37 @@
-using System;
-using MongoDB.Configuration.Mapping.Auto;
-using System.Linq.Expressions;
-using System.Reflection;
-
-namespace MongoDB.Configuration.Builders
-{
- /// <summary>
- ///
- /// </summary>
- /// <typeparam name="T"></typeparam>
- public class ClassOverridesBuilder<T>
- {
- private readonly ClassOverrides _overrides;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="ClassOverridesBuilder&lt;T&gt;"/> class.
- /// </summary>
- /// <param name="overrides">The overrides.</param>
- internal ClassOverridesBuilder(ClassOverrides overrides)
- {
- if (overrides == null)
- throw new ArgumentNullException("overrides");
-
- _overrides = overrides;
- }
-
- /// <summary>
- /// Collections the name.
- /// </summary>
- /// <param name="name">The name.</param>
- public void CollectionName(string name)
- {
- _overrides.CollectionName = name;
+using System;
+using MongoDB.Configuration.Mapping.Auto;
+using System.Linq.Expressions;
+using System.Reflection;
+
+namespace MongoDB.Configuration.Builders
+{
+ /// <summary>
+ ///
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ public class ClassOverridesBuilder<T>
+ {
+ private readonly ClassOverrides _overrides;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ClassOverridesBuilder&lt;T&gt;"/> class.
+ /// </summary>
+ /// <param name="overrides">The overrides.</param>
+ internal ClassOverridesBuilder(ClassOverrides overrides)
+ {
+ if (overrides == null)
+ throw new ArgumentNullException("overrides");
+
+ _overrides = overrides;
+ }
+
+ /// <summary>
+ /// Collections the name.
+ /// </summary>
+ /// <param name="name">The name.</param>
+ public void CollectionName(string name)
+ {
+ _overrides.CollectionName = name;
}
/// <summary>
@@ -41,8 +41,9 @@ public void CollectionName(string name)
/// <returns></returns>
public IdOverridesBuilder Id(MemberInfo member)
{
- var overrides = new IdOverrides { Member = member };
- return new IdOverridesBuilder(overrides);
+ var id = new IdOverrides { Member = member };
+ _overrides.IdOverrides = id;
+ return new IdOverridesBuilder(id);
}
/// <summary>
@@ -70,44 +71,44 @@ public IdOverridesBuilder Id(Expression<Func<T, object>> member)
{
var mex = GetMemberExpression(member);
return Id(mex.Member.Name);
- }
-
- /// <summary>
- /// Members the specified member.
- /// </summary>
- /// <param name="member">The member.</param>
- /// <returns></returns>
- public MemberOverridesBuilder Member(MemberInfo member)
- {
- var overrides = _overrides.GetOverridesFor(member);
- return new MemberOverridesBuilder(overrides);
- }
-
- /// <summary>
- /// Members the specified name.
- /// </summary>
- /// <param name="name">The name.</param>
- /// <returns></returns>
- public MemberOverridesBuilder Member(string name)
- {
- var members = typeof(T).GetMember(name, MemberTypes.Field | MemberTypes.Property, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
- if (members == null || members.Length == 0)
- throw new InvalidOperationException("No member was found.");
- if (members.Length > 1)
- throw new InvalidOperationException("More than one member matched the specified name.");
-
- return Member(members[0]);
- }
-
- /// <summary>
- /// Members the specified member.
- /// </summary>
- /// <param name="member">The member.</param>
- /// <returns></returns>
- public MemberOverridesBuilder Member(Expression<Func<T, object>> member)
+ }
+
+ /// <summary>
+ /// Members the specified member.
+ /// </summary>
+ /// <param name="member">The member.</param>
+ /// <returns></returns>
+ public MemberOverridesBuilder Member(MemberInfo member)
+ {
+ var overrides = _overrides.GetOverridesFor(member);
+ return new MemberOverridesBuilder(overrides);
+ }
+
+ /// <summary>
+ /// Members the specified name.
+ /// </summary>
+ /// <param name="name">The name.</param>
+ /// <returns></returns>
+ public MemberOverridesBuilder Member(string name)
+ {
+ var members = typeof(T).GetMember(name, MemberTypes.Field | MemberTypes.Property, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
+ if (members == null || members.Length == 0)
+ throw new InvalidOperationException("No member was found.");
+ if (members.Length > 1)
+ throw new InvalidOperationException("More than one member matched the specified name.");
+
+ return Member(members[0]);
+ }
+
+ /// <summary>
+ /// Members the specified member.
+ /// </summary>
+ /// <param name="member">The member.</param>
+ /// <returns></returns>
+ public MemberOverridesBuilder Member(Expression<Func<T, object>> member)
{
var mex = GetMemberExpression(member);
- return Member(mex.Member.Name);
+ return Member(mex.Member.Name);
}
/// <summary>
@@ -125,6 +126,6 @@ private MemberExpression GetMemberExpression(Expression<Func<T, object>> member)
}
return memberExpression;
- }
- }
+ }
+ }
}
@@ -8,7 +8,6 @@ namespace MongoDB.Configuration.Mapping.Auto
/// </summary>
public class ClassOverrides
{
- private readonly IdOverrides _idOverrides;
private readonly Dictionary<MemberInfo, MemberOverrides> _memberOverrides;
/// <summary>
@@ -18,21 +17,17 @@ public class ClassOverrides
public string CollectionName { get; set; }
/// <summary>
- /// Initializes a new instance of the <see cref="ClassOverrides"/> class.
+ /// Gets or sets the id overrides.
/// </summary>
- public ClassOverrides()
- {
- _idOverrides = null;
- _memberOverrides = new Dictionary<MemberInfo, MemberOverrides>();
- }
+ /// <value>The id overrides.</value>
+ public IdOverrides IdOverrides { get; set; }
/// <summary>
- /// Gets the id overrides.
+ /// Initializes a new instance of the <see cref="ClassOverrides"/> class.
/// </summary>
- /// <returns></returns>
- public IdOverrides GetIdOverrides()
+ public ClassOverrides()
{
- return _idOverrides;
+ _memberOverrides = new Dictionary<MemberInfo, MemberOverrides>();
}
/// <summary>
@@ -49,4 +44,4 @@ public MemberOverrides GetOverridesFor(MemberInfo memberInfo)
return memberOverrides;
}
}
-}
+}
@@ -1,10 +1,14 @@
-using System.Reflection;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Reflection;
using MongoDB.Configuration.IdGenerators;
namespace MongoDB.Configuration.Mapping.Auto
{
/// <summary>
- ///
+ /// Overrides the Id member.
/// </summary>
public class IdOverrides
{
@@ -253,7 +253,7 @@ private T GetClassOverrideValue<T>(Type classType, Func<ClassOverrides, T> overr
if (!_overrides.HasOverridesForType(classType))
return defaultValue;
- var idOverrides = _overrides.GetOverridesForType(classType).GetIdOverrides();
+ var idOverrides = _overrides.GetOverridesForType(classType).IdOverrides;
if (idOverrides == null)
return defaultValue;
@@ -219,6 +219,9 @@ internal void AddMemberMap(PersistentMemberMap memberMap)
/// <param name = "memberMaps">The member maps.</param>
internal void AddMemberMaps(IEnumerable<PersistentMemberMap> memberMaps)
{
+ if (memberMaps.Any(m => m.Alias == "_id"))
+ throw new MongoException("_id is a reserved MongoDB alias and cannot be used for anything other than an Id column.");
+
_memberMaps.AddRange(memberMaps);
}
Oops, something went wrong.

0 comments on commit eb2badc

Please sign in to comment.