SilverlightShow: WCF RIA Services Part 8 - Testing and Debugging Comments http://www.silverlightshow.net/ Silverlight articles, Silverlight tutorials, Silverlight videos, Silverlight samples SilverlightShow.net http://www.rssboard.org/rss-specification Argotic Syndication Framework 2008.0.2.0, http://www.codeplex.com/Argotic en-US estoychev@completit.com (Emil Stoychev) Re: WCF RIA Services Part 8 - Testing and Debugging This article is truly relevant to my study at this moment, and I am really happy I discovered your website. <a href="http://www.merkamovil.com/">http://merkamovil.com/</a> http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx#comment8711 http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx Fri, 14 Dec 2012 04:52:39 GMT Re: WCF RIA Services Part 8 - Testing and Debugging <p>Nothing jumps out from glancing over the code and I'm afraid I don't have time to debug other people's code for free.</p> http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx#comment8708 brian.noyes http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx Thu, 13 Dec 2012 23:44:48 GMT Re: WCF RIA Services Part 8 - Testing and Debugging <p>Hi Brian,</p> <p>Do you have any help for me on the above piece of code?</p> http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx#comment8706 gnkarthik http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx Thu, 13 Dec 2012 19:16:51 GMT Re: WCF RIA Services Part 8 - Testing and Debugging <p>Hi Brian,</p> <p>Thanks for your immediate reply, I am posting my ViewModel, DomainService & Silverlight Test Class code below. Please let me know if you need anything else.</p> <div class="reCodeBlock" style="border: 1px solid #7f9db9; overflow-y: auto;"> <div style="background-color: #ffffff;"><span style="margin-left: 0px !important;"><code style="color: #000000;">// View Model Code </code></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px !important;"><code style="color: #000000;">public void DeleteCustomers()</code></span></div> <div style="background-color: #ffffff;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">if (CustomerData.Count > 0)</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">var selectedData = CustomerData.Where(d => d.IsDelete).ToList<</code><code style="color: #006699; font-weight: bold;">MainPageModel</code><code style="color: #000000;">>();</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">if (selectedData.Count > 0)</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">//MessageBoxResult result = MessageBox.Show("You are trying to delete customers. Are you sure?", "", MessageBoxButton.OKCancel);</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">//if (result == MessageBoxResult.OK)</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">//{</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">string cIds = string.Empty;</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">foreach (MainPageModel change in selectedData.Where(d => d.IsDelete))</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                        </code><span style="margin-left: 72px !important;"><code style="color: #000000;">cIds = string.Concat(cIds, Convert.ToString(change.CustomerId), ",");</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">cIds = cIds.TrimEnd(',');</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">CDomainContext.DelCustomers(cIds).Completed += new EventHandler(CustomerDelete_Completed);</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">//}</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">else</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">//MessageBox.Show("Please select a customer to delete.");</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">//return;</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">else</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">//MessageBox.Show("No data to delete.");</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">//return;</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #ffffff;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">private void CustomerDelete_Completed(object sender, EventArgs e)</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">GetCustomers();</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px !important;"><code style="color: #000000;">// Test Class Code</code></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px !important;"><code style="color: #000000;">[TestMethod, Asynchronous]</code></span></div> <div style="background-color: #ffffff;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">public void Test_DeleteCustomers()</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">{            </code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">// Arrange ---------------------------------</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">bool submitExecuted = false;</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">var domainClientStub = new Mock<</code><code style="color: #006699; font-weight: bold;">TestDomainClient</code><code style="color: #000000;">>();</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"> </span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">domainClientStub.Setup(d => d.Invoke(It.Is<</code><code style="color: #006699; font-weight: bold;">InvokeArgs</code><code style="color: #000000;">>(q => q.ReturnType == typeof(void))))</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">.Callback(() => submitExecuted = true)</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">.Returns(new InvokeCompletedResult(typeof(void)));</code></span></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">List<</code><code style="color: #006699; font-weight: bold;">MainPageModel</code><code style="color: #000000;">> testData = new List<</code><code style="color: #006699; font-weight: bold;">MainPageModel</code><code style="color: #000000;">>();</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">testData.Add(new MainPageModel() { FirstName = "karthik", LastName = "G", CustomerId = 0 });</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">testData.Add(new MainPageModel() { FirstName = "Fedrick", LastName = "D", CustomerId = 1, IsDelete = true });</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">testData.Add(new MainPageModel() { FirstName = "Steve", LastName = "K", CustomerId = 2 });</code></span></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">// Act -------------------------------------</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">MainPageViewModel viewModel = new MainPageViewModel(domainClientStub.Object);</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">viewModel.CustomerData = testData;</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">EnqueueCallback(() => viewModel.DeleteCustomers());</code></span></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">// Assert ---------------------------------</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">EnqueueConditional(() => submitExecuted);            </code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">EnqueueCallback(() =></code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">Assert.AreEqual(2, viewModel.CustomerData.Count);</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">});</code></span></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">EnqueueTestComplete();</code></span></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">//List<</code><code style="color: #006699; font-weight: bold;">MainPageModel</code><code style="color: #000000;">> testData = new List<</code><code style="color: #006699; font-weight: bold;">MainPageModel</code><code style="color: #000000;">>();</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">//testData.Add(new MainPageModel() { FirstName = "karthik", LastName = "guntupalli", CustomerId = 0 });</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">//testData.Add(new MainPageModel() { FirstName = "jotsna", LastName = "dammavalam", CustomerId = 1, IsDelete = true });</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">//testData.Add(new MainPageModel() { FirstName = "sameer", LastName = "gottipati", CustomerId = 2 });</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px !important;"><code style="color: #000000;">// Domain Service Code</code></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px !important;"><code style="color: #000000;">public void DelCustomers(string ids)</code></span></div> <div style="background-color: #ffffff;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">ObjectContext.DeleteCustomers(ids);</code></span></span></div> <div style="background-color: #ffffff;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">}</code></span></span></div> </div> <p> </p> http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx#comment8664 gnkarthik http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx Thu, 29 Nov 2012 20:17:25 GMT Re: WCF RIA Services Part 8 - Testing and Debugging <p>Hi Brian,</p> <p>Thanks for your immediate reply, I am posting my ViewModel, DomainService & Silverlight Test Class code below. Please let me know if you need anything else.</p> <div class="reCodeBlock" style="border: 1px solid #7f9db9; overflow-y: auto;"> <div style="background-color: #ffffff;"><span style="margin-left: 0px !important;"><code style="color: #000000;">// View Model Code </code></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px !important;"><code style="color: #000000;">public void DeleteCustomers()</code></span></div> <div style="background-color: #ffffff;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">if (CustomerData.Count > 0)</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">var selectedData = CustomerData.Where(d => d.IsDelete).ToList<</code><code style="color: #006699; font-weight: bold;">MainPageModel</code><code style="color: #000000;">>();</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">if (selectedData.Count > 0)</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">//MessageBoxResult result = MessageBox.Show("You are trying to delete customers. Are you sure?", "", MessageBoxButton.OKCancel);</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">//if (result == MessageBoxResult.OK)</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">//{</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">string cIds = string.Empty;</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">foreach (MainPageModel change in selectedData.Where(d => d.IsDelete))</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                        </code><span style="margin-left: 72px !important;"><code style="color: #000000;">cIds = string.Concat(cIds, Convert.ToString(change.CustomerId), ",");</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">cIds = cIds.TrimEnd(',');</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">CDomainContext.DelCustomers(cIds).Completed += new EventHandler(CustomerDelete_Completed);</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">//}</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">else</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">//MessageBox.Show("Please select a customer to delete.");</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">//return;</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">else</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">//MessageBox.Show("No data to delete.");</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">//return;</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #ffffff;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">private void CustomerDelete_Completed(object sender, EventArgs e)</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">GetCustomers();</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px !important;"><code style="color: #000000;">// Test Class Code</code></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px !important;"><code style="color: #000000;">[TestMethod, Asynchronous]</code></span></div> <div style="background-color: #ffffff;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">public void Test_DeleteCustomers()</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">{            </code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">// Arrange ---------------------------------</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">bool submitExecuted = false;</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">var domainClientStub = new Mock<</code><code style="color: #006699; font-weight: bold;">TestDomainClient</code><code style="color: #000000;">>();</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"> </span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">domainClientStub.Setup(d => d.Invoke(It.Is<</code><code style="color: #006699; font-weight: bold;">InvokeArgs</code><code style="color: #000000;">>(q => q.ReturnType == typeof(void))))</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">.Callback(() => submitExecuted = true)</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">.Returns(new InvokeCompletedResult(typeof(void)));</code></span></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">List<</code><code style="color: #006699; font-weight: bold;">MainPageModel</code><code style="color: #000000;">> testData = new List<</code><code style="color: #006699; font-weight: bold;">MainPageModel</code><code style="color: #000000;">>();</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">testData.Add(new MainPageModel() { FirstName = "karthik", LastName = "G", CustomerId = 0 });</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">testData.Add(new MainPageModel() { FirstName = "Fedrick", LastName = "D", CustomerId = 1, IsDelete = true });</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">testData.Add(new MainPageModel() { FirstName = "Steve", LastName = "K", CustomerId = 2 });</code></span></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">// Act -------------------------------------</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">MainPageViewModel viewModel = new MainPageViewModel(domainClientStub.Object);</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">viewModel.CustomerData = testData;</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">EnqueueCallback(() => viewModel.DeleteCustomers());</code></span></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">// Assert ---------------------------------</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">EnqueueConditional(() => submitExecuted);            </code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">EnqueueCallback(() =></code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">Assert.AreEqual(2, viewModel.CustomerData.Count);</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">});</code></span></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">EnqueueTestComplete();</code></span></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">//List<</code><code style="color: #006699; font-weight: bold;">MainPageModel</code><code style="color: #000000;">> testData = new List<</code><code style="color: #006699; font-weight: bold;">MainPageModel</code><code style="color: #000000;">>();</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">//testData.Add(new MainPageModel() { FirstName = "karthik", LastName = "guntupalli", CustomerId = 0 });</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">//testData.Add(new MainPageModel() { FirstName = "jotsna", LastName = "dammavalam", CustomerId = 1, IsDelete = true });</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">//testData.Add(new MainPageModel() { FirstName = "sameer", LastName = "gottipati", CustomerId = 2 });</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px !important;"><code style="color: #000000;">// Domain Service Code</code></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px !important;"><code style="color: #000000;">public void DelCustomers(string ids)</code></span></div> <div style="background-color: #ffffff;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">ObjectContext.DeleteCustomers(ids);</code></span></span></div> <div style="background-color: #ffffff;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">}</code></span></span></div> </div> <p> </p> http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx#comment8663 gnkarthik http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx Thu, 29 Nov 2012 20:15:34 GMT Re: WCF RIA Services Part 8 - Testing and Debugging <p>Hi Brian,</p> <p>Thanks for your immediate reply, I am posting my ViewModel, DomainService & Silverlight Test Class code below. Please let me know if you need anything else.</p> <div class="reCodeBlock" style="border: 1px solid #7f9db9; overflow-y: auto;"> <div style="background-color: #ffffff;"><span style="margin-left: 0px !important;"><code style="color: #000000;">// View Model Code </code></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px !important;"><code style="color: #000000;">public void DeleteCustomers()</code></span></div> <div style="background-color: #ffffff;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">if (CustomerData.Count > 0)</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">var selectedData = CustomerData.Where(d => d.IsDelete).ToList<</code><code style="color: #006699; font-weight: bold;">MainPageModel</code><code style="color: #000000;">>();</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">if (selectedData.Count > 0)</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">//MessageBoxResult result = MessageBox.Show("You are trying to delete customers. Are you sure?", "", MessageBoxButton.OKCancel);</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">//if (result == MessageBoxResult.OK)</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">//{</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">string cIds = string.Empty;</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">foreach (MainPageModel change in selectedData.Where(d => d.IsDelete))</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                        </code><span style="margin-left: 72px !important;"><code style="color: #000000;">cIds = string.Concat(cIds, Convert.ToString(change.CustomerId), ",");</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">cIds = cIds.TrimEnd(',');</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">CDomainContext.DelCustomers(cIds).Completed += new EventHandler(CustomerDelete_Completed);</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">//}</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">else</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">//MessageBox.Show("Please select a customer to delete.");</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                    </code><span style="margin-left: 60px !important;"><code style="color: #000000;">//return;</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">else</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">//MessageBox.Show("No data to delete.");</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">//return;</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #ffffff;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">private void CustomerDelete_Completed(object sender, EventArgs e)</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">GetCustomers();</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px !important;"><code style="color: #000000;">// Test Class Code</code></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px !important;"><code style="color: #000000;">[TestMethod, Asynchronous]</code></span></div> <div style="background-color: #ffffff;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">public void Test_DeleteCustomers()</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">{            </code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">// Arrange ---------------------------------</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">bool submitExecuted = false;</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">var domainClientStub = new Mock<</code><code style="color: #006699; font-weight: bold;">TestDomainClient</code><code style="color: #000000;">>();</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"> </span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">domainClientStub.Setup(d => d.Invoke(It.Is<</code><code style="color: #006699; font-weight: bold;">InvokeArgs</code><code style="color: #000000;">>(q => q.ReturnType == typeof(void))))</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">.Callback(() => submitExecuted = true)</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">.Returns(new InvokeCompletedResult(typeof(void)));</code></span></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">List<</code><code style="color: #006699; font-weight: bold;">MainPageModel</code><code style="color: #000000;">> testData = new List<</code><code style="color: #006699; font-weight: bold;">MainPageModel</code><code style="color: #000000;">>();</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">testData.Add(new MainPageModel() { FirstName = "karthik", LastName = "G", CustomerId = 0 });</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">testData.Add(new MainPageModel() { FirstName = "Fedrick", LastName = "D", CustomerId = 1, IsDelete = true });</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">testData.Add(new MainPageModel() { FirstName = "Steve", LastName = "K", CustomerId = 2 });</code></span></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">// Act -------------------------------------</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">MainPageViewModel viewModel = new MainPageViewModel(domainClientStub.Object);</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">viewModel.CustomerData = testData;</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">EnqueueCallback(() => viewModel.DeleteCustomers());</code></span></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">// Assert ---------------------------------</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">EnqueueConditional(() => submitExecuted);            </code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">EnqueueCallback(() =></code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #ffffff;"><span><code>                </code><span style="margin-left: 48px !important;"><code style="color: #000000;">Assert.AreEqual(2, viewModel.CustomerData.Count);</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">});</code></span></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">EnqueueTestComplete();</code></span></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">//List<</code><code style="color: #006699; font-weight: bold;">MainPageModel</code><code style="color: #000000;">> testData = new List<</code><code style="color: #006699; font-weight: bold;">MainPageModel</code><code style="color: #000000;">>();</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">//testData.Add(new MainPageModel() { FirstName = "karthik", LastName = "guntupalli", CustomerId = 0 });</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">//testData.Add(new MainPageModel() { FirstName = "jotsna", LastName = "dammavalam", CustomerId = 1, IsDelete = true });</code></span></span></div> <div style="background-color: #ffffff;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">//testData.Add(new MainPageModel() { FirstName = "sameer", LastName = "gottipati", CustomerId = 2 });</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">}</code></span></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px !important;"><code style="color: #000000;">// Domain Service Code</code></span></div> <div style="background-color: #ffffff;"><span style="margin-left: 0px !important;"> </span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px !important;"><code style="color: #000000;">public void DelCustomers(string ids)</code></span></div> <div style="background-color: #ffffff;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">{</code></span></span></div> <div style="background-color: #f8f8f8;"><span><code>            </code><span style="margin-left: 36px !important;"><code style="color: #000000;">ObjectContext.DeleteCustomers(ids);</code></span></span></div> <div style="background-color: #ffffff;"><span><code>        </code><span style="margin-left: 24px !important;"><code style="color: #000000;">}</code></span></span></div> </div> <p> </p> http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx#comment8661 gnkarthik http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx Thu, 29 Nov 2012 20:07:35 GMT Re: WCF RIA Services Part 8 - Testing and Debugging <p>Its hard to say without seeing the whole code, but you are adding 3 items, then calling DeleteCustomers (which I would presume should be clearing the collection) and then you are asserting that the count is 2. Something doesn't add up there.</p> http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx#comment8659 brian.noyes http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx Thu, 29 Nov 2012 14:33:10 GMT Re: WCF RIA Services Part 8 - Testing and Debugging <p>Hi Brian,</p> <p>This is an amazing article i read for a long time and you deserve all credit for it. However i have a question. I am using LinqToEntitiesDomainContext, not Entites (i.e. Task) but a ComplexType for Update/Insert/Delete. I could MoQ and test the dependency for Select. but i am unable to test the U/I/D. Please find below sample code of what i am trying to achieve and please suggest:</p> <p><span style="color: #008000; font-family: consolas; font-size: 13px;">// Arrange --------------------------------</span></p> <p><span style="color: #0000ff; font-family: consolas; font-size: 13px;">bool</span><span style="font-family: consolas; font-size: 13px;"> submitExecuted = </span><span style="color: #0000ff; font-family: consolas; font-size: 13px;">false</span><span style="font-family: consolas; font-size: 13px;">;</span><span style="font-family: consolas; font-size: 13px;"></span></p> <p><span style="color: #0000ff; font-family: consolas; font-size: 13px;">var</span><span style="font-family: consolas; font-size: 13px;"> domainClientStub = </span><span style="color: #0000ff; font-family: consolas; font-size: 13px;">new</span><span style="font-family: consolas; font-size: 13px;"> </span><span style="color: #2b91af; font-family: consolas; font-size: 13px;">Mock</span><span style="font-family: consolas; font-size: 13px;"><</span><span style="color: #2b91af; font-family: consolas; font-size: 13px;">TestDomainClient</span><span style="font-family: consolas; font-size: 13px;">>();</span><span style="font-family: consolas; font-size: 13px;"><span style="font-family: consolas; font-size: 13px;"></span></span></p> <p> </p> <p> domainClientStub.Setup(d => d.Invoke(</p> <p> </p> <p> </p> <p><span style="color: #2b91af; font-family: consolas; font-size: 13px;">It</span><span style="font-family: consolas; font-size: 13px;">.Is<</span><span style="color: #2b91af; font-family: consolas; font-size: 13px;">InvokeArgs</span><span style="font-family: consolas; font-size: 13px;">>(q => q.ReturnType == </span><span style="color: #0000ff; font-family: consolas; font-size: 13px;">typeof</span><span style="font-family: consolas; font-size: 13px;">(</span><span style="color: #0000ff; font-family: consolas; font-size: 13px;">void</span><span style="font-family: consolas; font-size: 13px;">))))</span><span style="font-family: consolas; font-size: 13px;">.Callback(() => submitExecuted = </span><span style="color: #0000ff; font-family: consolas; font-size: 13px;">true</span><span style="font-family: consolas; font-size: 13px;">)</span></p> <p><span style="font-family: consolas; font-size: 13px;"> .Returns(</span><span style="color: #0000ff; font-family: consolas; font-size: 13px;">new</span><span style="font-family: consolas; font-size: 13px;"> </span><span style="color: #2b91af; font-family: consolas; font-size: 13px;">InvokeCompletedResult</span><span style="font-family: consolas; font-size: 13px;">(</span><span style="color: #0000ff; font-family: consolas; font-size: 13px;">typeof</span><span style="font-family: consolas; font-size: 13px;">(</span><span style="color: #0000ff; font-family: consolas; font-size: 13px;">void</span><span style="font-family: consolas; font-size: 13px;">)));</span></p> <p><span style="font-family: consolas; font-size: 13px;"> </span><span style="color: #2b91af; font-family: consolas; font-size: 13px;">List</span><span style="font-family: consolas; font-size: 13px;"><</span><span style="color: #2b91af; font-family: consolas; font-size: 13px;">MainPageModel</span><span style="font-family: consolas; font-size: 13px;">> testData = </span><span style="color: #0000ff; font-family: consolas; font-size: 13px;">new</span><span style="font-family: consolas; font-size: 13px;"> </span><span style="color: #2b91af; font-family: consolas; font-size: 13px;">List</span><span style="font-family: consolas; font-size: 13px;"><</span><span style="color: #2b91af; font-family: consolas; font-size: 13px;">MainPageModel</span><span style="font-family: consolas; font-size: 13px;">>();</span></p> <p><span style="font-family: consolas; font-size: 13px;"> testData.Add(</span><span style="color: #0000ff; font-family: consolas; font-size: 13px;">new</span><span style="font-family: consolas; font-size: 13px;"> </span><span style="color: #2b91af; font-family: consolas; font-size: 13px;">MainPageModel</span><span style="font-family: consolas; font-size: 13px;">() { FirstName = </span><span style="color: #a31515; font-family: consolas; font-size: 13px;">"karthik"</span><span style="font-family: consolas; font-size: 13px;">, LastName = </span><span style="color: #a31515; font-family: consolas; font-size: 13px;">"G"</span><span style="font-family: consolas; font-size: 13px;">, CustomerId = 0 });</span></p> <p><span style="font-family: consolas; font-size: 13px;"> testData.Add(</span><span style="color: #0000ff; font-family: consolas; font-size: 13px;">new</span><span style="font-family: consolas; font-size: 13px;"> </span><span style="color: #2b91af; font-family: consolas; font-size: 13px;">MainPageModel</span><span style="font-family: consolas; font-size: 13px;">() { FirstName = </span><span style="color: #a31515; font-family: consolas; font-size: 13px;">"Fedrick"</span><span style="font-family: consolas; font-size: 13px;">, LastName = </span><span style="color: #a31515; font-family: consolas; font-size: 13px;">"D"</span><span style="font-family: consolas; font-size: 13px;">, CustomerId = 1, IsDelete = </span><span style="color: #0000ff; font-family: consolas; font-size: 13px;">true</span><span style="font-family: consolas; font-size: 13px;"> });</span></p> <p><span style="font-family: consolas; font-size: 13px;"> testData.Add(</span><span style="color: #0000ff; font-family: consolas; font-size: 13px;">new</span><span style="font-family: consolas; font-size: 13px;"> </span><span style="color: #2b91af; font-family: consolas; font-size: 13px;">MainPageModel</span><span style="font-family: consolas; font-size: 13px;">() { FirstName = </span><span style="color: #a31515; font-family: consolas; font-size: 13px;">"Steve"</span><span style="font-family: consolas; font-size: 13px;">, LastName = </span><span style="color: #a31515; font-family: consolas; font-size: 13px;">"K"</span><span style="font-family: consolas; font-size: 13px;">, CustomerId = 2 });</span></p> <p><span style="font-family: consolas; font-size: 13px;"> </span><span style="color: #008000; font-family: consolas; font-size: 13px;">// Act -------------------------------------</span></p> <p><span style="color: #2b91af; font-family: consolas; font-size: 13px;">MainPageViewModel</span><span style="font-family: consolas; font-size: 13px;"> viewModel = </span><span style="color: #0000ff; font-family: consolas; font-size: 13px;">new</span><span style="font-family: consolas; font-size: 13px;"> </span><span style="color: #2b91af; font-family: consolas; font-size: 13px;">MainPageViewModel</span><span style="font-family: consolas; font-size: 13px;">(domainClientStub.Object);</span><span style="font-family: consolas; font-size: 13px;"><span style="font-family: consolas; font-size: 13px;"></span></span></p> <p> </p> <p> viewModel.CustomerData = testData;</p> <p> EnqueueCallback(() => viewModel.DeleteCustomers());</p> <p> </p> <p> </p> <p><span style="color: #008000; font-family: consolas; font-size: 13px;">//Assert ---------------------------------</span><span style="font-family: consolas; font-size: 13px;"><span style="font-family: consolas; font-size: 13px;"></span></span></p> <p> </p> <p> EnqueueConditional(() => submitExecuted); </p> <p>EnqueueCallback(() =></p> <p>{</p> <p> </p> <p> </p> <p><span style="color: #2b91af; font-family: consolas; font-size: 13px;">Assert</span><span style="font-family: consolas; font-size: 13px;">.AreEqual(2, viewModel.CustomerData.Count);</span><span style="font-family: consolas; font-size: 13px;"></span></p> <p> </p> <p> });</p> <p> EnqueueTestComplete();</p> <p> </p> http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx#comment8658 gnkarthik http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx Thu, 29 Nov 2012 13:56:10 GMT Re: WCF RIA Services Part 8 - Testing and Debugging <p>Rob, glad to hear you sorted it out. Thanks for putting the solution here in the comments for others to benefit from. It easy to get bitten with the transparent code gen that happens at build time if you have it happening in two places and pull them together into the same scope. I've done it to myself on several occasions.</p> http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx#comment7633 brian.noyes http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx Wed, 07 Mar 2012 15:09:47 GMT Re: WCF RIA Services Part 8 - Testing and Debugging <p>Brian,</p> <p>Thanks for taking the time to get back to me, especially so quickly.  I ended up using Reflector and stepping through the code.  Turns out my real issue was having RIA Services linked in both the silverlight project and in the unit test project.  This was auto generating the same DomainContext classes in two places.  Since everything still compiled I figured it was just an overactive Resharper giving me warnings.  What was actually failing was a comparison deep inside EntityContainer where it was looking through the EntitySet for matching types.  What was in there was a match in name only, since the actual Types were coming from two separate dlls.<br /> <br /> I hope that all makes sense and thanks again for your time.</p> <p>Rob</p> <p><br /> </p> http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx#comment7632 robt http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx Wed, 07 Mar 2012 08:21:47 GMT Re: WCF RIA Services Part 8 - Testing and Debugging <p>So are you saying you tried doing the Mock.Setup call with the entity type instead of the QueryName and it did not work? I can kind of see why you would get the error you are describing by doing the setup that way because now the mock domain client has no information about the types it is exposing. When you setup the mock based on the type of the entity, it implicitly has type information to match against.</p> <p>But other than that, I have no idea why checking for your entity type would not work for you, nor exactly why not checking based on entity type would cause what you are seeing without going and doing a lot of digging with Reflector.</p> <p>Regards</p> <p>Brian</p> http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx#comment7631 brian.noyes http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx Wed, 07 Mar 2012 03:54:48 GMT Re: WCF RIA Services Part 8 - Testing and Debugging <p>Brian,</p> <p>Thanks for the article, it is very informative.  I'm having some trouble implementing it and was hoping you could provide some insight.I've created the TestDomainClient and am injecting it into the DomainContext as you describe.  Here is my Mock setup:</p> <p>var domainClientMock = new Mock<MockDomainClient>();<br /> domainClientMock<br /> <span class="Apple-tab-span" style="white-space: pre;"> </span>.Setup(dc => dc.Query(It.Is<EntityQuery>(query => query.QueryName == "GetCorrespondences")))<br />     .Callback(() => loadExecuted = true)<br />     .Returns(() => new Entity[]<br /> <span class="Apple-tab-span" style="white-space: pre;"> </span>{<br /> <span class="Apple-tab-span" style="white-space: pre;"> </span>new CorrespondenceDTO{ Id=new Guid(),ProgramName = "name1",Title="title1",Description = "description1"},<br /> <span class="Apple-tab-span" style="white-space: pre;"> </span>new CorrespondenceDTO{ Id=new Guid(),ProgramName = "name2",Title="title2",Description = "description2"}<br /> <span class="Apple-tab-span" style="white-space: pre;"> </span>}.AsQueryable()<br /> <span class="Apple-tab-span" style="white-space: pre;"> </span>}</p> <p>You may notice that I had to change the .Setup(...) a bit otherwise it was not finding the query.  It would get into BeginQueryCore and not have a value in results.  It's working now (in so much as it does have the test data in results). I also have my injected values in EndQueryCore (when I step through it).  And now we come to where the wheels fall off for me.  <br /> <br /> When I step out of EndQueryCore and into the ViewModel where I step into the Completed event handler for the LoadOperation the Error property for the LoadOperation is <br /> <br /> "Load operation failed for query 'GetCorrespondences'. This EntityContainer does not contain an EntitySet of type 'BasicDemo.Web.Models.CorrespondenceDTO'. If the type is external to this EntityContainer, please make sure you’ve called AddReference to establish the external link."</p> <p>Just for fun I tried calling AddReference on my DomainContext and passing in the CorrespondenceDTO, but it throws an error stating that it it already there.  Is this enough info for you to even hazard a guess?</p> http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx#comment7628 robt http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx Tue, 06 Mar 2012 19:58:27 GMT Re: WCF RIA Services Part 8 - Testing and Debugging <p>You can also find the sample code here: http://www.softinsight.com/downloads/Articles/SilverlightShow/TaskManagerPart8.zip </p> http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx#comment6390 brian.noyes http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx Mon, 01 Aug 2011 15:52:11 GMT Re: WCF RIA Services Part 8 - Testing and Debugging The link for the source code does not work!!! Please help it's such a useful article. Thanks. http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx#comment6389 Arushi http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx Mon, 01 Aug 2011 10:09:51 GMT RE: WCF RIA Services Part 8 - Testing and Debugging <p>Abraham,</p> <p>Nice post! Thanks for adding the link here for additional approaches to being more testable on the server side.</p> <p>Brian</p> http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx#comment6248 Brian Noyes http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx Wed, 01 Jun 2011 00:55:42 GMT RE: WCF RIA Services Part 8 - Testing and Debugging Ehm... that last comment should have read "you need a way to mock the object context". http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx#comment6247 Isaac Abraham http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx Tue, 31 May 2011 23:13:14 GMT RE: WCF RIA Services Part 8 - Testing and Debugging <p>@Colin: Any query you perform in a domain service on the ObjectContext (in a linq-to-entities domain service) will attempt to go to the database. So you need a way to mock the service, only this (apparently) can't be done as the EF Domain Service is closely coupled to the context. So you either go for the repository pattern / use a standard Domain Context and manually control lifetime of the context or use proxy classes. I blog about it here... http://cockneycoder.wordpress.com/2011/05/28/testing-out-the-entity-framework-wcf-ria-services-domain-service.</p> <p>Hope that helps someone...</p> http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx#comment6246 Isaac Abraham http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx Tue, 31 May 2011 23:12:25 GMT RE: WCF RIA Services Part 8 - Testing and Debugging This is the best series on RIA Services i have found so far, thank you very much for the great work! http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx#comment5965 Resad Zacina http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx Thu, 21 Apr 2011 23:35:12 GMT RE: WCF RIA Services Part 8 - Testing and Debugging Nice tip Colin, thanks much! http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx#comment5250 brian.noyes http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx Fri, 07 Jan 2011 01:12:07 GMT RE: WCF RIA Services Part 8 - Testing and Debugging For unit testing the DomainService code, in a normal LinqToEntitiesDomainService the only call being done to the database will be in the PersistChangeSet method. If you override that method and, during testing, call the AcceptAllChanges method instead of the SaveChanges method you will simulate a successful save to the database. You can start a full test of the full Submit process by calling the Submit method with your own ChangeSet object. Almost over step of the Submit process has an overridable method if you want to unit test the entire chain. There are <a href="http://www.wcfriaservices.net/Wiki/Default.aspx?Page=Unit-Testing-Your-DomainService-Methods&NS=&AspxAutoDetectCookieSupport=1">instructions </a>on the WCF RIA Services wiki on how to setup the DomainService in test. http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx#comment5249 Colin Blair http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx Thu, 06 Jan 2011 17:51:29 GMT RE: WCF RIA Services Part 8 - Testing and Debugging <p>Great series! I just read through the whole thing. Sadly I have to agree that RIA Services is not very testable. It's by far my biggest complaint against it. I also hate to admit that how difficult it is to test RIA Services is enough for me to consider adopting different technology altogether. RIA Services team, if you're listening, please address this.</p> <p>Anyway, another way to find the URL for your WCF service is to open the generated code file on the client side (it is named something like "MyWebApp.Web.g.cs", and just search for ".svc" in that file. You will find the constructors that create the WebDomainClients, and it will contain a string literal with the URI of the svc.</p> http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx#comment4955 Matt http://www.silverlightshow.net/items/WCF-RIA-Services-Part-8-Testing-and-Debugging.aspx Wed, 24 Nov 2010 19:08:10 GMT