Beispiel #1
0
        public void Remove(Analysis analysis)
        {
            const string query = "DELETE FROM Analysis WHERE AnalysisId=AnalysisId";
            var command = new SqlCommand(query);

            command.Parameters.AddWithValue("@AnalysisId", analysis.Id);

            _databaseProvider.PushData(command);
        }
Beispiel #2
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));
        }
Beispiel #3
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));
        }
Beispiel #4
0
        private bool AnalyzesAreEqual(Analysis first, Analysis second)
        {
            bool result = true;
            result &= TemplatesAreEqual(first.Template, second.Template);
            result &= PersonsAreEqual(first.Person, second.Person);
            result &= (first.CreationTime.CompareTo(second.CreationTime) == 1);

            return result;
        }
Beispiel #5
0
        public void Save(ref Analysis analysis)
        {
            var command = new SqlCommand
            {
                CommandType = CommandType.StoredProcedure,
                CommandText = "SaveAnalysisAnGetId"
            };

            AddMainParameters(command, analysis);
            command.Parameters["@AnalysisId"].Direction = ParameterDirection.Output;

            SqlParameterCollection parameters = _databaseProvider.PushDataWithOutputParameters(command);
            int id = int.Parse(parameters["@AnalysisId"].Value.ToString());

            analysis = new Analysis(analysis.Template, analysis.Person, id);
        }
Beispiel #6
0
        private void AddMainParameters(SqlCommand command, Analysis analysis)
        {
            command.Parameters.Add("@PersonId", SqlDbType.Int);
            command.Parameters["@PersonId"].Value = analysis.GetPersonId();

            command.Parameters.Add("@TemplateName", SqlDbType.NVarChar);
            command.Parameters["@TemplateName"].Value = analysis.GetTemplateName();

            command.Parameters.Add("@Analysis", SqlDbType.NText);
            command.Parameters["@Analysis"].Value = new JsonFormatter().ToJson(analysis);

            command.Parameters.Add("@AnalysisId", SqlDbType.Int);
        }
Beispiel #7
0
        public void Update(Analysis analysis)
        {
            const string query = "UPDATE Analysis SET Analysis= @Analysis WHERE AnalysisId = @AnalysisId";
            var command = new SqlCommand(query);

            command.Parameters.Add("@@Analysis", SqlDbType.NText);
            command.Parameters["@@Analysis"].Value = new JsonFormatter().ToJson(analysis);
            command.Parameters.AddWithValue("@AnalysisId", analysis.Id);

            _databaseProvider.PushData(command);
        }