locked
C# FullText query gives no result in Unit Test RRS feed

  • Question

  • Hello,

    I'm writing unit tests to test my repository classes and query's/stored procedures. The problem is that search function gives no result in the unit test.
    If i debug the unit test and step through every method i get the expected result but if i put the breakpoint after the method and debug the test i get an empty result.

    I've tested it in a console application and it seems to work there.

    I have manually executed my stored procedure in SQL Management Studio and it works there. Even the query that gets send to SQL server works if i execute it (intercepted the query using SQL Server profiler).

    Is this a bug in the .NET framework or the VS unit test framework or some unknown feature with fulltext queries? All other queries (that dont use fulltext search functions) work as intented in unit tests.

    // Unit test [TestMethod] public void Search_Content_Test() { var result = UnitOfWork.Boxes.Search(2, new Period(null, null), "Facturen", null); Assert.AreEqual(3, result.Count()); } // BoxRepository public IEnumerable<Box> Search(int customerId, Period period, string content, string addendum) { using (var command = unitOfWork.CreateCommand()) { command.CommandText = "usp_SearchBoxes"; command.CommandType = CommandType.StoredProcedure; command.AddParameter("@CustomerId", customerId); command.AddParameter("@PeriodStart", period.Start); command.AddParameter("@PeriodEnd", period.End); command.AddFullTextParameter("@Content", content); command.AddFullTextParameter("@Addendum", addendum); return command.ToList(boxMapper); } } // DataExtensions public static List<T> ToList<T>(this IDbCommand command, IDataMapper<T> mapper) { using (var reader = command.ExecuteReader()) { var list = new List<T>(); while (reader.Read()) { var item = mapper.Map(reader); list.Add(item); } return list; } }


    Thursday, March 24, 2016 1:55 PM

All replies

  • Hi Zef,

    Like your title mentioned, your case more related to Unit Test, I will move your case to Unit Test forum for better support.

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, March 25, 2016 1:46 AM
  • Hi Zef Ubachs,

    Is it related to the Stored Procedure unit test like the following thread?

    Reference:

    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/b400ce80-743a-4822-b6b0-6e23b7fdc838/unable-to-create-a-sqlclr-stored-procedure-unit-test?forum=ssdt

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 28, 2016 4:30 AM
  • Hey Jack,

    Its not related. The link you provided discusses a unit test not being created for a SQLCLR stored procedure.

    My problem is a SQL stored procedure not giving the same results when running the test, and debugging the test and stepping through the method.
    When creating a console application the stored procedure executes fine and gives the predicted result. Running the unit test however, does not.

    Monday, March 28, 2016 9:25 AM
  • Hi Zef Ubachs,

    To really repro this issue, could you share us a simple sample using the one drive?

    Please attach your Visual Studio project, you can upload it to the one drive, and then share the download link in your post.

    >>If i debug the unit test and step through every method i get the expected result but if i put the breakpoint after the method and debug the test i get an empty result.

    If you got error messages, please show the whole error messages in your post. Please also attach a screenshot image about the above result in your post.

    If there's any concern, please feel free to let me know.

    Sincerely,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, March 29, 2016 5:37 AM