public void Should_create_banner_with_correct_id() { var createBanner = new PostBanner { Id = 1, Html = "html1" }; var mappedPostBanner = new Banner { Id = createBanner.Id, Html = createBanner.Html }; Banner savedBanner = null; PostBanner mappedBanner = null; A.CallTo(() => _repository.TrySave(A <Banner> .Ignored)) .Invokes((Banner banner) => savedBanner = banner) .Returns(true); A.CallTo(() => _mapper.Map(A <PostBanner> .Ignored)) .Invokes((PostBanner banner) => mappedBanner = banner) .Returns(mappedPostBanner); var result = _controller.PostBanner(createBanner) as StatusCodeResult; result.StatusCode.Should().Be(StatusCodes.Status200OK); mappedBanner.Id.Should().Be(1); mappedBanner.Html.Should().Be("html1"); savedBanner.Id.Should().Be(1); savedBanner.Html.Should().Be("html1"); }
public void PostBanner() { // Arrange var controller = new BannerController(); controller.Request = new HttpRequestMessage(); controller.Configuration = new HttpConfiguration(); // Act var response = controller.GetBanner("10"); var actionResult = controller.PostBanner(new BannerModel { Id = "Banner1", Html = "Product1", createdOn = DateTime.Now, ModifiedOn = DateTime.Now }); // Assert BannerModel banner; Assert.IsTrue(response.TryGetContentValue <BannerModel>(out banner)); Assert.AreEqual(10, banner.Id); }