178
|
1 using System;
|
|
2 using System.Linq;
|
|
3 using AltNetHispano.Agendas.Domain;
|
|
4 using AltNetHispano.Agendas.Domain.Repositories;
|
|
5 using AltNetHispano.Agendas.Domain.Services;
|
|
6 using NUnit.Framework;
|
|
7
|
|
8 namespace AltNetHispano.Agendas.Tests.Cruds
|
|
9 {
|
|
10 public class PersonaCrud
|
|
11 {
|
|
12 private readonly IPersonaRepository _personaRepository;
|
|
13 private readonly Func<IDisposable> _requestEmulator;
|
|
14 private readonly PersonaService _personaService;
|
|
15
|
|
16 public PersonaCrud(Func<IPersonaRepository> createpersonaRepository, Func<IDisposable> requestEmulator)
|
|
17 {
|
|
18 _personaRepository = createpersonaRepository.Invoke();
|
|
19 _personaService = new PersonaService(_personaRepository);
|
|
20 _requestEmulator = requestEmulator;
|
|
21 }
|
|
22
|
|
23 public Guid CreateAdministrador()
|
|
24 {
|
|
25 using (_requestEmulator.Invoke())
|
|
26 {
|
180
|
27 _personaService.Add("Nelo Pauselli", "nelopauselli", "nelopauselli@gmail.com", "http://nelopauselli.blogspot.com", null);
|
178
|
28 }
|
|
29
|
|
30 using (_requestEmulator.Invoke())
|
|
31 {
|
|
32 var persona = _personaRepository.GetByNombre("Nelo Pauselli");
|
|
33 Assert.IsNotNull(persona);
|
|
34 return persona.Id;
|
|
35 }
|
|
36 }
|
|
37
|
|
38 public void ReadAdministrador()
|
|
39 {
|
|
40 Guid personaId = CreateAdministrador();
|
|
41
|
|
42 using (_requestEmulator.Invoke())
|
|
43 {
|
|
44 var persona = _personaRepository.Get(personaId);
|
|
45
|
|
46 Assert.IsNotNull(persona);
|
|
47 Assert.AreEqual("Nelo Pauselli", persona.Nombre);
|
|
48 Assert.AreEqual("nelopauselli", persona.Twitter);
|
|
49 Assert.AreEqual("nelopauselli@gmail.com", persona.Mail);
|
|
50 Assert.AreEqual("http://nelopauselli.blogspot.com", persona.Blog);
|
|
51
|
|
52 Assert.IsTrue(persona.Cuentas.Any());
|
|
53 Assert.AreEqual("nelopauselli", persona.Cuentas.First().LogonName);
|
|
54 Assert.AreEqual(IdentityProviderEnum.Twitter, persona.Cuentas.First().IdentityProvider);
|
|
55
|
|
56 Assert.IsTrue(persona.Roles.Any());
|
|
57 Assert.IsTrue(persona.Roles.Contains(Roles.Usuario));
|
|
58 Assert.IsTrue(persona.Roles.Contains(Roles.Administrador));
|
|
59 }
|
|
60 }
|
|
61
|
|
62 public Guid CreateUsuario()
|
|
63 {
|
|
64 using (_requestEmulator.Invoke())
|
|
65 {
|
180
|
66 _personaService.Add("Pablo Morales", "pablomorales", "pablomorales@gmail.com", "http://pablomorales.blogspot.com", new[]{Roles.Usuario});
|
178
|
67 }
|
|
68
|
|
69 using (_requestEmulator.Invoke())
|
|
70 {
|
|
71 var persona = _personaRepository.GetByNombre("Pablo Morales");
|
|
72 Assert.IsNotNull(persona);
|
|
73 return persona.Id;
|
|
74 }
|
|
75 }
|
|
76
|
|
77 public void ReadUsuario()
|
|
78 {
|
|
79 Guid personaId = CreateUsuario();
|
|
80
|
|
81 using (_requestEmulator.Invoke())
|
|
82 {
|
|
83 var persona = _personaRepository.Get(personaId);
|
|
84
|
|
85 Assert.IsNotNull(persona);
|
|
86 Assert.AreEqual("Pablo Morales", persona.Nombre);
|
|
87 Assert.AreEqual("pablomorales", persona.Twitter);
|
|
88 Assert.AreEqual("pablomorales@gmail.com", persona.Mail);
|
|
89 Assert.AreEqual("http://pablomorales.blogspot.com", persona.Blog);
|
|
90
|
|
91 Assert.IsTrue(persona.Cuentas.Any());
|
|
92 Assert.AreEqual("pablomorales", persona.Cuentas.First().LogonName);
|
|
93 Assert.AreEqual(IdentityProviderEnum.Twitter, persona.Cuentas.First().IdentityProvider);
|
|
94
|
|
95 Assert.IsTrue(persona.Roles.Any());
|
|
96 Assert.IsTrue(persona.Roles.Contains(Roles.Usuario));
|
|
97 Assert.IsFalse(persona.Roles.Contains(Roles.Administrador));
|
|
98 }
|
|
99 }
|
|
100
|
|
101 public void Update()
|
|
102 {
|
|
103 Guid personaId = CreateAdministrador();
|
|
104
|
|
105 using (_requestEmulator.Invoke())
|
|
106 {
|
|
107 var persona = _personaRepository.Get(personaId);
|
|
108 Assert.IsNotNull(persona);
|
|
109
|
|
110 persona.Nombre = "Nelo Mariano Pauselli";
|
|
111 }
|
|
112
|
|
113 using (_requestEmulator.Invoke())
|
|
114 {
|
|
115 var persona = _personaRepository.Get(personaId);
|
|
116
|
|
117 Assert.IsNotNull(persona);
|
|
118 Assert.AreEqual("Nelo Mariano Pauselli", persona.Nombre);
|
|
119 }
|
|
120 }
|
|
121 }
|
|
122 } |