Как написать юнит тест в разработке CRM 2011

Я готов начать писать модульные тесты для своего кода CRM 2011. У меня очень мало опыта модульного тестирования, поэтому я хотел бы помочь с этим.

Метод, который я хотел бы проверить:

public Proxy.custom_serviceobject PopulateServiceObject(Proxy.custom_serviceobject crmServiceObject, serviceobject irisServiceObject, Guid locationId)
{
    //set the reference to the location the order is connected to
    crmServiceObject.custom_location = new EntityReference("custom_location", locationId);
    //add the reference to the product in the serviceobject
    crmServiceObject.custom_product = new EntityReference("product", new Guid(irisServiceObject.ItemId));
    //convert the errorid to an int
    Int32 errorId;
    var success = Int32.TryParse(irisServiceObject.ErrorId, out errorId);
    crmServiceObject.custom_errorclassOptionSetValue = success ? new OptionSetValue(errorId) : new OptionSetValue(Int32.MinValue);

    crmServiceObject.custom_serviceobjecttype =
        new EntityReference("custom_serviceobjecttype", new Guid(irisServiceObject.ObjectType.Id));

    crmServiceObject.custom_placement = irisServiceObject.SortId;
    crmServiceObject.custom_yearofinstallationOptionSetValue = new OptionSetValue(irisServiceObject.AuditYear);
    crmServiceObject.custom_yearofmanufactureOptionSetValue = new OptionSetValue(irisServiceObject.ProductionYear);
    crmServiceObject.custom_location = new EntityReference("custom_location", new Guid(irisServiceObject.Location));
    crmServiceObject.custom_quantity = irisServiceObject.Qty;

    crmServiceObject.custom_remark = irisServiceObject.ExternalNote;
    crmServiceObject.custom_internalremark = irisServiceObject.InternalNote;



    if (irisServiceObject.Cancelled)
    {
        var setStateRequest = new SetStateRequest
        {
            EntityMoniker = new EntityReference
            {
                Id = crmServiceObject.Id,
                LogicalName = "custom_serviceobject"
            },
            State = new OptionSetValue(StatusInactive),
            Status = new OptionSetValue(StatusReasonInactive)
        };
        Service.Execute(setStateRequest);
    }

    return crmServiceObject;

}

У вас есть идеи о том, какой тест я мог бы написать? Должен ли я издеваться над некоторыми компонентами?

2 ответа

Решение

Ваш метод делает только две вещи, обновляет некоторые значения в crmServiceObject и выполняет оператор обновления. Поскольку нет ничего специфичного для CRM (кроме того, что crmServiceObject является типом, определенным CRM) для модульного тестирования, обновляющего объект, я пропущу эту его часть.

Что касается вызова CRM для отключения объекта, у вас есть два варианта для модульного теста. Убедитесь, что CRM выполнил отключение или нет, или смоделируйте IOrganizationService и подтвердите, что был выполнен вызов Execute или нет. Это зависит от вас на самом деле.

Этот вопрос также может быть полезен, хотя он относится конкретно к плагинам.

Проверьте эту ссылку ниже. И, кредит переходит к первоначальному владельцу этой страницы YouTube. http://www.youtube.com/watch?v=2obtHBx07tc

Жаль, что это помогает. Приветствия.

Другие вопросы по тегам