annotate Agendas/trunk/src/Agendas.Tests/AgendaTests.cs @ 3:5f007e266509

code cleanup
author nelopauselli
date Sat, 22 Jan 2011 20:23:50 -0300
parents c03560ae4762
children 49b572535156
rev   line source
2
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
1 using System;
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
2 using System.Linq;
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
3 using Agendas.Repositories.Memory;
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
4 using AltNetHispano.Agendas.Domain;
0
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
5 using AltNetHispano.Agendas.Domain.Repositories;
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
6 using Moq;
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
7 using NUnit.Framework;
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
8
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
9 namespace AltNetHispano.Agendas.Tests
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
10 {
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
11 [TestFixture]
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
12 public class AgendaTests
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
13 {
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
14 [Test]
3
5f007e266509 code cleanup
nelopauselli
parents: 2
diff changeset
15 public void Publicar_cafe()
5f007e266509 code cleanup
nelopauselli
parents: 2
diff changeset
16 {
5f007e266509 code cleanup
nelopauselli
parents: 2
diff changeset
17 var publicador = new Mock<IPublicador>();
5f007e266509 code cleanup
nelopauselli
parents: 2
diff changeset
18
5f007e266509 code cleanup
nelopauselli
parents: 2
diff changeset
19 var agenda = new Agenda(publicador.Object, null);
5f007e266509 code cleanup
nelopauselli
parents: 2
diff changeset
20
5f007e266509 code cleanup
nelopauselli
parents: 2
diff changeset
21 var cafe = new Cafe();
5f007e266509 code cleanup
nelopauselli
parents: 2
diff changeset
22 agenda.Publicar(cafe);
5f007e266509 code cleanup
nelopauselli
parents: 2
diff changeset
23
5f007e266509 code cleanup
nelopauselli
parents: 2
diff changeset
24 publicador.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
5f007e266509 code cleanup
nelopauselli
parents: 2
diff changeset
25 }
5f007e266509 code cleanup
nelopauselli
parents: 2
diff changeset
26
5f007e266509 code cleanup
nelopauselli
parents: 2
diff changeset
27 [Test]
1
6bb4ab4c0611 Tests de Crud para repositorio de Vans
nelopauselli
parents: 0
diff changeset
28 public void Publicar_van()
0
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
29 {
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
30 var publicador = new Mock<IPublicador>();
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
31
2
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
32 var agenda = new Agenda(publicador.Object, null);
0
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
33
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
34 var van = new Van();
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
35 agenda.Publicar(van);
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
36
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
37 publicador.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
38 }
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
39
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
40 [Test]
1
6bb4ab4c0611 Tests de Crud para repositorio de Vans
nelopauselli
parents: 0
diff changeset
41 public void Publicar_van_multiples_publicadores()
0
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
42 {
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
43 var publicador1 = new Mock<IPublicador>();
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
44 var publicador2 = new Mock<IPublicador>();
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
45
3
5f007e266509 code cleanup
nelopauselli
parents: 2
diff changeset
46 var agenda = new Agenda(new CompositePublicador(new[] {publicador1.Object, publicador2.Object}), null);
0
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
47
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
48 var cafe = new Cafe();
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
49 agenda.Publicar(cafe);
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
50
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
51 publicador1.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
52 publicador2.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
53 }
1
6bb4ab4c0611 Tests de Crud para repositorio de Vans
nelopauselli
parents: 0
diff changeset
54
6bb4ab4c0611 Tests de Crud para repositorio de Vans
nelopauselli
parents: 0
diff changeset
55 [Test]
6bb4ab4c0611 Tests de Crud para repositorio de Vans
nelopauselli
parents: 0
diff changeset
56 public void Publicar_y_recordar_van()
6bb4ab4c0611 Tests de Crud para repositorio de Vans
nelopauselli
parents: 0
diff changeset
57 {
6bb4ab4c0611 Tests de Crud para repositorio de Vans
nelopauselli
parents: 0
diff changeset
58 var publicador1 = new Mock<IPublicador>();
6bb4ab4c0611 Tests de Crud para repositorio de Vans
nelopauselli
parents: 0
diff changeset
59 var publicador2 = new Mock<IPublicador>();
6bb4ab4c0611 Tests de Crud para repositorio de Vans
nelopauselli
parents: 0
diff changeset
60 var recordador1 = new Mock<IRecordador>();
6bb4ab4c0611 Tests de Crud para repositorio de Vans
nelopauselli
parents: 0
diff changeset
61
3
5f007e266509 code cleanup
nelopauselli
parents: 2
diff changeset
62 var agenda = new Agenda(new CompositePublicador(new[] {publicador1.Object, publicador2.Object}), recordador1.Object);
1
6bb4ab4c0611 Tests de Crud para repositorio de Vans
nelopauselli
parents: 0
diff changeset
63
6bb4ab4c0611 Tests de Crud para repositorio de Vans
nelopauselli
parents: 0
diff changeset
64 var van = new Van();
6bb4ab4c0611 Tests de Crud para repositorio de Vans
nelopauselli
parents: 0
diff changeset
65 agenda.Publicar(van);
6bb4ab4c0611 Tests de Crud para repositorio de Vans
nelopauselli
parents: 0
diff changeset
66
6bb4ab4c0611 Tests de Crud para repositorio de Vans
nelopauselli
parents: 0
diff changeset
67 agenda.Recordar(van);
6bb4ab4c0611 Tests de Crud para repositorio de Vans
nelopauselli
parents: 0
diff changeset
68
6bb4ab4c0611 Tests de Crud para repositorio de Vans
nelopauselli
parents: 0
diff changeset
69 publicador1.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
6bb4ab4c0611 Tests de Crud para repositorio de Vans
nelopauselli
parents: 0
diff changeset
70 publicador2.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
6bb4ab4c0611 Tests de Crud para repositorio de Vans
nelopauselli
parents: 0
diff changeset
71 recordador1.Verify(r => r.Recordar(It.IsAny<Evento>()), Times.Exactly(1));
6bb4ab4c0611 Tests de Crud para repositorio de Vans
nelopauselli
parents: 0
diff changeset
72
2
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
73 Assert.AreEqual(1, agenda.Eventos.Count());
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
74 }
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
75
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
76 [Test]
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
77 public void Van_crud()
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
78 {
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
79 Guid vanId;
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
80 {
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
81 var agenda = new Agenda(null, null);
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
82 agenda.Publicar(new Van());
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
83
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
84 IAgendaRepository agendaRepository = new AgendaRepository();
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
85
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
86 agendaRepository.Save(agenda);
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
87 vanId = agenda.Id;
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
88 }
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
89
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
90 {
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
91 IAgendaRepository agendaRepository = new AgendaRepository();
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
92
3
5f007e266509 code cleanup
nelopauselli
parents: 2
diff changeset
93 Agenda agenda = agendaRepository.Get(vanId);
2
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
94
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
95 Assert.IsNotNull(agenda);
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
96 Assert.AreEqual(1, agenda.Eventos.Count());
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
97 agenda.Publicar(new Cafe());
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
98
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
99 agendaRepository.Update(agenda);
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
100 }
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
101
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
102 {
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
103 IAgendaRepository agendaRepository = new AgendaRepository();
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
104
3
5f007e266509 code cleanup
nelopauselli
parents: 2
diff changeset
105 Agenda agenda = agendaRepository.Get(vanId);
2
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
106
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
107 Assert.IsNotNull(agenda);
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
108 Assert.AreEqual(2, agenda.Eventos.Count());
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
109
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
110 agendaRepository.Delete(agenda);
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
111 }
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
112
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
113 {
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
114 IAgendaRepository agendaRepository = new AgendaRepository();
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
115
3
5f007e266509 code cleanup
nelopauselli
parents: 2
diff changeset
116 Agenda agenda = agendaRepository.Get(vanId);
2
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
117
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
118 Assert.IsNull(agenda);
c03560ae4762 Test de Crud para la agenda
nelopauselli
parents: 1
diff changeset
119 }
1
6bb4ab4c0611 Tests de Crud para repositorio de Vans
nelopauselli
parents: 0
diff changeset
120 }
0
3f7dbb633b71 Test sobre la publicación de Eventos al registrarlos en la Agenda
nelopauselli
parents:
diff changeset
121 }
3
5f007e266509 code cleanup
nelopauselli
parents: 2
diff changeset
122 }