logo
Tags down

shadow

How to test service function without connecting on database


By : michaelry
Date : October 15 2020, 08:10 PM
should help you out I'm turning again on you guys, because I spend my fair share of hours on this "task" and I still can't figure out how to test my service method, without my function connection on database (I have to mock repository functions) , This is an answer to my problem
code :
public function testGetInfo()
{
    $mockEntity = $this->mockEntityManager;

    $name = 'antrax.com';
    $requestMock = new RequestEntity();
    $transformedRequest = [
        'id' => 1
    ];

    $requestRepo = $this->getMockBuilder(RequestRepository::class)->disableOriginalConstructor()
    ->setMethods(['getRequestsByName', 'transform', 'getCompletedRequestByName'])->getMock();

    $requestRepo->method('getRequestsByName')->willReturnCallback(function ($passedName) use ($name, $requestMock) {
        $this->assertSame($name, $passedName);

        return [$requestMock, $requestMock];
    });

    $requestRepo->method('transform')->willReturnCallback(function ($request) use ($requestMock, $transformedRequest) {
        $this->assertSame($requestMock, $request);

        return $transformedRequest;
    });

    $i = 0;
    $requestRepo->method('getCompletedRequestByName')->willReturnCallback(function ($passedName) use ($name, $requestMock, &$i) {
        $this->assertSame($name, $passedName);
        if ($i == 0) {
            $i+=1;
            return null;
        } else {
            return $requestMock;
        }
    });

    $mockEntity->method('getRepository')->willReturnCallback(function ($requestClass) use ($requestRepo) {
        $this->assertSame(RequestEntity::class, $requestClass);

        return $requestRepo;
    });

    $requestManager = new RequestManager($mockEntity);
    $this->assertSame([$transformedRequest, $transformedRequest], $requestManager->getInfo(true, $name));

    $this->assertNull($requestManager->getInfo(false, $name));

    $this->assertSame($transformedRequest, $requestManager->getInfo(false, $name));
}


Share : facebook icon twitter icon

Unit test throwing an exception while connecting to asp.net web service


By : Ruler Badhon
Date : March 29 2020, 07:55 AM
around this issue You're doing an integration test here, as you are testing that your application can communicate with an external dependency.
If you wanted to unit test, you might want to explore a different approach.

Connecting a Test project to a WCF Service Automatically


By : Al Zoot
Date : March 29 2020, 07:55 AM
it helps some times There are 2 ways you can do this. Since you're using Windows Azure I assume you're using the emulator. Using the emulator means that the RoleEnvironment is available and you can get a list of roles, their instances, and their endpoints that are available.
code :
var endpoint = RoleEnvironment.Roles["WebRole1"].Instances.First().InstanceEndpoints["Endpoint1"];
var siteUrl = String.Format("{0}://{1}", endpoint.Protocol, endpoint.IPEndpoint);

Qt5 WebSockets test app not connecting to test service


By : Shawna
Date : March 29 2020, 07:55 AM
Does that help Opening websocket at "ws://echo.websocket.org" works for me just fine.
These handlers are sufficient in my project:
code :
connect(&webSocket, SIGNAL(connected()), this, SLOT(onConnected()));
connect(&webSocket, SIGNAL(disconnected()), this, SLOT(onDisconnected()));
connect(&webSocket, SIGNAL(textMessageReceived(const QString&)), this, SLOT(onTextMessageReceived(const QString&)));
    // you can try that immediately after opening the web socket and also using some QTimer
    m_webSocket.sendTextMessage("Pong!");

ASP. Net Web API service connecting to oracle database


By : Andras Alpar
Date : March 29 2020, 07:55 AM
may help you . I am new to AP.Net MVC services and Trying to create a web service where we give the array of input which will connect to oracle database and return the query (the array of input needs used in the filter)result. I am trying no to use the entity data model and giving the POCO classes in Model classes.So what I tried is to create a simple controller which selectentire data from the database , If you keep your "strQuery" variable, you can use the IN keyword :
code :
SELECT * FROM TABLE WHERE ID IN (id1, id2, ..., idn)
var ints = new int[] {1, 2, 3, 4, 5};
var ids= string.Join(",", ints.Select(x => x.ToString()).ToArray());// "1,2,3,4,5"

var strQuery = $@"Select PRIO_CATEGORY_ID as PRIO,LANG_ID as LANG, REC_DATE    as REC, REC_USER as RECUSER, RFCH_ID as RFCH,DESCR,COL_DESCR AS COL,ROW_DESCR as DROW,ABBR from STCD_PRIO_CATEGORY_DESCR where REC_USER IN({ids})";

WCF Service is not connecting to test client


By : user2869651
Date : March 29 2020, 07:55 AM
seems to work fine Since you don't seem to be using the default port, it is best to specify the port in your service binding. Change your service definition like this:
code :
<services>
  <service name="AgeCalculator.CalculateAge" behaviorConfiguration="MetadataBehavior">
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:50507/" />
      </baseAddresses>
    </host>
    <endpoint address="" 
        binding="basicHttpBinding" contract="AgeCalculator.IService1" />
    <endpoint address="mex" 
        binding="mexHttpBinding" contract="IMetadataExchange"/>
    <endpoint address="http://localhost:50507/Service1.svc" 
        binding="basicHttpBinding" contract="AgeCalculator.IService1"/>
  </service>
</services>
Related Posts Related Posts :
shadow
Privacy Policy - Terms - Contact Us © voile276.org