Skip to content

Commit

Permalink
Added AR test records to Generated folder in BugReports. Added test f…
Browse files Browse the repository at this point in the history
…or IActiveRecord in Load which sets isnew and isfalse accordingly. Closes #32
  • Loading branch information
robconery committed Jul 9, 2009
1 parent e670ec5 commit d4602e7
Show file tree
Hide file tree
Showing 17 changed files with 11,817 additions and 109 deletions.
8 changes: 8 additions & 0 deletions SubSonic.Core/Extensions/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ public static void Load<T>(this IDataReader rdr, T item)
currentField.SetValue(item, rdr.GetValue(i).ChangeTypeTo(valueType));
}
}

if (item is IActiveRecord) {
var arItem = (IActiveRecord)item;
arItem.SetIsLoaded(true);
arItem.SetIsNew(false);

}

}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions SubSonic.Core/Schema/IActiveRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ public interface IActiveRecord
DbCommand GetDeleteCommand();
void SetKeyValue(object value);
void SetIsLoaded(bool isLoaded);
void SetIsNew(bool isLoaded);

}
}
50 changes: 44 additions & 6 deletions SubSonic.Tests/BugReports/ActiveRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,58 @@
using System.Linq;
using System.Text;
using Xunit;
using SouthWind;

namespace SubSonic.Tests.BugReports {

public class ActiveRecord {

/// <summary>
/// Issue 58 on SubSonicThree site, reported by jonathan.channon (aka ZIPPY!~)
/// Reports a null return - cannot repro
/// Issue 32 - ActiveRecord - IsLoaded not set true when query is executed
/// http://github.com/subsonic/SubSonic-3.0/issues#issue/32
/// </summary>
[Fact]
public void FindByPrimaryKey_Should_Not_Return_Null() {
var db = new Southwind.NorthwindDB();
var table=db.FindByPrimaryKey("CategoryID");
Assert.NotNull(table);
public void UsingLinq_With_ActiveRecord_Product_Should_Set_IsLoaded_True() {
var list = from p in Product.All()
where p.ProductID > 0
select p;

Assert.Equal(true, list.FirstOrDefault().IsLoaded());
}


[Fact]
public void UsingLinq_With_ActiveRecord_Product_Should_Set_IsNew_False() {
var list = from p in Product.All()
where p.ProductID > 0
select p;

Assert.Equal(false, list.FirstOrDefault().IsNew());
}

[Fact]
public void CreatingNew_Product_Should_Set_IsNew_True() {
var product = new Product();
Assert.Equal(true, product.IsNew());
}
[Fact]
public void CreatingNew_Product_Should_Set_IsLoaded_False() {
var product = new Product();
Assert.Equal(false, product.IsLoaded());
}

[Fact]
public void PullingSingle_Should_Set_New_Product_IsLoaded_True() {
var product = new Product();
product = Product.SingleOrDefault(x => x.ProductID == 1);
Assert.Equal(true, product.IsLoaded());
}
[Fact]
public void PullingSingle_Should_Set_New_Product_IsNew_False() {
var product = new Product();
product = Product.SingleOrDefault(x => x.ProductID == 1);
Assert.Equal(false, product.IsNew());
}
}

}
75 changes: 0 additions & 75 deletions SubSonic.Tests/BugReports/AdvancedTemplates.cs

This file was deleted.

0 comments on commit d4602e7

Please sign in to comment.