Example #1
0
        public void Should_update_banner_with_correct_id()
        {
            var updateBanner = new PutBanner {
                Html = "html2"
            };
            var mappedPutBanner = new Banner {
                Id = 1, Html = updateBanner.Html
            };

            var storedBanner = new Banner {
                Id = 1, Html = "html1"
            };

            A.CallTo(() => _repository.TryGet(A <int> .Ignored, out storedBanner))
            .Returns(true)
            .AssignsOutAndRefParameters(storedBanner);

            Banner savedBanner = null;

            A.CallTo(() => _repository.TrySave(A <Banner> .Ignored))
            .Invokes((Banner banner) => savedBanner = banner)
            .Returns(true);

            Banner    oldBanner = null;
            PutBanner newBanner = null;

            A.CallTo(() => _mapper.Map(A <Banner> .Ignored, A <PutBanner> .Ignored))
            .Invokes((Banner banner, PutBanner putBanner) =>
            {
                oldBanner = banner;
                newBanner = putBanner;
            })
            .Returns(mappedPutBanner);

            var result = _controller.PutBanner(1, updateBanner) as StatusCodeResult;

            result.StatusCode.Should().Be(StatusCodes.Status200OK);

            oldBanner.Id.Should().Be(1);
            oldBanner.Html.Should().Be("html1");

            newBanner.Html.Should().Be("html2");

            savedBanner.Id.Should().Be(1);
            savedBanner.Html.Should().Be("html2");
        }