Click here to Skip to main content
14,241,806 members

.NET Framework

 
GeneralRe: Task based asyn Pin
anilkumar198612-Feb-19 21:37
memberanilkumar198612-Feb-19 21:37 
GeneralRe: Task based asyn Pin
Wastedtalent12-Feb-19 21:48
professionalWastedtalent12-Feb-19 21:48 
GeneralRe: Task based asyn Pin
anilkumar198612-Feb-19 22:52
memberanilkumar198612-Feb-19 22:52 
GeneralRe: Task based asyn Pin
anilkumar198613-Feb-19 1:23
memberanilkumar198613-Feb-19 1:23 
Questionstatement is not valid n a namespace Pin
Member 1384753912-Feb-19 8:07
memberMember 1384753912-Feb-19 8:07 
AnswerRe: statement is not valid n a namespace Pin
Richard Deeming12-Feb-19 10:05
mveRichard Deeming12-Feb-19 10:05 
GeneralRe: statement is not valid n a namespace Pin
Member 1384753913-Feb-19 5:37
memberMember 1384753913-Feb-19 5:37 
QuestionMocking a Service call in my Unit Tests Pin
simpledeveloper8-Feb-19 7:31
membersimpledeveloper8-Feb-19 7:31 
Hi,

I am writing unit tests for my application, I have a Service call which I wanna mock, the my method takes list of some type and converts that type into another type of objects then calls another back-end Service which we have only Proxy class but don't know much about it, for each item in the list - means for each item in the list we pass, it will be converted and then passed to that black-box service that we don't know anything about, our method returns nothing, I mean this methods is void method.
If Service call fails for any one item in the list, our our method throws Exception aborts calls to all the remaining items, that's all it does, its simple for implementation but for writing Unit Tests I am having problems.

What I have to check is, weather the conversion of the list of type items that we are passing is done properly or not, and there no response, so I have to mock it, I am trying, but the problem is, how am I going to check for all the items, since the scope of those items that are converted would be within that method call. Its just breaking my head, and I don't want to repeat the mock calls more than what it needs to be. Any help would be greatly greatly helpful - thanks in advance.

My Test method that I am trying:
[TestMethod]
public async Task ServiceAgreementUpdateAddTest()
{
    var serviceAgreementCharacteristicRequests = new List<ServiceAgreementCharacteristicRequest>();

    foreach (var serviceAgreementId in this.serviceAgreementIds)
    {
        var request = new ServiceAgreementCharacteristicRequest
        {
            ServiceAgreementId = serviceAgreementId,
            CharacteristicType = characteristicType,
            CharacteristicValue = characteristicValue,
            ActionType = RequestAction.ADD
        };

        serviceAgreementCharacteristicRequests.Add(request);
    }

    this._serviceWrapper.Setup(e => e.UseServiceAsync(It.IsAny<Func<ATC1ServiceAgreementUpdatePortType, Task<C1ServiceAgreementUpdateResponse>>>())).ReturnsAsync(new C1ServiceAgreementUpdateResponse());

    await this._service.ServiceAgreementCharacteristicAsync(serviceAgreementCharacteristicRequests).ConfigureAwait(false);

    this._serviceWrapper.Verify(sw => sw.UseServiceAsync(It.IsAny<Func<ATC1ServiceAgreementUpdatePortType, Task<C1ServiceAgreementUpdateResponse>>>()), Times.Exactly(serviceAgreementCharacteristicRequests.Count));
    // TODO - verify that the service call request was built correctly.
}


My Method is as below:
        public async Task ServiceAgreementCharacteristicAsync(List<ServiceAgreementCharacteristicRequest> serviceAgreementCharacteristicRequests)
        {
            foreach (var item in serviceAgreementCharacteristicRequests)
            {
                var request = new C1ServiceAgreementUpdateRequest
                {
                    C1ServiceAgreementUpdate = new C1ServiceAgreementUpdate
                    {
                        serviceAgreement = item.ServiceAgreementId,
                        saChar = new[]
                        {
                            new C1ServiceAgreementUpdateSaChar
                            {
                                action = MapActionType(item.ActionType),
                                actionSpecified = true,
                                serviceAgreement11 = item.ServiceAgreementId,
                                characteristicType3 = item.CharacteristicType,
                                characteristicValue2 = item.CharacteristicValue,
                                effectiveDate6 = DateTime.Now,
                                effectiveDate6Specified = true,
                                searchCharacteristicValue = SearchCharacteristicValue
                            }
                        }
                    }
                };

                await this._serviceWrapper.UseServiceAsync((ATC1ServiceAgreementUpdatePortType service) => service.C1ServiceAgreementUpdateAsync(request)).ConfigureAwait(false);
            }
        }

private listAction MapActionType(RequestAction requestAction)
        {
            var actionType = listAction.add;

            switch (requestAction)
            {
                case RequestAction.ADD:
                    break;
                case RequestAction.UPDATE:
                    actionType = listAction.update;
                    break;
                case RequestAction.DELETE:
                    actionType = listAction.delete;
                    break;
                default:
                    throw new ArgumentException($"CustomerServiceWeb.Services.ServiceAgreements.ServiceAgreementUpdateProxy.MapActionType: Unmapped CustomerServiceWeb.Domain.Services.Common.RequestAction value: {requestAction.ToString()}");
            }

            return actionType;
        }


modified 8-Feb-19 15:56pm.

AnswerRe: Mocking a Service call in my Unit Tests Pin
Gerry Schmitz8-Feb-19 10:46
mveGerry Schmitz8-Feb-19 10:46 
GeneralRe: Mocking a Service call in my Unit Tests Pin
simpledeveloper8-Feb-19 10:59
membersimpledeveloper8-Feb-19 10:59 
GeneralRe: Mocking a Service call in my Unit Tests Pin
simpledeveloper11-Feb-19 8:29
membersimpledeveloper11-Feb-19 8:29 
GeneralRe: Mocking a Service call in my Unit Tests Pin
Gerry Schmitz13-Feb-19 5:40
mveGerry Schmitz13-Feb-19 5:40 
QuestionNot able to read the Detail property of Exception, when it is shown in the Quick Watch Pin
simpledeveloper4-Feb-19 12:25
membersimpledeveloper4-Feb-19 12:25 
AnswerRe: Not able to read the Detail property of Exception, when it is shown in the Quick Watch Pin
Dave Kreskowiak4-Feb-19 14:04
mveDave Kreskowiak4-Feb-19 14:04 
GeneralRe: Not able to read the Detail property of Exception, when it is shown in the Quick Watch Pin
simpledeveloper8-Feb-19 7:15
membersimpledeveloper8-Feb-19 7:15 
GeneralRe: Not able to read the Detail property of Exception, when it is shown in the Quick Watch Pin
Dave Kreskowiak8-Feb-19 8:49
mveDave Kreskowiak8-Feb-19 8:49 
GeneralRe: Not able to read the Detail property of Exception, when it is shown in the Quick Watch Pin
simpledeveloper8-Feb-19 9:44
membersimpledeveloper8-Feb-19 9:44 
GeneralRe: Not able to read the Detail property of Exception, when it is shown in the Quick Watch Pin
Pete O'Hanlon8-Feb-19 10:37
protectorPete O'Hanlon8-Feb-19 10:37 
GeneralRe: Not able to read the Detail property of Exception, when it is shown in the Quick Watch Pin
Dave Kreskowiak8-Feb-19 10:44
mveDave Kreskowiak8-Feb-19 10:44 
GeneralRe: Not able to read the Detail property of Exception, when it is shown in the Quick Watch Pin
simpledeveloper8-Feb-19 10:52
membersimpledeveloper8-Feb-19 10:52 
AnswerRe: Not able to read the Detail property of Exception, when it is shown in the Quick Watch Pin
Richard MacCutchan4-Feb-19 22:05
protectorRichard MacCutchan4-Feb-19 22:05 
GeneralRe: Not able to read the Detail property of Exception, when it is shown in the Quick Watch Pin
simpledeveloper8-Feb-19 7:51
membersimpledeveloper8-Feb-19 7:51 
GeneralRe: Not able to read the Detail property of Exception, when it is shown in the Quick Watch Pin
Richard MacCutchan8-Feb-19 22:22
protectorRichard MacCutchan8-Feb-19 22:22 
GeneralRe: Not able to read the Detail property of Exception, when it is shown in the Quick Watch Pin
simpledeveloper11-Feb-19 6:59
membersimpledeveloper11-Feb-19 6:59 
QuestionBindingSource Implementation in .net Win Forms Pin
rjto2-Jan-19 5:01
memberrjto2-Jan-19 5:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.