public async Task Add()
        {
            // given
            int      pageId   = 1;
            string   text     = "text";
            string   author   = "author";
            DateTime dateTime = DateTime.UtcNow;

            var repoPageVersion = new PageVersion()
            {
                PageId   = pageId,
                DateTime = dateTime,
                Author   = author,
                Text     = text
            };

            _pageVersionRepositoryMock
            .AddNewVersionAsync(pageId, text, author, dateTime)
            .Returns(repoPageVersion);

            // when
            PageVersionResponse actualResponse = await _pageVersionsController.Add(pageId, text, author, dateTime);

            // then
            actualResponse.PageId.ShouldBe(pageId);
            actualResponse.Text.ShouldBe(text);
            actualResponse.Author.ShouldBe(author);
            actualResponse.DateTime.ShouldBe(dateTime);

            await _pageVersionRepositoryMock
            .Received(1)
            .AddNewVersionAsync(pageId, text, author, dateTime);
        }
Exemple #2
0
        public async Task Add()
        {
            // given
            int      pageId   = 1;
            string   text     = "text";
            string   author   = "author";
            DateTime dateTime = DateTime.UtcNow;

            var repoPageVersion = new PageVersion()
            {
                PageId   = pageId,
                DateTime = dateTime,
                Author   = author,
                Text     = text
            };

            _pageVersionRepositoryMock
            .AddNewVersionAsync(pageId, text, author, dateTime)
            .Returns(repoPageVersion);

            // when
            ActionResult <PageVersionResponse> actionResult = await _pageVersionsController.Add(pageId, text, author, dateTime);

            // then
            actionResult.ShouldBeCreatedAtActionResult();

            PageVersionResponse response = actionResult.CreatedAtActionResultValue();

            response.PageId.ShouldBe(pageId);
            response.Text.ShouldBe(text);
            response.Author.ShouldBe(author);
            response.DateTime.ShouldBe(dateTime);
        }
        public async Task <ActionResult <PageVersionResponse> > Add(int pageId, string text, string author, DateTime?dateTime = null)
        {
            PageVersion pageVersion = await _pageVersionRepository.AddNewVersionAsync(pageId, text, author, dateTime);

            PageVersionResponse response = _objectsConverter.ConvertToPageVersionResponse(pageVersion);

            return(CreatedAtAction(nameof(Add), response));
        }
        public async Task <PageVersionResponse> Add(int pageId, string text, string author, DateTime?dateTime = null)
        {
            PageVersion pageVersion = await _pageVersionRepository.AddNewVersionAsync(pageId, text, author, dateTime);

            return(_objectsConverter.ConvertToPageVersionResponse(pageVersion));
        }