-
Notifications
You must be signed in to change notification settings - Fork 2
/
Repository.cs
41 lines (31 loc) · 1012 Bytes
/
Repository.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Collections.Generic;
namespace LicensePlates
{
interface ILicensePlateRepository
{
bool IsAvailable(string number);
void Save(string number);
int CountRegisteredPlates();
}
class RepositoryException : Exception { };
class FakeLicensePlateRepository : ILicensePlateRepository
{
private readonly List<string> _registered = new List<string>();
public int CountRegisteredPlates() => _registered.Count;
public bool IsAvailable(string number)
{
// Simulation of database error is some cases
if (number == "XXX 666")
throw new RepositoryException();
return !_registered.Contains(number);
}
public void Save(string number)
{
// Simulation of database error is some cases
if (number == "YYY 666")
throw new RepositoryException();
_registered.Add(number);
}
}
}