Ejemplo n.º 1
0
        public async Task Blob_trigger_should_return_valid_stream_and_name()
        {
            var    logger = (ListLogger)TestFactory.CreateLogger(LoggerTypes.List);
            Stream s      = new MemoryStream();

            using (StreamWriter sw = new StreamWriter(s))
            {
                await sw.WriteLineAsync("This is a test");

                BlobFunction.Run(s, "TestBlob", logger);
            }
            var msg = logger.Logs[0];

            Assert.Contains("C# Blob trigger function Processed blob Name:TestBlob", msg);
        }
Ejemplo n.º 2
0
        public async void ResumeVisitorsCounterHttpTrigger_Should_Return_Json()
        {
            //Arrange
            var request = TestFactory.CreateHttpRequest(string.Empty, string.Empty);
            var counter = new Counter();

            counter.Id    = "index";
            counter.Count = 0;
            //Act
            var response = (HttpResponseMessage)GetResumeVisitorsCounterHttpTrigger.Run(request, counter, out counter, logger);
            var result   = await response.Content.ReadAsStringAsync();

            Counter counterActual = JsonConvert.DeserializeObject <Counter>(result);

            //Assert
            Assert.Equal(1, counterActual.Count);
        }
Ejemplo n.º 3
0
        public async void UploadFile_AlreadyUploadedImage()
        {
            //Arrange
            var request  = TestFactory.CreateHttpRequest("imageUrl", "https://media.gettyimages.com/photos/girl-near-the-mountains-picture-id485316112?s=612x612");
            var blobMock = new Mock <IBlobService>();

            blobMock.Setup(s => s.UploadImageAsync(It.IsAny <string>(), It.IsAny <string>())).Verifiable();

            var sqlMock = new Mock <ISqlService>();

            sqlMock.Setup(s => s.GetByUrlCountAsync(It.IsAny <string>())).Returns(Task.FromResult(1));
            sqlMock.Setup(s => s.InsertToDbAsync(It.IsAny <string>(), It.IsAny <string>())).Verifiable();

            var functions = new FunctionDefinitions(blobMock.Object, sqlMock.Object);

            //Act
            var response = await functions.Run(request, logger);

            Assert.IsType <BadRequestResult>(response);
        }
Ejemplo n.º 4
0
        public async void UploadFile_EmptyUrl()
        {
            //Arrange
            var request  = TestFactory.CreateHttpRequest("imageUrl", "");
            var blobMock = new Mock <IBlobService>();

            blobMock.Setup(s => s.UploadImageAsync(It.IsAny <string>(), It.IsAny <string>())).Verifiable();

            var sqlMock = new Mock <ISqlService>();

            sqlMock.Setup(s => s.GetByUrlCountAsync(It.IsAny <string>())).Returns(Task.FromResult(0));
            sqlMock.Setup(s => s.InsertToDbAsync(It.IsAny <string>(), It.IsAny <string>())).Verifiable();

            var functions = new FunctionDefinitions(blobMock.Object, sqlMock.Object);

            //Act
            var response = await functions.Run(request, logger);

            Assert.IsType <BadRequestResult>(response);
        }