public void AddAuction_ExpectSuccess() { // Arrange Auction auction = new Auction() { Title = "Dragon Plush Toy", Description = "Not a real dragon", User = "******", CurrentBid = 19.99 }; Mock <IRestClient> restClient = new Mock <IRestClient>(); restClient.Setup(x => x.Execute <Auction>(It.IsAny <IRestRequest>(), Method.POST)) .Returns(new RestResponse <Auction> { StatusCode = HttpStatusCode.OK, Data = new Auction { Id = 9, CurrentBid = 19.99, Description = "Not a real dragon", Title = "Dragon Plush Toy", User = "******" }, ResponseStatus = ResponseStatus.Completed }); APIService apiService = new APIService(restClient.Object); // Act Auction newAuction = apiService.AddAuction(auction); // Assert newAuction.Id.Should().Be(9); }
public void AddAuction_ExpectFailureResponse() { // Arrange Auction auction = new Auction() { Title = "\\", Description = "Bad data" }; Mock <IRestClient> restClient = new Mock <IRestClient>(); restClient.Setup(x => x.Execute <Auction>(It.Is <IRestRequest>(r => r.Resource == APIService.API_URL), Method.POST)) .Returns(new RestResponse <Auction> { StatusCode = HttpStatusCode.BadRequest, ResponseStatus = ResponseStatus.Completed }); APIService apiService = new APIService(restClient.Object); // Act Auction newAuction = apiService.AddAuction(auction); // Assert APIService.API_URL.Should().Be(EXPECTED_API_URL); restClient.Verify(x => x.Execute <Auction>(It.Is <IRestRequest>(r => r.Resource == EXPECTED_API_URL), Method.POST), Times.Once()); newAuction.Should().BeNull(); }
public void AddAuction_ExpectNoResponse() { // Arrange Auction auction = new Auction() { Title = "Dragon Plush Toy", Description = "Not a real dragon", User = "******", CurrentBid = 19.99 }; Mock <IRestClient> restClient = new Mock <IRestClient>(); restClient.Setup(x => x.Execute <Auction>(It.IsAny <IRestRequest>(), Method.POST)) .Returns(new RestResponse <Auction> { ResponseStatus = ResponseStatus.Error }); APIService apiService = new APIService(restClient.Object); // Act Auction newAuction = apiService.AddAuction(auction); // Assert newAuction.Should().BeNull(); }