private void SeedOngs(VoteMonitorContext context)
        {
            if (context.Ngos.Any())
            {
                return;
            }

            context.Ngos.AddRange(
                new Domain.Ong.Models.Ngo {
                Id = 1, Name = "Denumire ONG A", ShortName = "ONG A"
            },
                new Domain.Ong.Models.Ngo {
                Id = 2, Name = "Denumire ONG B", ShortName = "ONG B"
            },
                new Domain.Ong.Models.Ngo {
                Id = 3, Name = "Denumire ONG C", ShortName = "ONG C"
            },
                new Domain.Ong.Models.Ngo {
                Id = 4, Name = "Denumire ONG D", ShortName = "ONG D"
            },
                new Domain.Ong.Models.Ngo {
                Id = 5, Name = "Denumire ONG E", ShortName = "ONG E"
            },
                new Domain.Ong.Models.Ngo {
                Id = 6, Name = "Denumire ONG F", ShortName = "ONG F"
            }
                );

            context.SaveChanges();
        }
 public GenerateObserversHandler(VoteMonitorContext voteMonitorContext, ILogger <GenerateObserversHandler> logger, IMapper mapper, IHashService hashService)
 {
     _voteMonitorContext = voteMonitorContext;
     _logger             = logger;
     _mapper             = mapper;
     _hashService        = hashService;
 }
        private void SeedSectiiDeVotare(VoteMonitorContext context, int idJudet)
        {
            if (context.PollingStations.Any(a => a.IdCounty == idJudet))
            {
                return;
            }

            context.PollingStations.AddRange(
                new PollingStation {
                Id = idJudet * 10 + 1, IdCounty = idJudet, AdministrativeTerritoryCode = $"Sectia {idJudet * 10 + 1}", Number = 1, TerritoryCode = $"Localitate {idJudet * 10 + 1}"
            },
                new PollingStation {
                Id = idJudet * 10 + 2, IdCounty = idJudet, AdministrativeTerritoryCode = $"Sectia {idJudet * 10 + 2}", Number = 2, TerritoryCode = $"Localitate {idJudet * 10 + 2}"
            },
                new PollingStation {
                Id = idJudet * 10 + 3, IdCounty = idJudet, AdministrativeTerritoryCode = $"Sectia {idJudet * 10 + 3}", Number = 3, TerritoryCode = $"Localitate {idJudet * 10 + 3}"
            },
                new PollingStation {
                Id = idJudet * 10 + 4, IdCounty = idJudet, AdministrativeTerritoryCode = $"Sectia {idJudet * 10 + 4}", Number = 4, TerritoryCode = $"Localitate {idJudet * 10 + 4}"
            },
                new PollingStation {
                Id = idJudet * 10 + 5, IdCounty = idJudet, AdministrativeTerritoryCode = $"Sectia {idJudet * 10 + 5}", Number = 5, TerritoryCode = $"Localitate {idJudet * 10 + 5}"
            }
                );

            context.SaveChanges();
        }
        public async Task When_loading_county_by_existent_id()
        {
            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                context.Counties.Add(new County {
                    Code = "Code1", Diaspora = false, Id = 1, Name = "Name1", Order = 12, NumberOfPollingStations = 14
                });
                context.Counties.Add(new County {
                    Code = "Code2", Diaspora = true, Id = 2, Name = "Name2", Order = 3, NumberOfPollingStations = 2
                });
                context.Counties.Add(new County {
                    Code = "Code3", Diaspora = true, Id = 3, Name = "Name3", Order = 1, NumberOfPollingStations = 2
                });
                context.SaveChanges();
            }

            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                var countiesCommandHandler = new CountiesCommandHandler(context, _fakeLogger.Object, _mapper);
                var county =
                    await countiesCommandHandler.Handle(new GetCounty(2), new CancellationToken(false));

                county.IsSuccess.ShouldBeTrue();
                var c2 = county.Value;
                c2.Id.ShouldBe(2);
                c2.Code.ShouldBe("Code2");
                c2.Name.ShouldBe("Name2");
                c2.NumberOfPollingStations.ShouldBe(2);
                c2.Diaspora.ShouldBe(true);
                c2.Order.ShouldBe(3);
            }
        }
        public async Task When_updating_county_by_nonexistent_id()
        {
            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                context.Counties.Add(new County {
                    Code = "Code1", Diaspora = false, Id = 1, Name = "Name1", Order = 12, NumberOfPollingStations = 14
                });
                context.Counties.Add(new County {
                    Code = "Code2", Diaspora = true, Id = 2, Name = "Name2", Order = 3, NumberOfPollingStations = 2
                });
                context.Counties.Add(new County {
                    Code = "Code3", Diaspora = true, Id = 3, Name = "Name3", Order = 1, NumberOfPollingStations = 2
                });
                context.SaveChanges();
            }

            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                var countiesCommandHandler = new CountiesCommandHandler(context, _fakeLogger.Object, _mapper);
                var county =
                    await countiesCommandHandler.Handle(new UpdateCounty(588, new UpdateCountyModel()), new CancellationToken(false));

                county.IsFailure.ShouldBeTrue();
                county.Error.ShouldBe("Could not find county with id = 588");
            }
        }
        public override void SeedData()
        {
            base.SeedData();

            using (var context = new VoteMonitorContext(ContextOptions))
            {
                using (var tran = context.Database.BeginTransaction())
                {
                    SeedOngs(context);
                    SeedSectiiDeVotare(context, 1);
                    SeedSectiiDeVotare(context, 2);
                    SeedSectiiDeVotare(context, 3);
                    SeedSectiiDeVotare(context, 4);
                    SeedSectiiDeVotare(context, 5);
                    SeedObservatoriCuRaspunsuri(context, 1);
                    SeedObservatoriCuRaspunsuri(context, 2);
                    SeedObservatoriCuRaspunsuri(context, 3);
                    SeedObservatoriCuRaspunsuri(context, 4);
                    SeedObservatoriCuRaspunsuri(context, 5);
                    SeedObservatoriCuRaspunsuri(context, 6);

                    tran.Commit();
                }
            }
        }
Exemple #7
0
        public async void GetRaspunsuri_GetSectiiCuObservatori_ReturneazaRaspunsPaginat(int page, int pageSize, bool urgent)
        {
            // ARRANGE
            const int idONG = 1; // TODO set the idONG in token and use it as a param for the test
            int       countObservatori;

            using (var context = new VoteMonitorContext(_raspunsuriFixture.ContextOptions))
            {
                countObservatori = await context.Answers
                                   .Where(x => x.Observer.IdNgo == idONG && x.OptionAnswered.Flagged == urgent)
                                   .Select(y =>
                                           new { IdObservator = y.IdObserver, Observator = y.Observer.Name, IdSectie = y.IdPollingStation, Sectie = y.PollingStation.AdministrativeTerritoryCode, DataUltimeiModificari = y.LastModified }
                                           )
                                   .Distinct()
                                   .CountAsync();
            }

            // ACT
            var response = await _client.GetAsync($"api/v1/raspunsuri?page={page}&pagesize={pageSize}&urgent={urgent}");

            // ASSERT
            response.EnsureSuccessStatusCode();
            var model = JsonConvert.DeserializeObject <ApiListResponse <RaspunsModel> >(await response.Content.ReadAsStringAsync());

            Assert.NotNull(model);
            Assert.NotNull(model.Data);
            Assert.True(pageSize >= model.Data.Count);
            Assert.Equal(page, model.Page);
            Assert.Equal(pageSize, model.PageSize);
            Assert.Equal(countObservatori, model.TotalPages);
        }
Exemple #8
0
 private void SetupContextWithPollingStation(Entities.PollingStation pollingStation)
 {
     using (var context = new VoteMonitorContext(_dbContextOptions))
     {
         context.PollingStations.Add(pollingStation);
         context.SaveChanges();
     }
 }
Exemple #9
0
 private void SetupContextWithPollingStations(IEnumerable <Entities.PollingStation> pollingStations)
 {
     using (var context = new VoteMonitorContext(_dbContextOptions))
     {
         context.PollingStations.AddRange(pollingStations);
         context.SaveChanges();
     }
 }
 public virtual void SeedData()
 {
     using (var c = new VoteMonitorContext(ContextOptions))
     {
         c.Database.EnsureCreated();
         c.EnsureSeedData();
     }
 }
        public async Task When_importing_counties_should_insert_records_for_nonexistent_ids_and_update_the_rest()
        {
            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                context.Counties.Add(new County
                {
                    Code     = "Code1",
                    Diaspora = false,
                    Id       = 1,
                    Name     = "Name1",
                    Order    = 12,
                    NumberOfPollingStations = 14
                });
                context.Counties.Add(new County
                {
                    Code = "Code2", Diaspora = true, Id = 3, Name = "Name2", Order = 1, NumberOfPollingStations = 2
                });
                context.SaveChanges();
            }

            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                var countiesCommandHandler = new CountiesCommandHandler(context, _fakeLogger.Object, _mapper);

                StringBuilder sb = new StringBuilder("Id,Code,Name,NumberOfPollingStations,Diaspora,Order");
                sb.Append(Environment.NewLine);
                sb.Append("1,Cluj,Cluuuuuuuuuj,1,TRUE,999");
                sb.Append(Environment.NewLine);
                sb.Append("3,Iasi,Iasi The Best,13,False,5");

                var buffer   = Encoding.UTF8.GetBytes(sb.ToString());
                var formFile = new FormFile(new MemoryStream(buffer), 0, buffer.Length, "Data", "dummy.csv");

                var result = await countiesCommandHandler.Handle(new CreateOrUpdateCounties(formFile), new CancellationToken(false));

                result.IsSuccess.ShouldBeTrue();

                context.Counties.Count().ShouldBe(2);
                var counties   = context.Counties.ToArray();
                var clujCounty = counties[0];
                clujCounty.Id.ShouldBe(1);
                clujCounty.Code.ShouldBe("Cluj");
                clujCounty.Name.ShouldBe("Cluuuuuuuuuj");
                clujCounty.NumberOfPollingStations.ShouldBe(1);
                clujCounty.Diaspora.ShouldBe(true);
                clujCounty.Order.ShouldBe(999);

                var iasiCounty = counties[1];
                iasiCounty.Id.ShouldBe(3);
                iasiCounty.Code.ShouldBe("Iasi");
                iasiCounty.Name.ShouldBe("Iasi The Best");
                iasiCounty.NumberOfPollingStations.ShouldBe(13);
                iasiCounty.Diaspora.ShouldBe(false);
                iasiCounty.Order.ShouldBe(5);
            }
        }
        public async Task When_loading_counties_and_no_data_in_db()
        {
            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                var countiesCommandHandler = new CountiesCommandHandler(context, _fakeLogger.Object, _mapper);
                var result = await countiesCommandHandler.Handle(new GetCountiesForExport(), new CancellationToken(false));

                result.IsSuccess.ShouldBeTrue();
                result.Value.Count.ShouldBe(0);
            }
        }
        public async Task When_loading_all_counties_should_return_them_ordered()
        {
            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                context.Counties.Add(new County {
                    Code = "Code1", Diaspora = false, Id = 1, Name = "Name1", Order = 12, NumberOfPollingStations = 14
                });
                context.Counties.Add(new County {
                    Code = "Code2", Diaspora = true, Id = 2, Name = "Name2", Order = 3, NumberOfPollingStations = 2
                });
                context.Counties.Add(new County {
                    Code = "Code3", Diaspora = true, Id = 3, Name = "Name3", Order = 1, NumberOfPollingStations = 2
                });
                context.SaveChanges();
            }

            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                var countiesCommandHandler = new CountiesCommandHandler(context, _fakeLogger.Object, _mapper);
                var counties =
                    await countiesCommandHandler.Handle(new GetCountiesForExport(), new CancellationToken(false));

                counties.IsSuccess.ShouldBeTrue();

                counties.Value.Count.ShouldBe(3);
                var c1 = counties.Value[0];
                c1.Id.ShouldBe(3);
                c1.Code.ShouldBe("Code3");
                c1.Name.ShouldBe("Name3");
                c1.NumberOfPollingStations.ShouldBe(2);
                c1.Diaspora.ShouldBe(true);
                c1.Order.ShouldBe(1);

                var c2 = counties.Value[1];
                c2.Id.ShouldBe(2);
                c2.Code.ShouldBe("Code2");
                c2.Name.ShouldBe("Name2");
                c2.NumberOfPollingStations.ShouldBe(2);
                c2.Diaspora.ShouldBe(true);
                c2.Order.ShouldBe(3);

                var c3 = counties.Value[2];
                c3.Id.ShouldBe(1);
                c3.Code.ShouldBe("Code1");
                c3.Name.ShouldBe("Name1");
                c3.NumberOfPollingStations.ShouldBe(14);
                c3.Diaspora.ShouldBe(false);
                c3.Order.ShouldBe(12);
            }
        }
        public async Task When_importing_counties_and_file_provided_is_not_csv_should_return_correct_validation_message()
        {
            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                string base64Encoded          = "YmFzZTY0IGVuY29kZWQgc3RyaW5n";
                var    countiesCommandHandler = new CountiesCommandHandler(context, _fakeLogger.Object, _mapper);
                var    memoryStream           = new MemoryStream(System.Convert.FromBase64String(base64Encoded));
                var    formFile = new FormFile(memoryStream, 0, memoryStream.Length, "Data", "dummy.jpg");;
                var    result   = await countiesCommandHandler.Handle(new CreateOrUpdateCounties(formFile), new CancellationToken(false));

                result.IsFailure.ShouldBeTrue();
                result.Error.ShouldBe("No counties to add or update");
            }
        }
Exemple #15
0
        public async Task Handle_WhenPollingStationNotFound_ReturnsFalse()
        {
            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                var sut = new UpdatePollingStationsHandler(context, _mockLogger.Object);

                var requestNonExistingPollingStation = new UpdatePollingStation
                {
                    Id = 5
                };
                var result = await sut.Handle(requestNonExistingPollingStation, new CancellationToken());

                result.Should().Be(false);
            }
        }
        public async Task Handler_WhenPollingStationDoes_NotExist_ReturnsFalse()
        {
            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                var sut = new CheckPollingStationExistsHandler(context, _mockLogger.Object);
                var checkPollingStationExists = new CheckPollingStationExists()
                {
                    Id = 3
                };

                var result = await sut.Handle(checkPollingStationExists, new CancellationToken());

                result.Should().Be(false);
            }
        }
        public async Task When_loading_2_counties_from_db_for_export()
        {
            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                context.Counties.Add(new County
                {
                    Code     = "Code1",
                    Diaspora = false,
                    Id       = 1,
                    Name     = "Name1",
                    Order    = 12,
                    NumberOfPollingStations = 14
                });
                context.Counties.Add(new County
                {
                    Code = "Code2", Diaspora = true, Id = 3, Name = "Name2", Order = 1, NumberOfPollingStations = 2
                });
                context.SaveChanges();
            }

            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                var countiesCommandHandler = new CountiesCommandHandler(context, _fakeLogger.Object, _mapper);
                var exportResult           =
                    await countiesCommandHandler.Handle(new GetCountiesForExport(), new CancellationToken(false));

                exportResult.IsSuccess.ShouldBeTrue();

                exportResult.Value.Count.ShouldBe(2);
                exportResult.Value
                .FirstOrDefault(x => x.Code == "Code1" &&
                                x.Diaspora == false &&
                                x.Id == 1 &&
                                x.Name == "Name1" &&
                                x.Order == 12 &&
                                x.NumberOfPollingStations == 14)
                .ShouldNotBeNull();

                exportResult.Value
                .FirstOrDefault(x => x.Code == "Code2" &&
                                x.Diaspora == true &&
                                x.Id == 3 &&
                                x.Name == "Name2" &&
                                x.Order == 1 &&
                                x.NumberOfPollingStations == 2)
                .ShouldNotBeNull();
            }
        }
Exemple #18
0
        public async Task Handler_CreatesPollingStationInfo()
        {
            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                var sut = new CreatePollingStationInfoHandler(context, new Mapper(_mapperConfiguration), _mockLogger.Object);

                var createPollingStationInfo = new CreatePollingStationInfo()
                {
                    IdPollingStation = 3
                };
                await sut.Handle(createPollingStationInfo, new CancellationToken());

                var savedPollingStationInfo = context.PollingStationInfos.FirstOrDefault(p => p.IdPollingStation == createPollingStationInfo.IdPollingStation);
                savedPollingStationInfo.Should().NotBeNull();
            }
        }
Exemple #19
0
        public async Task Handle_WhenPollingStationFound_ReturnsTrue()
        {
            SetupContextWithPollingStation(new PollingStationBuilder().WithId(5).Build());

            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                var sut = new UpdatePollingStationsHandler(context, _mockLogger.Object);

                var requestExistingPollingStation = new UpdatePollingStation
                {
                    Id = 5
                };
                var result = await sut.Handle(requestExistingPollingStation, new CancellationToken());

                result.Should().Be(true);
            }
        }
Exemple #20
0
        public async void GetRaspunsuri_GetSectiiCuObservatori_ReturneazaRaspunsuriOrdonateDupaDataModificareDesc(int page, int pageSize, bool urgent)
        {
            // ARRANGE
            const int    idONG = 1; // TODO set the idONG in token and use it as a param for the test
            RaspunsModel first, last;

            using (var context = new VoteMonitorContext(_raspunsuriFixture.ContextOptions))
            {
                var sectiiCuObservatori = await context.Answers
                                          .Where(x => x.Observer.IdNgo == idONG && x.OptionAnswered.Flagged == urgent)
                                          .Select(y =>
                                                  new { IdObservator = y.IdObserver, Observator = y.Observer.Name, IdSectie = y.IdPollingStation, Sectie = y.PollingStation.AdministrativeTerritoryCode, DataUltimeiModificari = y.LastModified }
                                                  )
                                          .Distinct()
                                          .OrderByDescending(x => x.DataUltimeiModificari)
                                          .Skip((page - 1) * pageSize)
                                          .Take(pageSize)
                                          .ToListAsync();

                var sectieFirst = sectiiCuObservatori.First();
                var sectieLast  = sectiiCuObservatori.Last();
                first = new RaspunsModel {
                    IdObservator = sectieFirst.IdObservator, IdSectie = sectieFirst.IdSectie
                };
                last = new RaspunsModel {
                    IdObservator = sectieFirst.IdObservator, IdSectie = sectieLast.IdSectie
                };
            }

            // ACT
            var response = await _client.GetAsync($"api/v1/raspunsuri?page={page}&pagesize={pageSize}&urgent={urgent}");

            // ASSERT
            response.EnsureSuccessStatusCode();
            var model = JsonConvert.DeserializeObject <ApiListResponse <RaspunsModel> >(await response.Content.ReadAsStringAsync());

            Assert.NotNull(model);
            Assert.NotNull(model.Data);
            var firstModel = model.Data.First();
            var lastModel  = model.Data.Last();

            Assert.Equal(first.IdObservator, firstModel.IdObservator);
            Assert.Equal(first.IdSectie, firstModel.IdSectie);
            Assert.Equal(last.IdObservator, firstModel.IdObservator);
            Assert.Equal(last.IdObservator, firstModel.IdObservator);
        }
        public async Task When_updating_county_by_existent_id()
        {
            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                context.Counties.Add(new County {
                    Code = "Code1", Diaspora = false, Id = 1, Name = "Name1", Order = 12, NumberOfPollingStations = 14
                });
                context.Counties.Add(new County {
                    Code = "Code2", Diaspora = true, Id = 2, Name = "Name2", Order = 3, NumberOfPollingStations = 2
                });
                context.Counties.Add(new County {
                    Code = "Code3", Diaspora = true, Id = 3, Name = "Name3", Order = 1, NumberOfPollingStations = 2
                });
                context.SaveChanges();
            }

            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                var countiesCommandHandler = new CountiesCommandHandler(context, _fakeLogger.Object, _mapper);
                var updateCountyModel      = new UpdateCountyModel()
                {
                    Name     = "Super Iasi",
                    Code     = "IS",
                    Order    = 33,
                    Diaspora = false,
                    NumberOfPollingStations = 767
                };
                var county =
                    await countiesCommandHandler.Handle(new UpdateCounty(2, updateCountyModel), new CancellationToken(false));

                county.IsSuccess.ShouldBeTrue();
                context.Counties.Count().ShouldBe(3);
                var updatedCounty = await context.Counties.FirstOrDefaultAsync(x => x.Id == 2);

                updatedCounty.ShouldNotBeNull();
                updatedCounty.Id.ShouldBe(2);
                updatedCounty.Code.ShouldBe("IS");
                updatedCounty.Name.ShouldBe("Super Iasi");
                updatedCounty.NumberOfPollingStations.ShouldBe(767);
                updatedCounty.Diaspora.ShouldBe(false);
                updatedCounty.Order.ShouldBe(33);
            }
        }
        public async Task When_importing_counties_should_update_counties_by_id()
        {
            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                context.Counties.Add(new County
                {
                    Code     = "Code1",
                    Diaspora = false,
                    Id       = 3,
                    Name     = "Name1",
                    Order    = 12,
                    NumberOfPollingStations = 14
                });

                context.SaveChanges();
            }

            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                var countiesCommandHandler = new CountiesCommandHandler(context, _fakeLogger.Object, _mapper);

                StringBuilder sb = new StringBuilder("Id,Code,Name,NumberOfPollingStations,Diaspora,Order");
                sb.Append(Environment.NewLine);
                sb.Append("3,Cluj,Cluuuuuuuuuj,1,TRUE,1");

                var buffer   = Encoding.UTF8.GetBytes(sb.ToString());
                var formFile = new FormFile(new MemoryStream(buffer), 0, buffer.Length, "Data", "dummy.csv");


                var result = await countiesCommandHandler.Handle(new CreateOrUpdateCounties(formFile), new CancellationToken(false));

                result.IsSuccess.ShouldBeTrue();

                context.Counties.Count().ShouldBe(1);
                var county = context.Counties.First();
                county.Id.ShouldBe(3);
                county.Code.ShouldBe("Cluj");
                county.Name.ShouldBe("Cluuuuuuuuuj");
                county.NumberOfPollingStations.ShouldBe(1);
                county.Diaspora.ShouldBe(true);
                county.Order.ShouldBe(1);
            }
        }
        public async Task Handler_WhenPollingStationExists_ReturnsTrue()
        {
            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                context.PollingStations.Add(new PollingStationBuilder().WithId(3).Build());
                context.SaveChanges();
            }

            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                var sut = new CheckPollingStationExistsHandler(context, _mockLogger.Object);
                var checkPollingStationExists = new CheckPollingStationExists()
                {
                    Id = 3
                };

                var result = await sut.Handle(checkPollingStationExists, new CancellationToken());

                result.Should().Be(true);
            }
        }
Exemple #24
0
        public async Task Handle_WhenPollingStationFound_UpdatesNumber()
        {
            var id = 3;

            SetupContextWithPollingStation(new PollingStationBuilder().WithId(id).WithNumber(13).Build());

            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                var sut = new UpdatePollingStationsHandler(context, _mockLogger.Object);

                var requestExistingPollingStation = new UpdatePollingStation
                {
                    Id     = id,
                    Number = 27
                };
                await sut.Handle(requestExistingPollingStation, new CancellationToken());

                var updatedPollingStation = context.PollingStations.First(p => p.Id == id);
                updatedPollingStation.Number.Should().Be(27);
            }
        }
Exemple #25
0
        public async Task Handle_WithDefaultPage_ReturnsFirstPageResults()
        {
            SetupContextWithPollingStations(new List <Entities.PollingStation>
            {
                new PollingStationBuilder().WithId(1).Build()
            });

            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                var sut = new GetPollingStationsHandler(context, new Mapper(_mapperConfiguration), _mockLogger.Object);

                var getPollingStations = new GetPollingStations
                {
                    PageSize = 10
                };
                var result = await sut.Handle(getPollingStations, new CancellationToken());

                result.Count().Should().Be(1);
                result.First().Id.Should().Be(1);
            }
        }
Exemple #26
0
        public async Task Handle_WhenPollingStationFound_UpdatesAdministrativeTerritoryCode()
        {
            var id = 3;

            SetupContextWithPollingStation(new PollingStationBuilder().WithId(id).WithAdministrativeTerritoryCode("BC").Build());

            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                var sut = new UpdatePollingStationsHandler(context, _mockLogger.Object);

                var requestExistingPollingStation = new UpdatePollingStation
                {
                    Id = id,
                    AdministrativeTerritoryCode = "IS"
                };
                await sut.Handle(requestExistingPollingStation, new CancellationToken());

                var updatedPollingStation = context.PollingStations.First(p => p.Id == id);
                updatedPollingStation.AdministrativeTerritoryCode.Should().Be("IS");
            }
        }
        public async Task When_importing_counties_and_has_duplicated_indexes_should_not_update_db_and_invalidate_request()
        {
            using (var context = new VoteMonitorContext(_dbContextOptions))
            {
                var countiesCommandHandler = new CountiesCommandHandler(context, _fakeLogger.Object, _mapper);

                StringBuilder sb = new StringBuilder("Id,Code,Name,NumberOfPollingStations,Diaspora,Order");
                sb.Append(Environment.NewLine);
                sb.Append("2,Iasi,Iasi_,1,TRUE,1");
                sb.Append(Environment.NewLine);
                sb.Append("2,Cluj,Cluj_,1,TRUE,1");

                var buffer   = Encoding.UTF8.GetBytes(sb.ToString());
                var formFile = new FormFile(new MemoryStream(buffer), 0, buffer.Length, "Data", "dummy.csv");


                var result = await countiesCommandHandler.Handle(new CreateOrUpdateCounties(formFile), new CancellationToken(false));

                result.IsFailure.ShouldBeTrue();
                result.Error.ShouldBe("Duplicated id in csv found");
                context.Counties.Count().ShouldBe(0);
            }
        }
 public AdminQueryHandler(VoteMonitorContext context, IHashService hash)
 {
     _context = context;
     _hash    = hash;
 }
Exemple #29
0
 public UpdatePollingStationInfoHandler(VoteMonitorContext context, IMapper mapper, ILogger <UpdatePollingStationInfoHandler> logger)
 {
     _context = context;
     _mapper  = mapper;
     _logger  = logger;
 }
 public ObserverRequestsHandler(VoteMonitorContext context, ILogger logger, IHashService hashService)
 {
     _context     = context;
     _logger      = logger;
     _hashService = hashService;
 }