Beispiel #1
0
        public async Task Add_should_call_repository_and_return_createdAtAction()
        {
            // given
            var pageRequest       = _fixture.Create <PageRequest>();
            int autoIncrementedId = 99;

            _pageRepositoryMock
            .AddNewPageAsync(Arg.Any <Page>())
            .Returns(c =>
            {
                var page = c.Arg <Page>();

                // the repository returns a new id (autoincremented)
                return(Task.FromResult(new Page()
                {
                    Id = autoIncrementedId,
                    Title = page.Title
                }));
            });

            // when
            ActionResult <PageResponse> actionResult = await _pagesController.Add(pageRequest);

            // then
            actionResult.ShouldBeCreatedAtActionResult();
            PageResponse pageResponse = actionResult.CreatedAtActionResultValue();

            pageResponse.ShouldNotBeNull("ActionResult's ViewModel was null");
            pageResponse.Id.ShouldBe(autoIncrementedId);
            pageResponse.Title.ShouldBe(pageRequest.Title);
        }
        public async Task CreateAdmin_should_create_user_with_usermanager_and_add_claim()
        {
            // given
            string email    = "*****@*****.**";
            string password = "******";

            _userManagerMock.CreateAsync(
                Arg.Is <RoadkillIdentityUser>(
                    u => u.Email == email &&
                    u.EmailConfirmed &&
                    u.UserName == email), password)
            .Returns(Task.FromResult(IdentityResult.Success));

            var requestModel = new UserRequest()
            {
                Email    = email,
                Password = password
            };

            // when
            ActionResult <string> actionResult = await _usersController.CreateAdmin(requestModel);

            // then
            actionResult.ShouldBeCreatedAtActionResult();
            string actualEmailAddress = actionResult.CreatedAtActionResultValue();

            actualEmailAddress.ShouldBe(email);
        }
Beispiel #3
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);
        }