Ejemplo n.º 1
0
        private async Task <IActionResult> GetResponseByType(QrCodeController controller, object instance, string typeOverride)
        {
            var response = instance switch
            {
                CreateBookmarkModel => await controller.Bookmark(instance as CreateBookmarkModel),
                CreateCalendarEventModel => await controller.Calendar(instance as CreateCalendarEventModel),
                CreateContactDataEventModel => await controller.ContactData(instance as CreateContactDataEventModel),
                CreateEmailModel => await controller.Email(instance as CreateEmailModel),
                CreateGeoLocationModel => await controller.Geolocation(instance as CreateGeoLocationModel),
                CreateTextMessageModel => await controller.TextMessage(instance as CreateTextMessageModel),
                CreateWhatsAppMessageModel => await controller.WhatsApp(instance as CreateWhatsAppMessageModel),
                CreateUrlModel => await controller.Website(instance as CreateUrlModel),
                CreateWifiModel => await controller.Wifi(instance as CreateWifiModel),
                _ => null
            };

            if (typeOverride != null)
            {
                if (typeOverride == "text")
                {
                    response = await controller.Text(instance);
                }
                else if (typeOverride == "json")
                {
                    response = await controller.Json(instance);
                }
            }

            return(response);
        }
Ejemplo n.º 2
0
        private QrCodeController CreateController(bool modelStateInvalid = false)
        {
            var renderOptions = CreateQrCodeRenderOptions();
            var httpContext   = new DefaultHttpContext();

            httpContext.Request.Host   = new HostString("localhost");
            httpContext.Request.Scheme = "http";

            var controller = new QrCodeController(
                renderOptions,
                qrCodeRendererMock.Object,
                CreateApiKeyProvider(),
                imageServiceMock.Object,
                GetConfiguration()
                )
            {
                ControllerContext = new ControllerContext
                {
                    HttpContext = httpContext,
                }
            };

            if (modelStateInvalid)
            {
                controller.ModelState.AddModelError("key", "modelError");
            }

            return(controller);
        }
Ejemplo n.º 3
0
        public void Get_ShouldReturnProperHttpResponse()
        {
            var url = "http://github.com";

            var mockRepository = new Mock <IQrCodeService>();

            var expectedResponse = new HttpResponseMessage(HttpStatusCode.OK);

            mockRepository
            .Setup(x => x.GenerateQrCode(url))
            .Returns(expectedResponse);

            var controller = new QrCodeController(mockRepository.Object);

            var actualResponse = controller.Get(url);

            Assert.AreEqual(expectedResponse, actualResponse);
        }