Summary

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

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()
 12        {
 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" });
 17        }
 18
 19        public Person GetById(int id)
 20        {
 021            return _persons[id];
 22        }
 23
 24        public List<Person> GetAll()
 25        {
 026            return _persons.Values.ToList();
 27        }
 28
 29        public int GetCount()
 30        {
 031            return _persons.Count();
 32        }
 33
 34        public void Remove()
 35        {
 036            if (_persons.Keys.Any())
 37            {
 038                _persons.Remove(_persons.Keys.Last());
 39            }
 40        }
 41
 42        public string Save(Person person)
 43        {
 044            if (_persons.ContainsKey(person.Id))
 45            {
 046                _persons[person.Id] = person;
 047                return "Updated Person with id=" + person.Id;
 48            }
 49            else
 50            {
 051                _persons.Add(person.Id, person);
 052                return "Added Person with id=" + person.Id;
 53            }
 54        }
 55    }
 56}

Methods/Properties

.ctor
GetById
GetAll
GetCount
Remove
Save