public void GetProducts_InternalServerError_InternalServerError() { var mockRepo = new Mock <IProductRepo>(); mockRepo.Setup(m => m.GetHttpProducts()).Throws(new Exception()); var service = new Controllers.ProductController(mockRepo.Object); var result = service.GetProductsAsync().Result; var expected = HttpStatusCode.InternalServerError; Assert.AreEqual(expected, result.StatusCode); }
public void GetProducts_HttpNoContent_HttpNoContent() { var mockRepo = new Mock <IProductRepo>(); var nullProducts = Task.FromResult(Enumerable.Empty <Dtos.Product>()); mockRepo.Setup(m => m.GetWcfProducts()).Returns(nullProducts); mockRepo.Setup(m => m.GetHttpProducts()).Returns(nullProducts); var service = new Controllers.ProductController(mockRepo.Object); var result = service.GetProductsAsync().Result; Assert.AreEqual(HttpStatusCode.NoContent, result.StatusCode); }
public void GetProducts_OnlyHttpProducts_HttpProducts() { var mockRepo = new Mock <IProductRepo>(); mockRepo.Setup(m => m.GetHttpProducts()).Returns(mockData.HttpData()); mockRepo.Setup(m => m.GetWcfProducts()).Returns(Task.FromResult(Enumerable.Empty <Dtos.Product>())); var service = new Controllers.ProductController(mockRepo.Object); var response = service.GetProductsAsync().Result; var result = response.Content.ReadAsAsync <IEnumerable <Dtos.Product> >().Result; var expected = mockData.HttpData().Result; expected.ShouldBeEquivalentTo(result, "Expected result not equal to actual result."); }
public void GetProducts_NoErrors_CheapestProducts() { var mockRepo = new Mock <IProductRepo>(); mockRepo.Setup(m => m.GetWcfProducts()).Returns(mockData.WcfData); mockRepo.Setup(m => m.GetHttpProducts()).Returns(mockData.HttpData); var service = new Controllers.ProductController(mockRepo.Object); var resultResponse = service.GetProductsAsync().Result; var result = resultResponse.Content.ReadAsAsync <IEnumerable <Dtos.Product> >().Result; var expected = mockData.TestGetCheapestProductsData().Content.ReadAsAsync <IEnumerable <Dtos.Product> >().Result; expected.ShouldBeEquivalentTo(result, "Expected response not the same as actual response."); }
public void GetProducts_WcfTimeoutException_HttpProducts() { var mockStore = new Mock <BazzasBazaar.IStore>(); mockStore.Setup(m => m.GetFilteredProducts(null, null, null, null)).Throws(new TimeoutException()); MockHttpMessageHandler mockHttp = new MockHttpMessageHandler(); HttpResponseMessage fakeResponse = new HttpResponseMessage(HttpStatusCode.OK); fakeResponse.Content = new StringContent(JsonConvert.SerializeObject(mockData.HttpData().Result), Encoding.UTF8, "application/json"); mockHttp.When("http://localhost:24697/api/*").Respond(fakeResponse); HttpClient client = new HttpClient(mockHttp); Dictionary <string, Uri> uri = new Dictionary <string, Uri> { { "Fake", new Uri("http://localhost:24697/api/Products") } }; var repo = new Repos.ProductRepo(client, mockStore.Object, uri); var service = new Controllers.ProductController(repo); var response = service.GetProductsAsync().Result; var results = response.Content.ReadAsAsync <IEnumerable <Dtos.Product> >().Result; var expected = mockData.HttpDataFake().Result; expected.ShouldBeEquivalentTo(results, "Expected results not equal to actual results."); }