Пример #1
0
        public async void DeleteWithValidIdRemovesUserSelection()
        {
            var testPoll = new Poll {
                Title = "TestPoll", UserSelections = PollControllerTests.TestData()
            };
            var userSelection = testPoll.UserSelections.First();

            userSelection.DateSelections = userSelection.DateSelections
                                           .OrderBy(ds => ds.Date)
                                           .ToList();

            await _pollsContext.Polls.AddAsync(testPoll);

            testPoll.AuthorId = userSelection.Id;

            await _pollsContext.SaveChangesAsync();

            var lastId            = testPoll.UserSelections.Last().Id;
            var deleteWithValidId = await _userSelectionsControllerToTest.DeleteUserSelection(lastId);

            Assert.IsType <ActionResult <UserSelection> >(deleteWithValidId);

            var deletedSelection = deleteWithValidId.Value;
            var deletedId        = deletedSelection.Id;

            Assert.Equal(lastId, deletedId);
            Assert.Null(await _pollsContext.UserSelections.FindAsync(lastId));
        }
Пример #2
0
        public async void PutWithInvalidIdReturnsNotFound()
        {
            var testSelection = PollControllerTests.TestData()[0];
            var id            = new Guid();

            testSelection.Id = id;

            var putForMissingSelection = await _userSelectionsControllerToTest.PutUserSelection(id, testSelection);

            Assert.IsType <NotFoundResult>(putForMissingSelection.Result);
        }
Пример #3
0
        public async void PutWithWrongIdReturnsBadRequest()
        {
            var testSelection = PollControllerTests.TestData()[0];
            await _pollsContext.AddAsync(testSelection);

            await _pollsContext.SaveChangesAsync();

            var wrongId = new Guid();

            var putWithWrongId = await _userSelectionsControllerToTest.PutUserSelection(wrongId, testSelection);

            Assert.IsType <BadRequestResult>(putWithWrongId.Result);
        }
Пример #4
0
        public async void PostReturnsCreatedAt()
        {
            var testSelection = PollControllerTests.TestData()[0];

            var result = await _userSelectionsControllerToTest.PostUserSelection(testSelection);

            Assert.IsType <CreatedAtActionResult>(result.Result);

            var createdAtResult = result.Result as CreatedAtActionResult;
            var postedSelection = createdAtResult.Value as UserSelection;

            Assert.Equal(testSelection.Name, postedSelection.Name);
            Assert.Equal(testSelection.DateSelections, postedSelection.DateSelections);
        }
Пример #5
0
        public async void PutWithNewNameChangesName()
        {
            var testSelection = PollControllerTests.TestData()[0];
            await _pollsContext.AddAsync(testSelection);

            await _pollsContext.SaveChangesAsync();

            var newName = "I am new";

            testSelection.Name = newName;

            var putWithNewName = await _userSelectionsControllerToTest.PutUserSelection(testSelection.Id, testSelection);

            Assert.IsType <NoContentResult>(putWithNewName.Result);

            var changedSelection = await _pollsContext.UserSelections.FindAsync(testSelection.Id);

            Assert.Equal(newName, changedSelection.Name);
        }
Пример #6
0
        public async void GetReturnsUserSelection()
        {
            var testSelection = PollControllerTests.TestData()[0];
            await _pollsContext.AddAsync(testSelection);

            await _pollsContext.SaveChangesAsync();

            var id = testSelection.Id;

            var fetchedSelection = await _userSelectionsControllerToTest.GetUserSelection(id);

            Assert.IsNotType <NotFoundResult>(fetchedSelection.Result);

            Assert.NotNull(fetchedSelection.Value);
            Assert.NotNull(fetchedSelection.Value.DateSelections);
            Assert.NotNull(fetchedSelection.Value.Name);

            Assert.Equal(testSelection.Name, fetchedSelection.Value.Name);
            Assert.Equal(testSelection.DateSelections, fetchedSelection.Value.DateSelections);
        }
Пример #7
0
        public async void PutWithNewDateSelectionsChangesDateSelections()
        {
            var testSelection = PollControllerTests.TestData()[0];
            await _pollsContext.AddAsync(testSelection);

            await _pollsContext.SaveChangesAsync();

            var newSelection = new List <DateSelection>(testSelection.DateSelections);

            newSelection.ForEach(ds => ds.State = SelectionState.Yes);
            testSelection.DateSelections        = newSelection;

            var putWithNewSelection = await _userSelectionsControllerToTest.PutUserSelection(testSelection.Id, testSelection);

            Assert.IsType <NoContentResult>(putWithNewSelection.Result);

            var changedSelection = await _pollsContext.UserSelections.FindAsync(testSelection.Id);

            Assert.Equal(newSelection, changedSelection.DateSelections);
        }
Пример #8
0
        public async void DeleteWithAuthorsIdReturnsBadRequest()
        {
            var testPoll = new Poll {
                Title = "TestPoll", UserSelections = PollControllerTests.TestData()
            };
            var userSelection = testPoll.UserSelections.First();

            userSelection.DateSelections = userSelection.DateSelections
                                           .OrderBy(ds => ds.Date)
                                           .ToList();

            await _pollsContext.Polls.AddAsync(testPoll);

            testPoll.AuthorId = userSelection.Id;

            await _pollsContext.SaveChangesAsync();

            var deleteWithAuthorId = await _userSelectionsControllerToTest.DeleteUserSelection(testPoll.AuthorId);

            Assert.IsType <BadRequestObjectResult>(deleteWithAuthorId.Result);
        }