public void should_vote_twice_in_candidate_Jose() { // Dado / Setup // OBJETO Election var election = new Election(); var candidateAna = new Candidates("Ana", "154.585.256-58"); var candidateJose = new Candidates("Jose", "145.845.848-47"); var candidates = new List <Candidates>() { candidateAna, candidateJose }; election.CreateCandidates(candidates, "Pa$$w0rd"); var joseId = election.GetCandidateIdByCpf(candidateAna.Cpf); var anaId = election.GetCandidateIdByCpf(candidateJose.Cpf); // Quando / Ação // Estamos acessando o MÉTODO ShowMenu do OBJETO Election election.Vote(joseId); election.Vote(joseId); // Deve / Asserções var candidateJosee = election.Candidates.First(x => x.Id == joseId); var candidateAnaa = election.Candidates.First(x => x.Id == anaId); Assert.True(candidateAnaa.Votes == 0); Assert.True(candidateJosee.Votes == 2); }
public void Should_return_both_candidates_when_occurs_draw() { // Dado / Setup // OBJETO election var election = new Election(); var Jose = new Candidate("José", "895.456.214-78"); var Ana = new Candidate("Ana", "456.456.214-78"); var candidates = new List <Candidate> { Jose, Ana }; election.CreateCandidates(candidates, "Pa$$w0rd"); // Quando / Ação // Estamos acessando o MÉTODO ShowMenu do OBJETO election election.Vote(Ana.CPF); election.Vote(Jose.CPF); var winners = election.GetWinners(); // Deve / Asserções var candidateJose = winners.Find(x => x.Id == Jose.Id); var candidateAna = winners.Find(x => x.Id == Ana.Id); Assert.Equal(1, candidateJose.Votes); Assert.Equal(1, candidateAna.Votes); }
public void should_return_Ana_as_winner_when_only_Ana_receives_votes() { // Dado / Setup // OBJETO Election var election = new Election(); var candidateAna = new Candidates("Ana", "154.585.256-58"); var candidateJose = new Candidates("Jose", "145.845.848-47"); var candidates = new List <Candidates>() { candidateAna, candidateJose }; election.CreateCandidates(candidates, "Pa$$w0rd"); var anaId = election.GetCandidateIdByCpf(candidateAna.Cpf); // Quando / Ação // Estamos acessando o MÉTODO ShowMenu do OBJETO Election election.Vote(anaId); election.Vote(anaId); var winners = election.GetWinners(); // Deve / Asserções Assert.True(winners.Count == 1); Assert.Equal(anaId, winners[0].Id); Assert.Equal(2, winners[0].Votes); }
public void should_return_both_candidates_when_occurs_draw() { // Dado / Setup // OBJETO Election var election = new Election(); var candidateAna = new Candidates("Ana", "154.585.256-58"); var candidateJose = new Candidates("Jose", "145.845.848-47"); var candidates = new List <Candidates>() { candidateAna, candidateJose }; election.CreateCandidates(candidates, "Pa$$w0rd"); var joseId = election.GetCandidateIdByCpf(candidateJose.Cpf); var anaId = election.GetCandidateIdByCpf(candidateAna.Cpf); // Quando / Ação election.Vote(anaId); election.Vote(joseId); var winners = election.GetWinners(); // Deve / Asserções var candidateJosee = winners.Find(x => x.Cpf == candidateJose.Cpf); var candidateAnaa = winners.Find(x => x.Cpf == candidateAna.Cpf); Assert.Equal(1, candidateJose.Votes); Assert.Equal(1, candidateAna.Votes); }
public void Should_return_False_and_not_Vote_if_cpf_is_invalid() { var election = new Election(); var candidateRodrigo = new Candidate("Rodrigo", "910.371.860-36", 0); var candidateMaria = new Candidate("Maria", "764.122.990-50", 0); var cantidatesList = new List<Candidate>() { candidateRodrigo, candidateMaria }; //When election.CreateCandidates(cantidatesList, "Pa$$w0rd"); // cria-se candidatos var rodrigoId = election.GetCandidateIdByName("Rodrigo"); var mariaId = election.GetCandidateIdByName("Maria"); //To vote candidateRodrigo.Vote(); candidateMaria.Vote(); // Quando / Ação var winners = election.GetWinners(); // Deve / Asserções Assert.Equal(election.Candidate.ElementAt(0).Id, winners[0].Id); Assert.Equal(election.Candidate.ElementAt(1).Id, winners[1].Id); Assert.Equal(election.Candidate.ElementAt(0).Votes, 1); //Should election.Candidate.ElementAt(0).Votes.ShouldEqual(1); election.Candidate.ElementAt(0).Votes.ShouldNotBeSameAs(election.Candidate.ElementAt(1).Votes); }
public void should_return_different_ids() { //Given var election = new Election(); var candidateJose = new Candidate("José", "588.998.190-00", 0); var candidateMaria = new Candidate("Maria", "400.303.750-29", 0); var cantidatesList = new List<Candidate>() { candidateJose, candidateMaria }; //When var candidates = election.CreateCandidates(cantidatesList, "Pa$$w0rd"); // cria-se candidatos //joseId recebe o retorno do metodo GetCandidateIdByName por meio do election var joseId = election.GetCandidateIdByName("José"); var mariaId = election.GetCandidateIdByName("Maria"); //Then Assert.NotEqual(joseId, mariaId); }
public void Should_Retunr_names_of_repeat_Candidates() { //Given // criando candidatos var election = new Election(); var candidateRodrigo = new Candidate("Rodrigo", "922.736.560-50", 0); var candidateMaria = new Candidate("Maria", "573.225.920-18", 0); var cantidatesList = new List<Candidate>() { candidateRodrigo, candidateMaria }; election.CreateCandidates(cantidatesList, "Pa$$w0rd"); // cria-se candidatos // When var input = new List<string> { "Rodrigo" }; var result = election.ReturnRepeatNames(input); var expected = new List<string> { "Rodrigo" }; // Then Assert.Equal(expected, result); }
public void should_return_Ana_as_winner_when_only_Ana_receives_votes() { // Dado / Setup // OBJETO election var election = new Election(); var fernando = new Candidate("Fernando", "111.111.111-11"); var ana = new Candidate("Ana", "222.222.222-22"); var candidates = new List <Candidate> { fernando, ana }; election.CreateCandidates(candidates, "Pa$$w0rd"); var anaId = election.GetCandidateIdByCpf(ana.Cpf); // Quando / Ação // Estamos acessando o MÉTODO ShowMenu do OBJETO election election.Vote(ana.Cpf); election.Vote(ana.Cpf); var winners = election.GetWinners(); // Deve / Asserções Assert.Equal(1, winners.Count); Assert.Equal(anaId, winners[0].Id); Assert.Equal(2, winners[0].Votes); }
public void should_return_both_candidates_when_occurs_draw() { // Dado / Setup // OBJETO election var election = new Election(); var fernando = new Candidate("Fernando", "111.111.111-11"); var ana = new Candidate("Ana", "222.222.222-22"); var candidates = new List <Candidate> { fernando, ana }; election.CreateCandidates(candidates, "Pa$$w0rd"); var fernandoId = election.GetCandidateIdByCpf(fernando.Cpf); var anaId = election.GetCandidateIdByCpf(ana.Cpf); // Quando / Ação // Estamos acessando o MÉTODO ShowMenu do OBJETO election election.Vote(ana.Cpf); election.Vote(fernando.Cpf); var winners = election.GetWinners(); // Deve / Asserções var candidateFernando = winners.Find(x => x.Id == fernandoId); var candidateAna = winners.Find(x => x.Id == anaId); Assert.Equal(1, candidateFernando.Votes); Assert.Equal(1, candidateAna.Votes); }
public void Should_vote_twice_in_candidate_Jose() { // Dado / Setup // OBJETO election var election = new Election(); var Jose = new Candidate("José", "895.456.214-78"); var Ana = new Candidate("Ana", "456.456.214-78"); var candidates = new List <Candidate> { Jose, Ana }; election.CreateCandidates(candidates, "Pa$$w0rd"); // Quando / Ação // Estamos acessando o MÉTODO ShowMenu do OBJETO election election.Vote(Jose.CPF); election.Vote(Jose.CPF); // Deve / Asserções var candidateJose = election.Candidates.First(x => x.Id == Jose.Id); var candidateAna = election.Candidates.First(x => x.Id == Ana.Id); Assert.Equal(2, candidateJose.Votes); Assert.Equal(0, candidateAna.Votes); }
public void should_create_candidates_when_password_is_correct() { //Given var election = new Election(); var candidateRodrigo = new Candidates("Rodrigo", "000.123.452-00", 0); var candidateMaria = new Candidates("Maria", "112.342.543-88", 0); var cantidatesList = new List <Candidates>() { candidateRodrigo, candidateMaria }; // When //acessa o metodo CreateCandidates por meio do selection, com os dados e o pass var created = election.CreateCandidates(cantidatesList, "Pa$$w0rd"); // Then // candidatos devem ser criados Assert.True(created); // Estamos acessando a PROPRIEDADE Candidates, que faz parte do ESTADO do OBJETO election Assert.True(election.Candidates.Count == 2); //assegura que a pos 0 nome e igual ao nome do candidato 1 Assert.True(election.Candidates.ElementAt(0).Name == candidateRodrigo.Name); //assegura q a pos 1 do noome e igual ao nome do candidato2 Assert.True(election.Candidates.ElementAt(1).Name == candidateMaria.Name); //asegura que os nomes são diferentes Assert.True(election.Candidates.ElementAt(1).Name != election.Candidates.ElementAt(0).Name); //assegura que os candidatos não possuem votos Assert.True(election.Candidates.ElementAt(1).Votes == 0); Assert.True(election.Candidates.ElementAt(0).Votes == 0); //assegura que os ids são diferentes Assert.True(election.Candidates.ElementAt(1).Id != election.Candidates.ElementAt(0).Id); Assert.True(election.Candidates.ElementAt(1).Id != election.Candidates.ElementAt(0).Id); }
public void should_return_3_votes_for_rafael_and_1_vote_for_fernanda() { // Dado / Setup var election = new Election(); var rafael = new Candidate("Rafael", "123.456.789.10"); var fernanda = new Candidate("Fernanda", "109.876.543.21"); var candidatesInput = new List <Candidate> { rafael, fernanda }; election.CreateCandidates(candidatesInput, "Pa$$w0rd"); // Quando / Ação election.Vote(rafael.Cpf); election.Vote(rafael.Cpf); election.Vote(rafael.Cpf); election.Vote(fernanda.Cpf); // Deve / Asserções var candidateRafael = election.Candidates.First(x => x.Cpf == rafael.Cpf); var candidateFernanda = election.Candidates.First(x => x.Cpf == fernanda.Cpf); Assert.Equal(3, candidateRafael.Votes); Assert.Equal(1, candidateFernanda.Votes); }
public void should_return_Rodrigo_as_winner_when_only_Rodrigo_receives_votes() { //Given var election = new Election(); var candidateRodrigo = new Candidates("Rodrigo", "000.123.452-00", 0); var candidateMaria = new Candidates("Maria", "112.342.543-88", 0); var cantidatesList = new List <Candidates>() { candidateRodrigo, candidateMaria }; //When election.CreateCandidates(cantidatesList, "Pa$$w0rd"); // cria-se candidatos //joseId recebe o retorno do metodo GetCandidateIdByName por meio do election var rodrigoId = election.GetCandidateIdByName("Rodrigo"); var mariaId = election.GetCandidateIdByName("Maria"); // Given candidateRodrigo.Vote(); candidateRodrigo.Vote(); // election.Vote(election.Candidates.ElementAt(0).Id); // election.Vote(election.Candidates.ElementAt(0).Id); // When var winners = election.GetWinners(); //Then Assert.True(winners.Count == 1); Assert.Equal(election.Candidates.ElementAt(0).Id, winners[0].Id); Assert.Equal(2, winners[0].Votes); }
public void should_return_both_candidates_when_occurs_draw() { var election = new Election(); var jose = new Candidate("José", "009.923.970-14"); var ana = new Candidate("Ana", "852.710.650-73"); var candidates = new List <Candidate> { jose, ana }; election.CreateCandidates(candidates, "Pa$$w0rd"); var joseId = election.GetCandidateIdByName("José"); var anaId = election.GetCandidateIdByName("Ana"); ana.Vote(); jose.Vote(); var winners = election.GetWinners(); var candidateJose = winners.Find(x => x.Id == joseId); var candidateAna = winners.Find(x => x.Id == anaId); Assert.Equal(1, candidateJose.Votes); Assert.Equal(1, candidateAna.Votes); }
public void should_vote_twice_in_candidate_Jose() { //Given var election = new Election(); var candidateRodrigo = new Candidates("Rodrigo", "000.123.452-00", 0); var candidateMaria = new Candidates("Maria", "112.342.543-88", 0); var cantidatesList = new List <Candidates>() { candidateRodrigo, candidateMaria }; //When election.CreateCandidates(cantidatesList, "Pa$$w0rd"); // cria-se candidatos //joseId recebe o retorno do metodo GetCandidateIdByName por meio do election var rodrigoId = election.GetCandidateIdByName("Rodrigo"); var mariaId = election.GetCandidateIdByName("Maria"); //when candidateRodrigo.Vote(); candidateRodrigo.Vote(); // election.Vote(election.Candidates.ElementAt(0).Id); // election.Vote(election.Candidates.ElementAt(0).Id); //Then Assert.Equal(2, election.Candidates.ElementAt(0).Votes); Assert.Equal(0, election.Candidates.ElementAt(1).Votes); }
public void Should_Retunr_names_of_repeat_Candidates() { //Given // criando candidatos var election = new Election(); var candidateRodrigo = new Candidates("Rodrigo", "000.123.452-00", 0); var candidateMaria = new Candidates("Maria", "112.342.543-88", 0); var cantidatesList = new List <Candidates>() { candidateRodrigo, candidateMaria }; election.CreateCandidates(cantidatesList, "Pa$$w0rd"); // cria-se candidatos // When var input = new List <string> { "Rodrigo" }; var result = election.ReturnRepeatNames(input); var expected = new List <string> { "Rodrigo" }; // Then Assert.Equal(expected, result); }
public void should_vote_twice_in_candidate_José() { var election = new Election(); var jose = new Candidate("José", "009.923.970-14"); var ana = new Candidate("Ana", "852.710.650-73"); var candidates = new List <Candidate>() { jose, ana }; election.CreateCandidates(candidates, "Pa$$w0rd"); var joseId = election.GetCandidateIdByName(jose.Name); var anaId = election.GetCandidateIdByName(ana.Name); jose.Vote(); jose.Vote(); var candidateJose = election.Candidates.First(x => x.Id == joseId); var candidateAna = election.Candidates.First(x => x.Id == anaId); Assert.Equal(2, candidateJose.Votes); Assert.Equal(0, candidateAna.Votes); }
public void should_return_both_candidates_when_occurs_draw() { var election = new Election(); var candidateRodrigo = new Candidates("Rodrigo", "000.123.452-00", 0); var candidateMaria = new Candidates("Maria", "112.342.543-88", 0); var cantidatesList = new List <Candidates>() { candidateRodrigo, candidateMaria }; //When election.CreateCandidates(cantidatesList, "Pa$$w0rd"); // cria-se candidatos var rodrigoId = election.GetCandidateIdByName("Rodrigo"); var mariaId = election.GetCandidateIdByName("Maria"); //To vote candidateRodrigo.Vote(); candidateMaria.Vote(); // Quando / Ação var winners = election.GetWinners(); // Deve / Asserções Assert.Equal(election.Candidates.ElementAt(0).Id, winners[0].Id); Assert.Equal(election.Candidates.ElementAt(1).Id, winners[1].Id); Assert.Equal(election.Candidates.ElementAt(0).Votes, 1); //Should election.Candidates.ElementAt(0).Votes.ShouldEqual(1); election.Candidates.ElementAt(0).Votes.ShouldNotBeSameAs(election.Candidates.ElementAt(1).Votes); }
public void Should_assertions() { // Dado / Setup var election = new Election(); var candidateRodrigo = new Candidates("Rodrigo", "000.123.452-00", 0); var candidateMaria = new Candidates("Maria", "112.342.543-88", 0); var cantidatesList = new List <Candidates>() { candidateRodrigo, candidateMaria }; //When election.CreateCandidates(cantidatesList, "Pa$$w0rd"); // cria-se candidatos var result = election.GetCandidateIdBycpf(candidateRodrigo.Cpf); // Should election.Candidates.ElementAt(0).ShouldBeType(typeof(Candidates)); election.Candidates.ElementAt(0).Id.ShouldEqual(result); // object obj = null; // obj.ShouldBeNull(); // obj = new object(); // obj.ShouldNotBeNull(); // obj.ShouldNotBeSameAs(new object()); // obj.ShouldNotBeType(typeof(string)); // obj.ShouldNotEqual("foo"); // obj = "x"; // obj.ShouldNotBeInRange("y", "z"); // obj.ShouldBeInRange("a", "z"); // obj.ShouldBeSameAs("x"); // "This String".ShouldContain("This"); // "This String".ShouldNotBeEmpty(); // "This String".ShouldNotContain("foobar"); // false.ShouldBeFalse(); // true.ShouldBeTrue(); // var list = new List<object>(); // list.ShouldBeEmpty(); // list.ShouldNotContain(new object()); // var item = new object(); // list.Add(item); // list.ShouldNotBeEmpty(); // list.ShouldContain(item); }
public void Should_Not_Create_A_Candidate() { //Given var openElections = new Election(); var candidatesForElection = PreCandidatesFactory(); //When var result = openElections.CreateCandidates(candidatesForElection, "wrongPasswrd"); //Then Assert.Null(openElections.Candidates); Assert.False(result); }
public void Should_Create_A_Candidate() { //Given var openElections = new Election(); var candidatesForElection = PreCandidatesFactory(); //When var result = openElections.CreateCandidates(candidatesForElection, "Pa$$w0rd"); //Then Assert.True(result); Assert.Equal(candidatesForElection.Count, openElections.Candidates.Count); }
public void should_return_empty_if_null_input() { // Dado / Setup var election = new Election(); List <Candidate> candidatesInput = null; // Quando / Ação bool result = election.CreateCandidates(candidatesInput, "anything"); // Deve / Asserções Assert.False(result); Assert.Empty(election.Candidates); }
public void Should_Return_True_Trying_To_Vote_In_Shuri() { //Given var openElections = new Election(); var candidatesForElection = PreCandidatesFactory(); var subscribedForElection = openElections.CreateCandidates(candidatesForElection, "Pa$$w0rd"); //When var result = openElections.VoteCandidateByCpf("112.346.543-88"); // //Then Assert.False(result); }
public void should_return_differents_id_for_same_names() { var election = new Election(); var candidates = new List <Candidate> { new Candidate("José", "009.923.970-14"), new Candidate("José", "852.710.650-73") }; election.CreateCandidates(candidates, "Pa$$w0rd"); var candidatesSameName = election.GetCandidatesIdWithSameNames("José"); Assert.NotEqual(candidatesSameName[0], candidatesSameName[1]); }
public void should_return_id_by_cpf() { var election = new Election(); var candidates = new List <Candidate> { new Candidate("José", "009.923.970-14"), new Candidate("José", "852.710.650-73") }; election.CreateCandidates(candidates, "Pa$$w0rd"); var candidate = election.GetCandidateIdByCPF("852.710.650-73"); Assert.Equal(candidate, election.Candidates.ElementAt(1).Id); }
public void Should_Register_A_Third_Candidate() { //Given var openElections = new Election(); var candidatesForElection = PreCandidatesFactory(); var candidateShuriSegunda = new Candidate("Shuri", "145.098.756-98"); candidatesForElection.Add(candidateShuriSegunda); //When var subscribedForElection = openElections.CreateCandidates(candidatesForElection, "Pa$$w0rd"); //Then Assert.True(subscribedForElection); Assert.Equal(candidatesForElection.Count, openElections.Candidates.Count); }
public void Should_Show_The_Candidates_Subscribed_For_Election() { //Given var openElections = new Election(); var candidatesForElection = PreCandidatesFactory(); var subscribedForElection = openElections.CreateCandidates(candidatesForElection, "Pa$$w0rd"); //When var showedCandidates = openElections.ShowCandidates(); //Then Assert.Equal($"Vote {candidatesForElection[0].Id} for candidate {candidatesForElection[0].Name}", showedCandidates[0]); Assert.Equal($"Vote {candidatesForElection[1].Id} for candidate {candidatesForElection[1].Name}", showedCandidates[1]); }
public void should_not_create_candidates_when_password_is_incorrect() { // Dado / Setup var election = new Election(); var candidate = new List <Candidate> { new Candidate("José", "009.923.970-14") }; // Quando / Ação var created = election.CreateCandidates(candidate, "incorrect"); // Deve / Asserções Assert.Null(election.Candidates); Assert.False(created); }
public void should_not_generate_same_id_for_both_candidates() { var election = new Election(); var candidates = new List <Candidate> { new Candidate("José", "009.923.970-14"), new Candidate("Ana", "852.710.650-73") }; election.CreateCandidates(candidates, "Pa$$w0rd"); // Quando / Ação var candidateJose = election.Candidates.ElementAt(0).Id; var candidateAna = election.Candidates.ElementAt(1).Id; // Deve / Asserções Assert.NotEqual(candidateAna, candidateJose); }
public void Should_Return_Second_Shuri_ID_Search_By_Her_CPF() { //Given var openElections = new Election(); var candidatesForElection = PreCandidatesFactory(); var candidateShuriSecond = new Candidate("Shuri", "145.098.756-98"); candidatesForElection.Add(candidateShuriSecond); var subscribedForElection = openElections.CreateCandidates(candidatesForElection, "Pa$$w0rd"); //When var shuriSegundaId = openElections.GetCandidateIdByCpf("145.098.756-98"); //Then Assert.Equal(candidateShuriSecond.Id, shuriSegundaId); }