Ejemplo n.º 1
0
        public async Task TestUploadBatchesAsync_HasBatchToUpload()
        {
            using (ShimsContext.Create())
            {
                var userId = 1;
                appSettings.Add(AppSettings.SYSTEM_USER_ID_KEY, userId.ToString());
                var dto = new SevisBatchProcessingDTO
                {
                    BatchId       = "batchId",
                    SendString    = "<root></root>",
                    SevisOrgId    = "sevis org Id",
                    SevisUsername = "******"
                };
                service.Setup(x => x.GetNextBatchToUploadAsync()).ReturnsAsync(dto);

                var responseContent = "hello world";
                var message         = new HttpResponseMessage
                {
                    Content    = new StringContent(responseContent),
                    StatusCode = System.Net.HttpStatusCode.OK
                };
                var shimComm = new ECA.Net.Fakes.ShimSevisComm
                {
                    UploadAsyncXElementStringStringString = (xElement, batchId, sOrgId, sUsername) =>
                    {
                        Assert.AreEqual(dto.BatchId, batchId);
                        Assert.AreEqual(dto.SevisOrgId, sOrgId);
                        Assert.AreEqual(dto.SevisUsername, sUsername);
                        service.Setup(x => x.GetNextBatchToUploadAsync()).ReturnsAsync(null);
                        return(Task.FromResult <HttpResponseMessage>(message));
                    }
                };
                Action <User, SevisBatchProcessingDTO, Stream> callback = (u, d, s) =>
                {
                    Assert.AreEqual(userId, u.Id);
                    Assert.IsTrue(Object.ReferenceEquals(dto, d));
                    Assert.IsNotNull(s);
                    using (var streamReader = new StreamReader(s))
                    {
                        var stringContent = streamReader.ReadToEnd();
                        Assert.AreEqual(responseContent, stringContent);
                    }
                };
                responseHandler.Setup(x => x.HandleUploadResponseStreamAsync(It.IsAny <User>(), It.IsAny <SevisBatchProcessingDTO>(), It.IsAny <Stream>()))
                .Returns(Task.FromResult <Object>(null))
                .Callback(callback);

                await instance.UploadBatchesAsync(shimComm);

                responseHandler.Verify(x => x.HandleUploadResponseStreamAsync(It.IsAny <User>(), It.IsAny <SevisBatchProcessingDTO>(), It.IsAny <Stream>()), Times.Once());
            }
        }
Ejemplo n.º 2
0
        public async Task TestProcessAsync()
        {
            using (ShimsContext.Create())
            {
                var userId = 1;
                appSettings.Add(AppSettings.SYSTEM_USER_ID_KEY, userId.ToString());

                var uploadCalled   = false;
                var downloadCalled = false;
                var dto            = new SevisBatchProcessingDTO
                {
                    BatchId       = "batchId",
                    SendString    = "<root></root>",
                    SevisOrgId    = "sevis org Id",
                    SevisUsername = "******"
                };
                var responseContent = "hello world";
                var message         = new HttpResponseMessage
                {
                    Content    = new StringContent(responseContent),
                    StatusCode = System.Net.HttpStatusCode.OK
                };
                var shimComm = new ECA.Net.Fakes.ShimSevisComm
                {
                    UploadAsyncXElementStringStringString = (xElement, batchId, sOrgId, sUsername) =>
                    {
                        uploadCalled = true;
                        service.Setup(x => x.GetNextBatchToUploadAsync()).ReturnsAsync(null);
                        return(Task.FromResult <HttpResponseMessage>(message));
                    },
                    DownloadAsyncStringStringString = (batchId, sOrgId, sUsername) =>
                    {
                        downloadCalled = true;
                        service.Setup(x => x.GetNextBatchToDownloadAsync()).ReturnsAsync(null);
                        return(Task.FromResult <HttpResponseMessage>(message));
                    }
                };
                service.Setup(x => x.GetNextBatchToDownloadAsync()).ReturnsAsync(dto);
                service.Setup(x => x.GetNextBatchToUploadAsync()).ReturnsAsync(dto);
                await instance.ProcessAsync(service.Object, shimComm, settings);

                Assert.IsTrue(uploadCalled);
                Assert.IsTrue(downloadCalled);
                service.Verify(x => x.DeleteProcessedBatchesAsync(), Times.Once());
            }
        }
Ejemplo n.º 3
0
        public async Task TestDownloadBatceshAsync_NoBatches()
        {
            using (ShimsContext.Create())
            {
                var userId = 1;
                appSettings.Add(AppSettings.SYSTEM_USER_ID_KEY, userId.ToString());

                service.Setup(x => x.GetNextBatchToDownloadAsync()).ReturnsAsync(null);
                var shimComm = new ECA.Net.Fakes.ShimSevisComm
                {
                };

                await instance.DownloadBatchesAsync(shimComm);

                responseHandler.Verify(x => x.HandleDownloadResponseStreamAsync(It.IsAny <User>(), It.IsAny <SevisBatchProcessingDTO>(), It.IsAny <Stream>()), Times.Never());
            }
        }
Ejemplo n.º 4
0
        public async Task TestUploadBatchAsync_IsFailure()
        {
            using (ShimsContext.Create())
            {
                var userId = 1;
                appSettings.Add(AppSettings.SYSTEM_USER_ID_KEY, userId.ToString());
                var dto = new SevisBatchProcessingDTO
                {
                    Id            = 1,
                    BatchId       = "batchId",
                    SendString    = "<root></root>",
                    SevisOrgId    = "sevis org Id",
                    SevisUsername = "******"
                };
                var responseContent = "hello world";
                var message         = new HttpResponseMessage
                {
                    Content    = new StringContent(responseContent),
                    StatusCode = System.Net.HttpStatusCode.BadRequest
                };
                var shimComm = new ECA.Net.Fakes.ShimSevisComm
                {
                    UploadAsyncXElementStringStringString = (xElement, batchId, sOrgId, sUsername) =>
                    {
                        Assert.AreEqual(dto.BatchId, batchId);
                        Assert.AreEqual(dto.SevisOrgId, sOrgId);
                        Assert.AreEqual(dto.SevisUsername, sUsername);
                        return(Task.FromResult <HttpResponseMessage>(message));
                    }
                };
                Action <int, Exception> callback = (bId, exc) =>
                {
                    Assert.AreEqual(dto.Id, bId);
                    Assert.IsNull(exc);
                };

                service.Setup(x => x.HandleFailedUploadBatchAsync(It.IsAny <int>(), It.IsAny <Exception>()))
                .Returns(Task.FromResult <object>(null))
                .Callback(callback);

                await instance.UploadBatchAsync(shimComm, dto);

                service.Verify(x => x.HandleFailedUploadBatchAsync(It.IsAny <int>(), It.IsAny <Exception>()), Times.Once());
            }
        }