Summary

Class:SampleDotNetCore2RestStub.Repositories.PersonRepository
Assembly:SampleDotNetCore2RestStub
File(s):C:\SampleDotNetCore2RestStub\src\SampleDotNetCore2RestStub\Repositories\PersonRepository.cs
Covered lines:0
Uncovered lines:35
Coverable lines:35
Total lines:57
Line coverage:0%
Branch coverage:0%

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
.ctor()1000
GetById(...)1000
GetAll()1000
GetCount()1000
Remove()2200
Save(...)2200

File(s)

C:\SampleDotNetCore2RestStub\src\SampleDotNetCore2RestStub\Repositories\PersonRepository.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using SampleDotNetCore2RestStub.Models;
 4
 5namespace SampleDotNetCore2RestStub.Repositories
 6{
 7    public class PersonRepository : IPersonRepository
 8    {
 09        private Dictionary<int, Person> _persons = new Dictionary<int, Person>();
 10
 011        public PersonRepository()
 012        {
 013            _persons.Add(1, new Person { Id = 1, FirstName = "FN1", LastName = "LN1", Email = "email1@email.na" });
 014            _persons.Add(2, new Person { Id = 2, FirstName = "FN2", LastName = "LN2", Email = "email2@email.na" });
 015            _persons.Add(3, new Person { Id = 3, FirstName = "FN3", LastName = "LN3", Email = "email3@email.na" });
 016            _persons.Add(4, new Person { Id = 4, FirstName = "FN4", LastName = "LN4", Email = "email4@email.na" });
 017        }
 18
 19        public Person GetById(int id)
 020        {
 021            return _persons[id];
 022        }
 23
 24        public List<Person> GetAll()
 025        {
 026            return _persons.Values.ToList();
 027        }
 28
 29        public int GetCount()
 030        {
 031            return _persons.Count();
 032        }
 33
 34        public void Remove()
 035        {
 036            if (_persons.Keys.Any())
 037            {
 038                _persons.Remove(_persons.Keys.Last());
 039            }
 040        }
 41
 42        public string Save(Person person)
 043        {
 044            var result = "";
 045            if (_persons.ContainsKey(person.Id))
 046            {
 047                result = "Updated Person with id=" + person.Id;
 048            }
 49            else
 050            {
 051                result = "Added Person with id=" + person.Id;
 052            }
 053            _persons.Add(person.Id, person);
 054            return result;
 055        }
 56    }
 57}