Beispiel #1
0
        public ModSicService CreateModSicServiceToReturnErrorInSendRequestResult()
        {
            var mocks = new MockRepository();
            var mockAPI = mocks.DynamicMock<ModSicConnection>(new string[] { "", "", "", "" });
            var fakeRequestResultWithErrors = new SendRequestResult() { HasErrors = true };
            Expect.Call(mockAPI.SendCollect(null, null, null, null, null)).IgnoreArguments().Return(fakeRequestResultWithErrors);
            mocks.ReplayAll();

            return new ModSicService(mockAPI);
        }
Beispiel #2
0
        public ModSicConnection CreateModSicServiceToSendCollectAndWaitItsCompletion()
        {
            var fakeRequestInfo = CreateRequestInfo(Guid.NewGuid().ToString(), FAKE_COLLECT_REQUEST_ID);
            var fakeSendCollectResult = new SendRequestResult() { Requests = new RequestInfo[] { fakeRequestInfo } };

            var fakeCollectInfo0 = CreateCollectInfo("10.1.0.1", "CollectRequests/1");
            var fakeCollectInfo1 = CreateCollectInfo("10.1.1.1", FAKE_COLLECT_REQUEST_ID);
            var fakeCollectInfo2 = CreateCollectInfo("10.1.1.2", "CollectRequests/1025");
            var fakeCollectionsInExecution = new CollectInfo[] { fakeCollectInfo0, fakeCollectInfo1, fakeCollectInfo2 };

            var mocks = new MockRepository();
            var api = mocks.StrictMock<ModSicConnection>(new string[] { "", "", "", "" });
            Expect.Call(api.SendCollect(null, null, null, null, null)).IgnoreArguments().Return(fakeSendCollectResult);
            Expect.Call(api.GetCollectionsInExecution()).Repeat.Times(5).Return(fakeCollectionsInExecution);
            Expect.Call(api.GetCollectionsInExecution()).Return(new CollectInfo[] { fakeCollectInfo2 });
            Expect.Call(api.GetOvalResults(FAKE_COLLECT_REQUEST_ID)).Return(FAKE_OVAL_RESULTS);
            mocks.ReplayAll();

            return api;
        }
Beispiel #3
0
        public ModSicService CreateModSicServiceToSendCollect(
            string fakeClientRequestID, string fakeServiceRequestID)
        {
            var fakeRequestInfo1 = new RequestInfo() { ClientRequestId = fakeClientRequestID, ServiceRequestId = fakeServiceRequestID };
            var fakeRequestInfo2 = new RequestInfo() { ClientRequestId = fakeServiceRequestID, ServiceRequestId = fakeClientRequestID };
            var fakeSendCollectResult = new SendRequestResult() { Requests = new RequestInfo[] { fakeRequestInfo1, fakeRequestInfo2 } };
            var fakeCertificate = new FileContentLoader().GetFileContentBytes(GetType().Assembly, "CollectService.pfx");
            var fakeCredentials = new Credential();
            var mocks = new MockRepository();
            
            var api = mocks.DynamicMock<ModSicConnection>(new string[] { "", "", "", "" });
            Expect.Call(
                api.SendCollect(FAKE_TARGET_ADDRESS, fakeCredentials, FAKE_OVAL_DEFINITIONS, null, null))
                       .IgnoreArguments()
                    .Return(fakeSendCollectResult);
            Expect.Call(
                api.GetCertificate())
                    .Return(fakeCertificate);
            mocks.ReplayAll();

            return new ModSicService(api);
        }
Beispiel #4
0
        public SendRequestResult SendRequest(Package collectPackage, string token)
        {
            var result = new SendRequestResult();

            try
            {
                string clientId;

                if (!CollectController.Authenticate(token, out clientId))
                {
                    throw new FaultException(INVALID_AUTHORIZATION_TOKEN);
                }

                var requestIds = CollectController.CollectRequest(collectPackage, clientId);
                result.Requests =
                    requestIds
                        .Select(x => new RequestInfo() { ClientRequestId = x.Key, ServiceRequestId = x.Value }).ToArray();
            }
            catch (Exception ex)
            {
                var logMessage = String.Format(EXECUTION_ERROR_MESSAGE, ex.Message, ex.StackTrace);
                Logger.Error(logMessage);
                result.HasErrors = true;
                result.Message = ex.Message;
            }

            return result;
        }