Skip to content

Commit 8d899d3

Browse files
committed
More fixes
1 parent d47a251 commit 8d899d3

File tree

3 files changed

+56
-85
lines changed

3 files changed

+56
-85
lines changed

_posts/2009-02-13-sprint-planner-helper-session-9.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Finally – so what I did was simply to remove the services and then
4444
TDD:ed (hey, that looks funky) a way to inject a repository into the
4545
Controller. It caused me to move things around a bit in the solution.
4646
But for the better. I learned that test-projects should only contain
47-
tests. TestData Repositories for examples are better placed in the
47+
tests. Test Data Repositories for examples are better placed in the
4848
Repositories-assembly.
4949

5050
I am really going back and forth – but at least I know what I am doing.

_posts/2009-02-17-great-generic-repository-patter.md

Lines changed: 54 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -12,91 +12,62 @@ blogger_orig_url: https://www.marcusoft.net/2009/02/great-generic-repository-pat
1212
---
1313

1414

15-
I have [pointed
16-
here](http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/10/08/the-repository-pattern.aspx)
17-
several times before – but it’s so nice.
15+
I have [pointed here](http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/10/08/the-repository-pattern.aspx) several times before – but it’s so nice.
1816

19-
It’s an
20-
[implementation](http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/10/08/the-repository-pattern.aspx)
21-
of the [Repository
22-
Pattern](http://martinfowler.com/eaaCatalog/repository.html) using
23-
generics, that will minimize your code in a very nice way. I am sure
24-
that the FindAll can be refined into something very nice with
25-
[LINQ](http://msdn.microsoft.com/en-us/library/bb308959.aspx), that
26-
allows you to send a specification criteria or so.
17+
It’s an [implementation](http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/10/08/the-repository-pattern.aspx) of the [Repository Pattern](http://martinfowler.com/eaaCatalog/repository.html) using generics, that will minimize your code in a very nice way. I am sure that the FindAll can be refined into something very nice with [LINQ](http://msdn.microsoft.com/en-us/library/bb308959.aspx), that allows you to send a specification criteria or so.
2718

28-
Here is my implementation that uses a common interface (IBaseEntity) for
29-
all my entities. It basically has an ID, so that the abstract
30-
implementation can use it as a key:
19+
Here is my implementation that uses a common interface (IBaseEntity) for all my entities. It basically has an ID, so that the abstract implementation can use it as a key:
3120

32-
> namespace Marcusoft.SprintPlannerHelper.Repositories
33-
> {
34-
> /// \<summary\>
35-
> /// A generic repository interface that dictates all the methods
36-
> that a repository should map to
37-
> /// \</summary\>
38-
> /// \<typeparam name="T"\>the type of the
39-
> interface\</typeparam\>
40-
> public interface IRepository\<T\>  where T :IBaseEntity
41-
> {
42-
> T GetById(Guid id);
43-
> IList\<T\> FindAll();
44-
> void Add(T entity);
45-
> void Remove(T entity);
46-
> }
47-
> }
48-
>
49-
>  
21+
```c#
22+
namespace Marcusoft.SprintPlannerHelper.Repositories
23+
{
24+
/// \<summary\>
25+
/// A generic repository interface that dictates all the methods
26+
that a repository should map to
27+
/// \</summary\>
28+
/// \<typeparam name="T"\>the type of the interface\</typeparam\>
29+
public interface IRepository<Twhere T :IBaseEntity
30+
{
31+
T GetById(Guid id);
32+
IList<T> FindAll();
33+
void Add(T entity);
34+
void Remove(T entity);
35+
}
5036

51-
> public abstract class Repository\<T\> : IRepository\<T\> where T :
52-
> IBaseEntity
53-
> {
54-
> protected readonly Dictionary\<Guid, T\> dictionary = new
55-
> Dictionary\<Guid, T\>();
56-
>
57-
> \#region IRepository\<T\> Members
58-
>
59-
> public T GetById(Guid id)
60-
> {
61-
> return dictionary\[id\];
62-
> }
63-
>
64-
> public IList\<T\> FindAll()
65-
> {
66-
> return new List\<T\>(dictionary.Values);
67-
> }
68-
>
69-
> public void Add(T entity)
70-
> {
71-
> dictionary.Add(entity.ID, entity);
72-
> }
73-
>
74-
> public void Remove(T entity)
75-
> {
76-
> dictionary.Remove(entity.ID);
77-
> }
78-
>
79-
> \#endregion
80-
> }
81-
>
82-
>  
37+
public abstract class Repository<T> : IRepository<T> where T : IBaseEntity
38+
{
39+
protected readonly Dictionary<Guid, T> dictionary = new Dictionary<Guid, T>();
40+
public T GetById(Guid id)
41+
{
42+
return dictionary\[id\];
43+
}
44+
public IList<T> FindAll()
45+
{
46+
return new List<T>(dictionary.Values);
47+
}
48+
public void Add(T entity)
49+
{
50+
dictionary.Add(entity.ID, entity);
51+
}
52+
public void Remove(T entity)
53+
{
54+
dictionary.Remove(entity.ID);
55+
}
56+
}
57+
public class ProductRepositoryFake: Repository<Product>, IProductRepository
58+
{
59+
/// \<summary\>
60+
/// Default constructor that fills the repository with some test data
61+
/// \</summary\>
62+
public ProductRepositoryFake()
63+
{
64+
// Add the products from the test data-class
65+
foreach (var p in TestData.GetTestProductList())
66+
{
67+
dictionary.Add(p.ID, p);
68+
}
69+
}
70+
}
71+
```
8372

84-
> public class ProductRepositoryFake: Repository\<Product\>,
85-
> IProductRepository
86-
> {
87-
> /// \<summary\>
88-
> /// Default constructor that fills the repository with some
89-
> testdata
90-
> /// \</summary\>
91-
> public ProductRepositoryFake()
92-
> {
93-
> // Add the products from the testdata-class
94-
> foreach (var p in TestData.GetTestProductList())
95-
> {
96-
> dictionary.Add(p.ID, p);
97-
> }
98-
> }
99-
> }
100-
101-
I implemented it and wrote this with Albert sleeping on my chest. Just
102-
imagine if all programming sessions were so peaceful.
73+
I implemented it and wrote this with Albert sleeping on my chest. Just imagine if all programming sessions were so peaceful.

_posts/2012-05-16-specflow-page-objects-and.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ I’ve created a small class with static methods that I use to perform database
157157

158158
SpecFlow gives you a number of [events and hooks](https://www.marcusoft.net/2010/12/using-tags-in-specflow-features.html) that you can use to perform task that you want to run before and after tests. In this case I’m:
159159

160-
- Cleaning out the testdata I’ve used and change after each scenario
160+
- Cleaning out the test data I’ve used and change after each scenario
161161
- Closing the browser after each test run. You DO want to do this or you’ll have 50+ browser instances open pretty quickly.
162162

163163
### Steps

0 commit comments

Comments
 (0)