annotate Agendas/trunk/src/Agendas.Repositories.Memory/RepositoryBase.cs @ 62:c40b97bbed01

Verificando persistencia de Ponentes y Tracks en tests de CRUD
author nelopauselli
date Tue, 17 May 2011 01:55:19 -0300
parents 65bbcdd5d357
children 2d1adbaf0373
rev   line source
4
49b572535156 proponer van
nelopauselli
parents:
diff changeset
1 using System;
49b572535156 proponer van
nelopauselli
parents:
diff changeset
2 using System.Collections.Generic;
56
65bbcdd5d357 Pasando la responsabilidad de generar el Id al repositorio
nelopauselli
parents: 34
diff changeset
3 using AltNetHispano.Agendas.Domain;
4
49b572535156 proponer van
nelopauselli
parents:
diff changeset
4
34
475be11edf56 Ajuste en los nombre de los assemblies y namespaces
nelo@MTEySS.neluz.int
parents: 4
diff changeset
5 namespace AltNetHispano.Agendas.Repositories.Memory
4
49b572535156 proponer van
nelopauselli
parents:
diff changeset
6 {
56
65bbcdd5d357 Pasando la responsabilidad de generar el Id al repositorio
nelopauselli
parents: 34
diff changeset
7 public class RepositoryBase<T> where T : Identificable
4
49b572535156 proponer van
nelopauselli
parents:
diff changeset
8 {
49b572535156 proponer van
nelopauselli
parents:
diff changeset
9 protected static readonly IDictionary<Guid, T> Objects = new Dictionary<Guid, T>();
56
65bbcdd5d357 Pasando la responsabilidad de generar el Id al repositorio
nelopauselli
parents: 34
diff changeset
10
65bbcdd5d357 Pasando la responsabilidad de generar el Id al repositorio
nelopauselli
parents: 34
diff changeset
11 public void Save(T obj)
65bbcdd5d357 Pasando la responsabilidad de generar el Id al repositorio
nelopauselli
parents: 34
diff changeset
12 {
65bbcdd5d357 Pasando la responsabilidad de generar el Id al repositorio
nelopauselli
parents: 34
diff changeset
13 if (obj.Id==Guid.Empty)
65bbcdd5d357 Pasando la responsabilidad de generar el Id al repositorio
nelopauselli
parents: 34
diff changeset
14 {
65bbcdd5d357 Pasando la responsabilidad de generar el Id al repositorio
nelopauselli
parents: 34
diff changeset
15 var setter = typeof (Identificable).GetProperty("Id");
65bbcdd5d357 Pasando la responsabilidad de generar el Id al repositorio
nelopauselli
parents: 34
diff changeset
16 setter.SetValue(obj, Guid.NewGuid(), null);
65bbcdd5d357 Pasando la responsabilidad de generar el Id al repositorio
nelopauselli
parents: 34
diff changeset
17 }
65bbcdd5d357 Pasando la responsabilidad de generar el Id al repositorio
nelopauselli
parents: 34
diff changeset
18
65bbcdd5d357 Pasando la responsabilidad de generar el Id al repositorio
nelopauselli
parents: 34
diff changeset
19 if (!Objects.Keys.Contains(obj.Id))
65bbcdd5d357 Pasando la responsabilidad de generar el Id al repositorio
nelopauselli
parents: 34
diff changeset
20 Objects.Add(obj.Id, obj);
65bbcdd5d357 Pasando la responsabilidad de generar el Id al repositorio
nelopauselli
parents: 34
diff changeset
21 }
65bbcdd5d357 Pasando la responsabilidad de generar el Id al repositorio
nelopauselli
parents: 34
diff changeset
22
4
49b572535156 proponer van
nelopauselli
parents:
diff changeset
23 }
49b572535156 proponer van
nelopauselli
parents:
diff changeset
24 }