Mercurial > silverbladetech
comparison SilverlightAsyncRestWcf/SilverlightAsyncRestWcf.Services/FakeCarRepository.cs @ 117:9eadccc3b46c
REST working, next step unit tests
author | stevenh7776 |
---|---|
date | Sun, 27 May 2012 15:06:35 +0100 |
parents | |
children | fa4ba8943048 |
comparison
equal
deleted
inserted
replaced
116:d3380f499575 | 117:9eadccc3b46c |
---|---|
1 using System; | |
2 using System.Collections.Generic; | |
3 using System.Linq; | |
4 using SilverlightAsyncRestWcf.Common; | |
5 | |
6 namespace SilverlightAsyncRestWcf.Services | |
7 { | |
8 public class FakeCarRepository : IRepository<Car> | |
9 { | |
10 private readonly IList<Car> _data; | |
11 | |
12 public FakeCarRepository() | |
13 { | |
14 _data = new List<Car> | |
15 { | |
16 new Car() {Id = 1, Make = "Rolls Royce", Model = "Bentley", Year = 1996}, | |
17 new Car() {Id = 2, Make = "Ford", Model = "Fiesta", Year = 1996}, | |
18 new Car() {Id = 3, Make = "Mercedes", Model = "C Class", Year = 1996}, | |
19 new Car() {Id = 4, Make = "BMW", Model = "7 Series", Year = 1996}, | |
20 new Car() {Id = 5, Make = "Jaguar", Model = "XKS", Year = 1996}, | |
21 new Car() {Id = 6, Make = "Audi", Model = "R8", Year = 1996} | |
22 }; | |
23 } | |
24 | |
25 public Car GetById(string id) | |
26 { | |
27 int number; | |
28 return Int32.TryParse(id, out number) | |
29 ? _data.SingleOrDefault(c => c.Id == number) | |
30 : null; | |
31 } | |
32 | |
33 public IQueryable<Car> GetAll() | |
34 { | |
35 return _data.AsQueryable(); | |
36 } | |
37 | |
38 public void Insert(Car entity) | |
39 { | |
40 _data.Add(entity); | |
41 } | |
42 | |
43 public void Update(Car entity) | |
44 { | |
45 var lookup = GetById(entity.Id.ToString()); | |
46 if (lookup == null) throw new Exception("Car not found"); | |
47 | |
48 lookup.Make = entity.Make; | |
49 lookup.Model = entity.Model; | |
50 lookup.Year = entity.Year; | |
51 } | |
52 | |
53 public void Delete(string id) | |
54 { | |
55 var lookup = GetById(id); | |
56 if (lookup == null) throw new Exception("Car not found"); | |
57 _data.Remove(lookup); | |
58 } | |
59 } | |
60 } |