You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.7 KiB
C#
64 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace xUnitStudy.Model
|
|
{
|
|
/// <summary>
|
|
/// 测试方法共享对象实例
|
|
/// </summary>
|
|
public class ClassFixtureDemo : IDisposable
|
|
{
|
|
public int CallTimes { get; private set; }
|
|
public List<Person> Persons;
|
|
public ClassFixtureDemo()
|
|
{
|
|
Persons = new List<Person>()
|
|
{
|
|
new Person(){ Id=1, FirstName="first1",LastName="last1" },
|
|
new Person(){ Id=2, FirstName="first2",LastName="last2" },
|
|
new Person(){ Id=3, FirstName="first3",LastName="last3" },
|
|
};
|
|
}
|
|
|
|
public (bool result, Person person) AddPerson(Person person)
|
|
{
|
|
CallTimes += 1;
|
|
|
|
var exist = Persons.FirstOrDefault(p => p.Id == person.Id);
|
|
if (exist == null)
|
|
{
|
|
Persons.Add(person);
|
|
return ValueTuple.Create(true, person);
|
|
}
|
|
else
|
|
{
|
|
return ValueTuple.Create(false, person);
|
|
}
|
|
}
|
|
|
|
public (bool result, Person person) RemovePerson(Person person)
|
|
{
|
|
CallTimes += 1;
|
|
|
|
var exist = Persons.FirstOrDefault(p => p.Id == person.Id);
|
|
if (exist == null)
|
|
{
|
|
return ValueTuple.Create(false, person);
|
|
}
|
|
else
|
|
{
|
|
Persons.Remove(exist);
|
|
return ValueTuple.Create(true, exist);
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Persons = null;
|
|
}
|
|
}
|
|
}
|