Skip to content
This repository has been archived by the owner on Feb 6, 2021. It is now read-only.

Commit

Permalink
Minor update to examples and xml doc
Browse files Browse the repository at this point in the history
  • Loading branch information
christophano committed Mar 8, 2017
1 parent 552f74b commit 965994c
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 45 deletions.
15 changes: 9 additions & 6 deletions Effort.Extra.EF6.Tests/Effort.Extra.EF6.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,6 @@
<Compile Include="..\Effort.Extra.Tests\Builder.cs">
<Link>Builder.cs</Link>
</Compile>
<Compile Include="..\Effort.Extra.Tests\Fella.cs">
<Link>Fella.cs</Link>
</Compile>
<Compile Include="..\Effort.Extra.Tests\FellaWithAttribute.cs">
<Link>FellaWithAttribute.cs</Link>
</Compile>
<Compile Include="..\Effort.Extra.Tests\ObjectData.cs">
<Link>ObjectData.cs</Link>
</Compile>
Expand All @@ -153,6 +147,12 @@
<Compile Include="..\Effort.Extra.Tests\ObjectTableDataLoader.cs">
<Link>ObjectTableDataLoader.cs</Link>
</Compile>
<Compile Include="..\Effort.Extra.Tests\Person.cs">
<Link>Person.cs</Link>
</Compile>
<Compile Include="..\Effort.Extra.Tests\PersonWithAttribute.cs">
<Link>PersonWithAttribute.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand All @@ -165,6 +165,9 @@
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
7 changes: 5 additions & 2 deletions Effort.Extra.Tests/Effort.Extra.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@
<Compile Include="Behaviours\CreatesNewTableBehaviour.cs" />
<Compile Include="Behaviours\ReturnsExistingTableBehaviour.cs" />
<Compile Include="Builder.cs" />
<Compile Include="FellaWithAttribute.cs" />
<Compile Include="PersonWithAttribute.cs" />
<Compile Include="ObjectData.cs" />
<Compile Include="ObjectDataCollection.cs" />
<Compile Include="ObjectDataLoader.cs" />
<Compile Include="ObjectDataLoaderFactory.cs" />
<Compile Include="ObjectTableDataLoader.cs" />
<Compile Include="Fella.cs" />
<Compile Include="Person.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand All @@ -184,6 +184,9 @@
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
10 changes: 5 additions & 5 deletions Effort.Extra.Tests/ObjectDataLoaderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class when_data_is_valid : ctor_context
It does_not_throw_an_exception = () => thrown_exception.ShouldBeNull();
}
}

public class CreateTableDataLoader
{
[Subject("ObjectDataLoaderFactory.CreateTableDataLoader")]
Expand Down Expand Up @@ -70,7 +70,7 @@ public class when_table_is_null : create_table_data_loader
table = null;
};

It throws_an_argument_null_exception = () =>
It throws_an_argument_null_exception = () =>
thrown_exception.ShouldBeOfExactType<ArgumentNullException>();
}

Expand All @@ -91,14 +91,14 @@ public class when_there_is_data_for_table : create_table_data_loader
{
Establish context = () =>
{
data.Table<Fella>().Add(new Fella { Name = "Fred" });
table = Builder.CreateTableDescription("Fella", typeof(Fella));
data.Table<Person>().Add(new Person { Name = "Fred" });
table = Builder.CreateTableDescription(typeof(Person).Name, typeof(Person));
};

It does_not_throw_an_exception = () => thrown_exception.ShouldBeNull();

It the_result_is_entity_table_data_loader =
() => result.ShouldBeOfExactType<ObjectTableDataLoader<Fella>>();
() => result.ShouldBeOfExactType<ObjectTableDataLoader<Person>>();
}
}
}
Expand Down
26 changes: 13 additions & 13 deletions Effort.Extra.Tests/ObjectTableDataLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ public abstract class ctor_context : WithFakes
{
protected static Exception thrown_exception;
protected static TableDescription table;
protected static ObjectDataTable<Fella> entities;
protected static ObjectTableDataLoader<Fella> subject;
protected static ObjectDataTable<Person> entities;
protected static ObjectTableDataLoader<Person> subject;

Because of = () => thrown_exception = Catch.Exception(
() => subject = new ObjectTableDataLoader<Fella>(table, entities));
() => subject = new ObjectTableDataLoader<Person>(table, entities));
}

public class when_table_is_null : ctor_context
{
Establish context = () =>
{
table = null;
entities = new ObjectDataTable<Fella>();
entities = new ObjectDataTable<Person>();
};

It throws_an_argument_null_exception =
Expand All @@ -39,7 +39,7 @@ public class when_entities_is_null : ctor_context
{
Establish context = () =>
{
table = Builder.CreateTableDescription("Fella", typeof(Fella));
table = Builder.CreateTableDescription(typeof(Person).Name, typeof(Person));
entities = null;
};

Expand All @@ -51,14 +51,14 @@ public class when_arguments_are_valid : ctor_context
{
Establish context = () =>
{
table = Builder.CreateTableDescription("Fella", typeof(Fella));
entities = new ObjectDataTable<Fella>();
table = Builder.CreateTableDescription(typeof(Person).Name, typeof(Person));
entities = new ObjectDataTable<Person>();
};

It does_not_throw_an_exception = () => thrown_exception.ShouldBeNull();
}
}

public class CreateFormatter
{
[Subject("ObjectTableDataLoader.CreateFormatter")]
Expand All @@ -71,29 +71,29 @@ public abstract class create_formatter_context<TModel> : WithSubject<StubObjectT
() => formatter = Subject.CreateFormatter());
}

public class when_formatter_is_created : create_formatter_context<Fella>
public class when_formatter_is_created : create_formatter_context<Person>
{
It does_not_throw_an_exception = () => thrown_exception.ShouldBeNull();

It the_formatter_is_not_null = () => formatter.ShouldNotBeNull();

It the_formatter_behaves_correctly = () =>
{
var formatted = formatter(new Fella { Name = "Fred" });
var formatted = formatter(new Person { Name = "Fred" });
formatted.Length.ShouldEqual(1);
formatted[0].ShouldEqual("Fred");
};
}

public class when_type_has_column_attribtues : create_formatter_context<FellaWithAttribute>
public class when_type_has_column_attribtues : create_formatter_context<PersonWithAttribute>
{
It does_not_throw_an_exception = () => thrown_exception.ShouldBeNull();

It the_formatter_is_not_null = () => formatter.ShouldNotBeNull();

It the_formatter_behaves_correctly = () =>
{
var formatted = formatter(new FellaWithAttribute { Name = "Fred" });
var formatted = formatter(new PersonWithAttribute { Name = "Fred" });
formatted.Length.ShouldEqual(1);
formatted[0].ShouldEqual("Fred");
};
Expand All @@ -102,7 +102,7 @@ public class when_type_has_column_attribtues : create_formatter_context<FellaWit

public class StubObjectTableDataLoader<TModel> : ObjectTableDataLoader<TModel>
{
public StubObjectTableDataLoader()
public StubObjectTableDataLoader()
: base(Builder.CreateTableDescription(typeof(TModel).Name, typeof(TModel)), new ObjectDataTable<TModel>())
{ }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

namespace Effort.Extra.Tests
{
public class Fella
public class Person
{
public string Name { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
using System.ComponentModel.DataAnnotations.Schema;

public class FellaWithAttribute
public class PersonWithAttribute
{
[Column("Alias")]
public string Name { get; set; }
Expand Down
14 changes: 7 additions & 7 deletions Effort.Extra/ObjectData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ public ObjectData(TableNamingStrategy tableNamingStrategy = TableNamingStrategy.
/// </exception>
/// <example>
/// <code language="c#">
/// public class Fella
/// public class Person
/// {
/// public string Name { get; set; }
/// }
/// ...
/// var data = new ObjectData();
/// var table = data.Table&lt;Fella>();
/// table.Add(new Fella { Name = "Fred" });
/// table.Add(new Fella { Name = "Jeff" });
/// foreach (var fella in data.Table&lt;Fella>())
/// var table = data.Table&lt;Person>();
/// table.Add(new Person { Name = "Fred" });
/// table.Add(new Person { Name = "Jeff" });
/// foreach (var person in data.Table&lt;Person>())
/// {
/// Debug.Print(fella.Name);
/// Debug.Print(person.Name);
/// }
/// // prints:
/// // Fred
Expand Down Expand Up @@ -106,7 +106,7 @@ internal Type TableType(string tableName)
{
return table.GetType().GetGenericArguments()[0];
}
throw new InvalidOperationException(String.Format("No table with the name '{0}' defined.", tableName));
throw new InvalidOperationException($"No table with the name '{tableName}' defined.");
}

internal object GetTable(string tableName)
Expand Down
2 changes: 1 addition & 1 deletion Effort.Extra/ObjectDataTable`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void AddDiscriminator<TType>(string discriminator) where TType : T
/// <summary>
/// Gets the discriminator value for the given type.
/// </summary>
/// <typeparam name="TType">The type of entity.</typeparam>
/// <typeparam name="T">The type of entity.</typeparam>
/// <returns>The discriminator value.</returns>
internal string GetDiscriminator(T item)
{
Expand Down
5 changes: 2 additions & 3 deletions Effort.Extra/ObjectTableDataLoader`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ private static PropertyInfo GetProperty(Type parentType, ColumnDescription colum
.SingleOrDefault(p => MatchColumnAttribute(p, column));
}

// ReSharper disable once UnusedMember.Local
private string GetDiscriminator(T item)
{
return table.GetDiscriminator(item);
Expand All @@ -58,13 +57,13 @@ private Expression ToExpression(ParameterExpression parameter, PropertyInfo prop
{
if (column.Name == table.DiscriminatorColumn)
{
return Expression.Call(Expression.Constant(table), typeof(ObjectDataTable<T>).GetMethod("GetDiscriminator", BindingFlags.Instance | BindingFlags.NonPublic), parameter);
return Expression.Call(Expression.Constant(table), typeof(ObjectDataTable<T>).GetMethod(nameof(GetDiscriminator), BindingFlags.Instance | BindingFlags.NonPublic), parameter);
}
var binder = Binder.GetMember(CSharpBinderFlags.None, column.Name, typeof (ObjectData),
new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) });
var expression = Expression.Dynamic(binder, typeof (object), parameter);
return Expression.TryCatch(expression, Expression.Catch(typeof(RuntimeBinderException), Expression.Constant(null)));
};
}
return Expression.Property(parameter, property);
}

Expand Down
2 changes: 1 addition & 1 deletion Effort.Extra/TableNamingStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public enum TableNamingStrategy
/// </summary>
Pluralised,
/// <summary>
/// Default tabe names should be the entity type name.
/// Default table names should be the entity type name.
/// </summary>
EntityName
}
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ var connection = DbConnectionFactory.CreateTransient(dataLoader);

Adding entities to the `ObjectData` instance is as simple as calling the `Table` method with the generic parameter of the type you want to add. The table name is optional.
```csharp
data.Table<Fella>().Add(new Fella { Name = "Jeff" });
data.Table<Person>().Add(new Person { Name = "Jeff" });
```

If the entity contains a db generated identity field, then this should be provided too. This will enable you to create relations between entities.
```csharp
data.Table<Fella>().Add(new Fella { Id = 1, Name = "Jeff" });
data.Table<Person>().Add(new Person { Id = 1, Name = "Jack" });
data.Table<Dog>().Add(new Dog { Id = 1, OwnerId = 1, Name = "Jim" });
```

If your schema uses a different naming convention that the entity type name, then you can simply provide the set name when calling the `Table` method.
```csharp
data.Table<Fella>("People").Add(new Fella { Id = 1, Name = "Jeff" });
data.Table<Person>("Folk").Add(new Person { Id = 1, Name = "Jane" });
```

If your schema calls for multiple sets of the same type, each collection is keyed on the set name, so multiple sets are supported.
```csharp
data.Table<Fella>("SomeFellas").Add(new Fella { Id = 1, Name = "Jeff" });
data.Table<Fella>("OtherFellas").Add(new Fella { Id = 1, Name = "Jim" });
data.Table<Person>("SomePeople").Add(new Person { Id = 1, Name = "John" });
data.Table<Person>("OtherPeople").Add(new Person { Id = 1, Name = "June" });
```

1 comment on commit 965994c

@bertie78
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Chris - apologies for contacting you in this manner. I have an issue using Effort.Extra which I was hoping you could help me with. My username is Bertie78 - could you email me and I can go into more detail there.

Many thanks ,
Chris.

Please sign in to comment.