示例#1
0
 public Analysis(Template template, Person person)
 {
     _data = new Dictionary<string, string>();
     Template = template;
     Person = person;
     CreationTime = DateTime.Now;
 }
示例#2
0
        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);
        }
示例#3
0
        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));
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
        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));
        }
示例#8
0
        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]));
        }
示例#9
0
 private bool PersonsAreEqual(Person first, Person second)
 {
     return
         first.BirthDate.Equals(second.BirthDate) &
         first.FirstName.Equals(second.FirstName) &
         first.MiddleName.Equals(second.MiddleName);
 }
示例#10
0
        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);
        }
示例#11
0
        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);
        }
示例#12
0
 internal Analysis(Template template, Person person, int id)
     : this(template, person)
 {
     Id = id;
 }
示例#13
0
 private void SavePerson(Person person)
 {
     var personProvider = new PersonProvider(new DatabaseProvider());
     personProvider.Save(ref person);
 }
示例#14
0
        public static Person BuidPerson(string fistName, string lastName, string middleName, DateTime birthDate)
        {
            var person = new Person(fistName, lastName, middleName, birthDate);

            return person;
        }