public Analysis(Template template, Person person) { _data = new Dictionary<string, string>(); Template = template; Person = person; CreationTime = DateTime.Now; }
public void Remove(Person person) { const string query = "DELETE FROM Analysis WHERE PersonId=@PersonId"; var command = new SqlCommand(query); command.Parameters.AddWithValue("@PersonId", person.Id); _databaseProvider.PushData(command); }
public void Analysis_ToAndFromJson_AnalysisIsProperlyDeserialized(string firstName, string lastName, string middleName, string birthDate) { var template = new Template("имя шаблона", "содержимое"); var person = new Person(firstName, lastName, middleName, DateTime.Parse(birthDate)); var jsonFormatter = new JsonFormatter(); var expectedAnalysis = new Analysis(template, person); var actualAnalysis = jsonFormatter.FromJson<Analysis>(jsonFormatter.ToJson(expectedAnalysis)); Assert.True(AnalyzesAreEqual(expectedAnalysis, actualAnalysis)); }
public void Remove(Person person) { new AnalysisProvider(_databaseProvider).Remove(person); const string query = "DELETE FROM Persons WHERE PersonId=@PersonId"; var command = new SqlCommand(query); command.Parameters.Add("@PersonId", SqlDbType.Int); command.Parameters["@PersonId"].Value = person.Id; _databaseProvider.PushData(command); }
public IList<Analysis> Load(Person person) { const string query = "SELECT Analysis, AnalysisId FROM Analysis WHERE PersonId = @PersonId"; var command = new SqlCommand(query); command.Parameters.AddWithValue("@PersonId", person.Id); SqlDataReader reader = _databaseProvider.GetData(command); return GetAnalyzes(reader); }
public void Save(ref Person person) { var command = new SqlCommand { CommandType = CommandType.StoredProcedure, CommandText = "SavePersonAndGetId" }; AddMainParameters(command, person); command.Parameters["@PersonId"].Direction = ParameterDirection.Output; var parameters = _databaseProvider.PushDataWithOutputParameters(command); var id = int.Parse(parameters["@PersonId"].Value.ToString()); person = new Person(id, person.FirstName, person.LastName, person.MiddleName, person.BirthDate); }
public void AnalysisProvider_PersonAnalyzesArePropelyLoaded_ShouldPass(string firstName, string lastName, string middleName, string birthDate) { var person = new Person(firstName, lastName, middleName, DateTime.Parse(birthDate)); _personProvider.Save(ref person); var template = new Template("name" + firstName, "content"); _templateProvider.Save(template); var expectedAnalysis = new Analysis(template, person); _analysisProvider.Save(ref expectedAnalysis); var analyzes = _analysisProvider.Load(person); _analysisProvider.Remove(expectedAnalysis); _personProvider.Remove(person); _templateProvider.Remove(template); var actualAnalysis = analyzes[0]; Assert.True(analyzes.Count() == 1); Assert.True(AnalyzesAreEqual(expectedAnalysis, actualAnalysis)); }
public void PersonProvider_SaveAndSearch_ShouldPass(string firstName, string lastName, string middleName, string birthDate) { var person = new Person(firstName, lastName, middleName, DateTime.Parse(birthDate)); _personProvider.Save(ref person); var loadedPerson = _personProvider.Search(firstName, lastName); _personProvider.Remove(person); Assert.True(PersonsAreEqual(person, loadedPerson[0])); }
private bool PersonsAreEqual(Person first, Person second) { return first.BirthDate.Equals(second.BirthDate) & first.FirstName.Equals(second.FirstName) & first.MiddleName.Equals(second.MiddleName); }
private void AddMainParameters(SqlCommand command, Person person) { command.Parameters.Add("@FirstName", SqlDbType.NVarChar); command.Parameters["@FirstName"].Value = person.FirstName; command.Parameters.Add("@LastName", SqlDbType.NVarChar); command.Parameters["@LastName"].Value = person.LastName; command.Parameters.Add("@MiddleName", SqlDbType.NVarChar); command.Parameters["@MiddleName"].Value = person.MiddleName; command.Parameters.Add("@BirthDate", SqlDbType.VarChar); command.Parameters["@BirthDate"].Value = person.BirthDate.ToShortDateString(); command.Parameters.Add("@PersonId", SqlDbType.Int); }
public void Update(Person person) { const string query = "UPDATE Persons SET FirstName = @FirstName, LastName=@LastName, MiddleName=@MiddleName, " + "BirthDate=@BirthDate WHERE PersonId=@PersonId"; var command = new SqlCommand(query); AddMainParameters(command, person); command.Parameters["@PersonId"].Value = person.Id; _databaseProvider.PushData(command); }
internal Analysis(Template template, Person person, int id) : this(template, person) { Id = id; }
private void SavePerson(Person person) { var personProvider = new PersonProvider(new DatabaseProvider()); personProvider.Save(ref person); }
public static Person BuidPerson(string fistName, string lastName, string middleName, DateTime birthDate) { var person = new Person(fistName, lastName, middleName, birthDate); return person; }