Note that there are some explanatory texts on larger screens.

plurals
  1. POUnit testing functions which access Entity Database
    primarykey
    data
    text
    <p>Trying to unit test functions which access a entity framework. So i tried to put all the entity code into the test function below? However it stops at the Linq statement; obviously trying to access the database is too much drama for it. Maybe a work around would be too to create a replica database within the unit test function based on sql lite or compact;(Its not a big database anyways) then execution would not have to leave the test function? Is this possible and how would i implement it?</p> <pre><code>public void RetreiveKeyFnTest() { StegApp target = new StegApp(); // TODO: Initialize to an appropriate value string username = "david"; // TODO: Initialize to an appropriate value string password = "david1"; // TODO: Initialize to an appropriate value string ConnectionString = ConfigurationManager.ConnectionStrings["DatabaseEntities"].ToString(); var dataContext = new DatabaseEntities(ConnectionString); var user = dataContext.Users.FirstOrDefault(u =&gt; u.Username.Equals(username) &amp;&amp; u.Password.Equals(password)); Assert.IsNotNull(user); //target.RetreiveKeyFn(username, password); //Assert.IsInstanceOfType(target.RetreiveLogs,typeof(DataAccess)); //Assert.IsInstanceOfType(target.p); //Assert.IsNotNull(target.RetreiveLogs.AuthenitcateCredentials(username,password)); //Assert.Inconclusive("A method that does not return a value cannot be verified."); } </code></pre> <p>Below is the code i am trying to test:</p> <pre><code>public void RetreiveKeyFn(string username, string password) { BusinessObjects.User p = RetreiveLogs.AuthenitcateCredentials(username,password); if (p != null) { if (RetreiveLogs.RetreiveMessages(p.UserId) == null) { DisplayLogs.Text = "Sorry No messages for you recorded in Database, your correspondant might have chose not to record the entry"; } else { MessageBox.Show("LogId = " + RetreiveLogs.RetreiveMessages(p.UserId).LogId + "\n" + "UserId = " + RetreiveLogs.RetreiveMessages(p.UserId).UserId + "\n" + "Message Key = " + RetreiveLogs.RetreiveMessages(p.UserId).MessageKey + "\n" + "PictureId = " + RetreiveLogs.RetreiveMessages(p.UserId).PictureId + " Date &amp; time = " + RetreiveLogs.RetreiveMessages(p.UserId).SentDateTime); DisplayLogs.Visible = true; } } else { MessageBox.Show("Please enter your correct username and password in order to retreive either key, image or both from Databse"); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload