Exemplo n.º 1
0
        public void EndToEnd()
        {
            using (var connection = DatabaseHelper.CreateAndOpenConnection())
            {
                // Arrange
                var targetSchema = SqlTableSchema.LoadFromDatabase(connection, "TestUpsert", "ident");

                var columnMappings = new Dictionary<string, Func<TestDto, object>>
                                        {
                                            {"ident", d => d.Ident},
                                            {"key_part_1", d => d.KeyPart1},
                                            {"key_part_2", d => d.KeyPart2},
                                            {"nullable_text", d => d.Text},
                                            {"nullable_number", d => d.Number},
                                            {"nullable_datetimeoffset", d => d.Date},
                                        };

                Action<TestDto, int> identUpdater = (d, i) => d.Ident = i;

                var upserter = new TypedUpserter<TestDto>(targetSchema, columnMappings, identUpdater);

                var items = new List<TestDto>();

                for (int i = 1; i <= 10; i++)
                {
                    items.Add(
                        new TestDto
                            {
                                Ident = null,
                                KeyPart1 = "TEST",
                                KeyPart2 = (short)i,
                                Text = String.Format("some text here {0}", i),
                                Number = i,
                                Date = new DateTimeOffset(new DateTime(2010, 11, 14, 12, 0, 0), TimeSpan.FromHours(i))
                            });
                }

                // Act
                upserter.Upsert(connection, items);

                // Assert
                foreach (var testDto in items)
                {
                    Assert.AreEqual(testDto.Number, testDto.Ident);
                }
            }
        }
Exemplo n.º 2
0
        public void EndToEnd()
        {
            using (var connection = DatabaseHelper.CreateAndOpenConnection())
            {
                // Arrange
                var targetSchema = SqlTableSchema.LoadFromDatabase(connection, "TestUpsert", "ident");

                var columnMappings = new Dictionary <string, Func <TestDto, object> >
                {
                    { "ident", d => d.Ident },
                    { "key_part_1", d => d.KeyPart1 },
                    { "key_part_2", d => d.KeyPart2 },
                    { "nullable_text", d => d.Text },
                    { "nullable_number", d => d.Number },
                    { "nullable_datetimeoffset", d => d.Date },
                };

                Action <TestDto, int> identUpdater = (d, i) => d.Ident = i;

                var upserter = new TypedUpserter <TestDto>(targetSchema, columnMappings, identUpdater);

                var items = new List <TestDto>();

                for (int i = 1; i <= 10; i++)
                {
                    items.Add(
                        new TestDto
                    {
                        Ident    = null,
                        KeyPart1 = "TEST",
                        KeyPart2 = (short)i,
                        Text     = String.Format("some text here {0}", i),
                        Number   = i,
                        Date     = new DateTimeOffset(new DateTime(2010, 11, 14, 12, 0, 0), TimeSpan.FromHours(i))
                    });
                }

                // Act
                upserter.Upsert(connection, items);

                // Assert
                foreach (var testDto in items)
                {
                    Assert.AreEqual(testDto.Number, testDto.Ident);
                }
            }
        }
        private async void BulkUpsertCdaResult(IEnumerable<AnalysisResultDto> analysisResults)
        {
            try
            {
                var connection = await GetConnectionPool() as SqlConnection;

                Debug.Assert(connection != null, "connection != null");

                if (connection.State == ConnectionState.Closed)
                    connection.Open();

                // Arrange
                Action<AnalysisResultDto, int> identUpdater = (d, i) => d.IdentityColumn = i;

                var targetSchema = SqlTableSchema.LoadFromDatabase(connection, AnalysisResultTableName, "IdentityColumn");

                var upserter = new TypedUpserter<AnalysisResultDto>(
                    targetSchema,
                    new Dictionary<string, Func<AnalysisResultDto, object>>
                    {
                            {"IdentityColumn", d => d.IdentityColumn},
                            {"IdCis", d => d.IdCis},
                            {"IdCda", d => d.CdaKey.Id},
                            {"CdaVersion", d => d.CdaKey.Version},
                            {"Result", d => d.Result},
                            {"UpdatedTime", d => d.UpdatedTime}
                    },
                    identUpdater
                    );

                // Act
                upserter.Upsert(connection, analysisResults);

                ObjectPoolPutConnection(connection);
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
            }
        }