AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 07.01.2009, 17:05   #1  
Blog bot is offline
Blog bot
Участник
 
25,643 / 848 (80) +++++++
Регистрация: 28.10.2006
Dynamics Mobile: Unit Testing DocumentHandlers
Источник: http://blogs.msdn.com/dynamicsmobile...thandlers.aspx
==============

As I promised in a previous post, I'd like to discuss how to unit test a custom DocumentHandler. There's really nothing to it: Just create a new instance of your DocumentHandler and start invoking its members.

Here's a test of the Submit method:

[TestMethod] public void SubmitWillReturnCorrectDescription() {     // Fixture setup     string anonymousXml = "XML";     Guid anonymousMessageId = Guid.NewGuid();     string anonymousDeviceId = "Anonymous device ID";     IPrincipal anonymousPrincipal =         new GenericPrincipal(             new GenericIdentity("Someone"), new string[0]);       string expectedDescription =         string.Format("Message {0} was successfully submitted",         anonymousMessageId);       MyDocumentHandler sut = new MyDocumentHandler();     // Exercise system     DocumentResponse result =         sut.Submit(anonymousXml, anonymousMessageId,         anonymousDeviceId, anonymousPrincipal);     // Verify outcome     Assert.AreEqual<span style="color: blue"string/span>(expectedDescription,         result.Description, "Description");     // Teardown }
Since the Submit method takes four parameters, you must create these four objects prior to invoking the method. In this example, I'm naming the variables using the Anonymous Variable Naming coding idiom.

In many cases, the XML string containing the document to submit is probably the most interesting parameter, and you will likely need to write many separate tests to verify that your custom DocumentHandler correctly deals with different instances of your particular XML document format.

In this context, it's worth noting that you can obviously debug into your code when running a test, so this is a very effective troubleshooting technique. Due to the way we load and host DocumentHandlers, it's not possible to attach a debugger to a custom DocumentHandler while it's executing in Mobile Server, so debugging into a unit test is a good alternative. If your custom DocumentHandler throws an exception while executing in Mobile Server, the event log will contain a copy of the message, and you can then use this copy to reproduce the problem in a unit test.

In the test shown above, notice that I create a new GenericPrincipal instance to use as the mobileUser parameter. Be aware that any IPrincipal instance is acceptable, so I just created a GenericPrincipal because it was the easiest thing to do. When executing your custom DocumentHandler, Mobile Server doesn't use GenericPrincipal, but rather a different implementation of IPrincipal, and it makes no guarantees that it will always use the same implementation type. In other words, your custom DocumentHandler should follow the Liskov Substitution Principle.

As you can see, it's really straightforward to unit test custom DocumentHandlers. The Submit method has by far the most complex signature, so testing the FriendlyName and GetDocumentDescription members is even simpler.



Источник: http://blogs.msdn.com/dynamicsmobile...thandlers.aspx
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Dynamics Mobile: How to code your own barcode enabled tasklets (Motorola and Intermec devices) Blog bot DAX Blogs 1 03.06.2014 06:34
Dynamics Mobile: Unit Testing DocumentHandlers With Parameters Blog bot DAX Blogs 0 13.01.2009 14:05
axStart: Microsoft Dynamics AX 2009 Hot Topics Web Seminar Series Blog bot DAX Blogs 0 06.08.2008 12:05
mfp: Late night discussions on software development #3: Unit testing Blog bot DAX Blogs 6 17.03.2008 12:01
Dynamics AX: Dynamics AX 4.0 - Unit Testing and Test Projects Blog bot DAX Blogs 0 28.10.2006 16:40

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 00:33.