Esempio n. 1
0
        public void GetCatalogItemsTest()
        {
            var okObjectResult = _controller.Get();
            var okResult       = Assert.IsType <OkObjectResult>(okObjectResult.Result);
            var items          = Assert.IsType <List <CatalogItem> >(okResult.Value);

            Assert.Equal(2, items.Count);
        }
        public async Task CatalogWebApiGetId()
        {
            // Arrange
            CatalogController controller = new CatalogController(catalogService.Object);

            // Act
            OkNegotiatedContentResult <Product> result = await controller.Get("15") as OkNegotiatedContentResult <Product>;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("15", result.Content.Name);
        }
        public async Task CatalogWebApiGet()
        {
            // Arrange
            CatalogController controller = new CatalogController(catalogService.Object);

            // Act
            IEnumerable <Product> result = await controller.Get() as IEnumerable <Product>;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(totalProducts, result.Count());
        }
Esempio n. 4
0
            public void ReturnsCatalogOfServices()
            {
                var catalog   = new Catalog(Substitute.For <IDatabaseBuilder>());
                var service   = Substitute.For <ICloudFoundryService>();
                var serviceId = Guid.NewGuid();

                catalog.Services.Add(serviceId.ToString(), service);
                var controller = new CatalogController(catalog);

                IHttpActionResult result = controller.Get();
                var response             = result as OkNegotiatedContentResult <CatalogResponse>;

                Assert.NotNull(response);
                Assert.Equal(2, response.Content.Services.Count);
            }
Esempio n. 5
0
        public async Task GetTest()
        {
            //Arrange
            int fakeInventoryResponse = 15;
            var httpMessageHandler    = new Mock <HttpMessageHandler>();

            httpMessageHandler.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(),
                                                 ItExpr.IsAny <CancellationToken>())
            .Returns(Task.FromResult(new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(fakeInventoryResponse.ToString(), Encoding.UTF8, "application/json"),
            }));

            HttpClient httpClient = new HttpClient(httpMessageHandler.Object);

            httpClient.BaseAddress = new Uri(@"http://some.address.com/v1/");
            httpClient.DefaultRequestHeaders.Accept.Clear();
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            IPolicyRegistry <string>           mockRegistry    = new PolicyRegistry();
            IAsyncPolicy <HttpResponseMessage> httpRetryPolicy = Policy.NoOpAsync <HttpResponseMessage>();
            IAsyncPolicy httpClientTimeoutExceptionPolicy      = Policy.NoOpAsync();

            mockRegistry.Add("SimpleHttpRetryPolicy", httpRetryPolicy);
            mockRegistry.Add("SimpleHttpTimeoutPolicy", httpClientTimeoutExceptionPolicy);

            CatalogController controller = new CatalogController(mockRegistry, httpClient);

            //Act
            IActionResult result = await controller.Get(2);

            //Assert
            OkObjectResult resultObject = result as OkObjectResult;

            Assert.NotNull(resultObject);

            int number = (int)resultObject.Value;

            Assert.Equal(15, number);
        }
            public void ReturnsCatalogOfServices()
            {
                var catalog = new Catalog(Substitute.For<IDatabaseBuilder>());
                var service = Substitute.For<ICloudFoundryService>();
                var serviceId = Guid.NewGuid();
                catalog.Services.Add(serviceId.ToString(), service);
                var controller = new CatalogController(catalog);

                IHttpActionResult result = controller.Get();
                var response = result as OkNegotiatedContentResult<CatalogResponse>;

                Assert.NotNull(response);
                Assert.Equal(2, response.Content.Services.Count);
            }