1+ using NUnit . Framework ;
2+ using SharpRepository . Repository ;
3+ using Should ;
4+
5+ namespace SharpRepository . Samples
6+ {
7+ [ TestFixture ]
8+ public class GettingStarted
9+ {
10+ /*
11+ * Getting Started
12+ *
13+ * Let's keep things simple. The Repository pattern is a facade that abstracts
14+ * away the technical concerns of your persistence implementation by offering a
15+ * collection-like interface for managing domain objects.
16+ *
17+ * SharpRepository is a persistent ignorant seam which sits between your
18+ * application and data access layer. SharpRepository provides the generic base
19+ * but also numerous persistence implementations (EF, RavenDb, etc) which can
20+ * be swapped based on project needs. By offering the needed separation
21+ * of concerns, SharpRepository promotes the ability to unit test agains mocks
22+ * as opposed to intergration testing against the database itself.
23+ *
24+ * For more information on the Repository Pattern:
25+ *
26+ * http://domaindrivendesign.org/books/#DDD
27+ * http://martinfowler.com/eaaCatalog/repository.html
28+ * http://msdn.microsoft.com/en-us/library/ff649690.aspx
29+ *
30+ * CRUD Operations
31+ *
32+ * The most basic repository operations are CRUD (create, read, update, delete).
33+ * Here we define the entity type, Order, which will be persisted and we execute
34+ * the four CRUD operations.
35+ */
36+ public class Order
37+ {
38+ public int OrderId { get ; set ; }
39+ public string Name { get ; set ; }
40+ }
41+
42+ [ Test ]
43+ public void SharpRepository_Supports_Basic_Crud_Operations ( )
44+ {
45+ // Declare your generic InMemory Repository.
46+ // Check out HowToAbstractAwayTheGenericRepository.cs for cleaner ways to new up a repo.
47+ var repo = new InMemoryRepository < Order , int > ( ) ;
48+
49+ // Create
50+ var create = new Order { Name = "Big sale" } ;
51+ repo . Add ( create ) ;
52+
53+ const int expectedOrderId = 1 ;
54+ create . OrderId . ShouldEqual ( expectedOrderId ) ;
55+
56+ // Read
57+ var read = repo . Get ( expectedOrderId ) ;
58+ read . Name . ShouldEqual ( create . Name ) ;
59+
60+ // Update
61+ read . Name = "Really big sale" ;
62+ repo . Update ( read ) ;
63+
64+ var update = repo . Get ( expectedOrderId ) ;
65+ update . OrderId . ShouldEqual ( expectedOrderId ) ;
66+ update . Name . ShouldEqual ( read . Name ) ;
67+
68+ // Delete
69+ repo . Delete ( update ) ;
70+ var delete = repo . Get ( expectedOrderId ) ;
71+ delete . ShouldBeNull ( ) ;
72+ }
73+ }
74+ }
0 commit comments