Beispiel #1
0
        public void Delete_ExistingCompanyId_ReturnsOkResult()
        {
            _service.Setup(s => s.GetByIdAsync(1)).Returns(() => Task.FromResult(new Company()
            {
                Id = 1, Name = "Company1"
            }));
            var OkResult = ControllerUnderTest.Delete(1);

            Assert.IsType <OkResult>(OkResult.Result);
        }
Beispiel #2
0
        public async Task DeletePostShouldReturnRedirectToActionIndex()
        {
            var model = new DeleteViewModel();

            var result = await ControllerUnderTest.Delete(model);

            var redirectResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal(nameof(ToDoController.Index), redirectResult.ActionName);
        }
Beispiel #3
0
        public async Task DeleteGetViewModelShouldBeOfTypeDeleteViewModel()
        {
            MockService.Setup(svc => svc.GetAsync(FirstItem.Id)).ReturnsAsync(FirstItem);

            var result = await ControllerUnderTest.Delete(FirstItem.Id);

            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.IsAssignableFrom <DeleteViewModel>(viewResult.ViewData.Model);
        }
Beispiel #4
0
        public async Task DeletePostShouldCallDeleteItemAsyncOnceIfModelIsValid()
        {
            var model = new DeleteViewModel()
            {
                Name = nameof(DeletePostShouldCallDeleteItemAsyncOnceIfModelIsValid)
            };

            await ControllerUnderTest.Delete(model);

            MockService.Verify(mock => mock.DeleteItemAsync(It.IsAny <Guid>()), Times.Once);
        }
Beispiel #5
0
        public async Task DeleteGetViewModelShouldHaveCorrectProperties()
        {
            MockService.Setup(svc => svc.GetAsync(FirstItem.Id)).ReturnsAsync(FirstItem);

            var result = await ControllerUnderTest.Delete(FirstItem.Id);

            var viewResult = Assert.IsType <ViewResult>(result);
            var viewModel  = Assert.IsAssignableFrom <DeleteViewModel>(viewResult.ViewData.Model);

            Assert.Equal(FirstItem.Id, viewModel.Id);
            Assert.Equal(FirstItem.Name, viewModel.Name);
        }
            public void ReturnsInternalServerErrorOnFailure()
            {
                // arrange
                const string key = "key";

                MockPackScheduleService.Setup(m => m.RemoveProductionBatch(key))
                .Returns(new FailureResult <string>());

                // act
                var response = ControllerUnderTest.Delete(key);

                // assert
                Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);
            }
            public void ReturnsNotFoundOnInvalid()
            {
                // arrange
                const string key = "key";

                MockPackScheduleService.Setup(m => m.RemoveProductionBatch(key))
                .Returns(new InvalidResult <string>());

                // act
                var response = ControllerUnderTest.Delete(key);

                // assert
                Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
            }
            public void CallsServiceAsExpected()
            {
                // arrange
                const string key = "key";

                MockPackScheduleService.Setup(m => m.RemoveProductionBatch(key))
                .Returns(new SuccessResult <string>());

                // act
                ControllerUnderTest.Delete(key);

                // assert
                MockPackScheduleService.Verify(m => m.RemoveProductionBatch(key));
            }
Beispiel #9
0
        public async Task DeletePostShouldCallDeleteItemAsyncWithCorrectParameter()
        {
            var item = new ToDoItem()
            {
                Id = FirstItem.Id, Name = nameof(DeletePostShouldCallDeleteItemAsyncWithCorrectParameter)
            };
            var model = new DeleteViewModel()
            {
                Id = item.Id, Name = item.Name
            };

            await ControllerUnderTest.Delete(model);

            MockService.Verify(mock => mock.DeleteItemAsync(It.Is <Guid>(id => id.Equals(item.Id))), Times.Once);
        }
            public async void Should_return_NoContentResult_when_Id_is_valid()
            {
                // Arrange
                var userId = 6;
                // var returnResultObject = true;
                var returnExpectedStatusCode = 204;

                //Act
                var result = await ControllerUnderTest.Delete(userId);

                //Assert
                Assert.IsType <NoContentResult>(result);

                var NoContentResult = Assert.IsType <NoContentResult>(result);

                Assert.Equal(returnExpectedStatusCode, NoContentResult.StatusCode);
            }
            public async Task Post_Returns_RedirectToActionResult_When_Succeeds()
            {
                // Arrange
                const int    id = 1;
                const string expectedActionName = nameof(WorkoutsController.Index);

                WorkoutServiceMock
                .Setup(x => x.DeleteAsync(id))
                .Returns(Task.CompletedTask);

                // Act
                var result = await ControllerUnderTest.Delete(id);

                // Assert
                var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

                Assert.Equal(expectedActionName, redirectToActionResult.ActionName);
            }
            public async void Should_return_NoContentResult_when_Id_is_valid()
            {
                // Arrange
                var userId = 1;
                // var returnResultObject = true;
                var returnExpectedStatusCode = 204;

                ControllerUnderTest.ControllerContext.HttpContext.Request.Headers.Add("id", userId.ToString());

                //Act
                var result = await ControllerUnderTest.Delete();

                //Assert
                Assert.IsType <NoContentResult>(result);

                var NoContentResult = Assert.IsType <NoContentResult>(result);

                Assert.Equal(returnExpectedStatusCode, NoContentResult.StatusCode);
            }
Beispiel #13
0
            public async void Should_return_NotFoundResult_when_id_is_invalid()
            {
                // Arrange
                var unexistingUserId = 2;
                var key             = "User_StatusCode_404_NotFound";
                var localizedString = new LocalizedString(key, "Not Found");

                LocalizerMock
                .Setup(_ => _[key]).Returns(localizedString);

                UserServiceMock
                .Setup(o => o.RemoveAsync(unexistingUserId))
                .ThrowsAsync(new ArgumentException(unexistingUserId.ToString()));

                // Act
                var result = await ControllerUnderTest.Delete(unexistingUserId);

                // Assert
                Assert.IsType <NotFoundObjectResult>(result);
            }
Beispiel #14
0
        public void Delete_UnknownCompanyId_ReturnsNotFoundResult()
        {
            var notFoundResult = ControllerUnderTest.Delete(100);

            Assert.IsType <NotFoundResult>(notFoundResult.Result);
        }
Beispiel #15
0
        public async Task DeleteGetShouldCallGetAsyncOnce()
        {
            await ControllerUnderTest.Delete(Guid.Empty);

            MockService.Verify(mock => mock.GetAsync(It.IsAny <Guid>()), Times.Once);
        }
Beispiel #16
0
        public async Task DeleteGetWithInvalidIdShouldReturnNotFound()
        {
            var result = await ControllerUnderTest.Delete(Guid.Empty);

            Assert.IsType <NotFoundResult>(result);
        }