コード例 #1
0
        public void ThrowExceptionIfQualifierFieldIsNotMatchingFromMappings()
        {
            // Setup
            var statementBuilder = new SqlDbStatementBuilder();
            var queryBuilder     = new QueryBuilder <ThrowExceptionIfQualifierFieldIsNotMatchingFromMappingsClass>();
            var qualifiers       = Field.From("Field1", "Field3");

            // Act/Assert
            Assert.Throws <InvalidOperationException>(() => statementBuilder.CreateMerge(queryBuilder, qualifiers));
        }
コード例 #2
0
        public void ThrowExceptionIfQualifierFieldsAreNull()
        {
            // Setup
            var statementBuilder = new SqlDbStatementBuilder();
            var queryBuilder     = new QueryBuilder <ThrowExceptionIfQualifierFieldsAreNullClass>();
            var qualifiers       = (IEnumerable <Field>)null;

            // Act/Assert
            Assert.Throws <InvalidOperationException>(() => statementBuilder.CreateMerge(queryBuilder, qualifiers));
        }
コード例 #3
0
        public void ThrowExceptionIfAtleastOneQualifierFieldIsMissingFromDataEntity()
        {
            // Setup
            var statementBuilder = new SqlDbStatementBuilder();
            var queryBuilder     = new QueryBuilder <ThrowExceptionIfAtleastOneQualifierFieldIsMissingFromDataEntityClass>();
            var qualifiers       = Field.From("Field1", "Field4");

            // Act/Assert
            Assert.Throws <InvalidOperationException>(() => statementBuilder.CreateMerge(queryBuilder, qualifiers));
        }
コード例 #4
0
        public void TestWithClassMappings()
        {
            // Setup
            var statementBuilder = new SqlDbStatementBuilder();
            var queryBuilder     = new QueryBuilder <TestWithClassMappingsClass>();
            var qualifiers       = Field.From("Field1");

            // Act
            var actual   = statementBuilder.CreateMerge(queryBuilder, qualifiers);
            var expected = $"" +
                           $"MERGE [ClassName] AS T " +
                           $"USING ( SELECT @Field1 AS [Field1], @Field2 AS [Field2], @Field3 AS [Field3] ) " +
                           $"AS S ON ( S.[Field1] = T.[Field1] ) " +
                           $"WHEN NOT MATCHED THEN " +
                           $"INSERT ( [Field1], [Field2], [Field3] ) " +
                           $"VALUES ( S.[Field1], S.[Field2], S.[Field3] ) " +
                           $"WHEN MATCHED THEN " +
                           $"UPDATE SET [Field2] = S.[Field2], [Field3] = S.[Field3] ;";

            // Assert
            Assert.AreEqual(expected, actual);
        }
コード例 #5
0
        public void TestWithClassId()
        {
            // Setup
            var statementBuilder = new SqlDbStatementBuilder();
            var queryBuilder     = new QueryBuilder <TestWithClassIdClass>();
            var qualifiers       = (IEnumerable <Field>)null;

            // Act
            var actual   = statementBuilder.CreateMerge(queryBuilder, qualifiers);
            var expected = $"" +
                           $"MERGE [TestWithClassIdClass] AS T " +
                           $"USING ( SELECT @TestWithClassIdClassId AS [TestWithClassIdClassId], @Field2 AS [Field2], @Field3 AS [Field3] ) " +
                           $"AS S ON ( S.[TestWithClassIdClassId] = T.[TestWithClassIdClassId] ) " +
                           $"WHEN NOT MATCHED THEN " +
                           $"INSERT ( [TestWithClassIdClassId], [Field2], [Field3] ) " +
                           $"VALUES ( S.[TestWithClassIdClassId], S.[Field2], S.[Field3] ) " +
                           $"WHEN MATCHED THEN " +
                           $"UPDATE SET [Field2] = S.[Field2], [Field3] = S.[Field3] ;";

            // Assert
            Assert.AreEqual(expected, actual);
        }