public void FromDTO_ReturnsServiceDTO_GivenService()
        {
            // Arrange
            var mockRepo   = new Mock <IServiceService <Service> >();
            var controller = new ServicesController(mockRepo.Object);

            // Act
            var result = controller.ToDTO(GetServiceSync(CodeServiceUsersControllerTests.GetListSync()));

            // Assert
            Assert.IsType <ServiceDTO>(result);
            Assert.Equal(1, result.Id);
            Assert.Equal("Test One", result.Name);
        }
        public async Task GetByName_ReturnsServiceDTO_GivenService()
        {
            // Arrange
            var mockRepo = new Mock <IServiceService <Service> >();
            var dbMock   = GetService(CodeServiceUsersControllerTests.GetListSync());

            mockRepo.Setup(x => x.GetByName(It.IsAny <string>())).Returns(dbMock);

            var controller = new ServicesController(mockRepo.Object);

            // Act
            var result = await controller.GetByName("Service Name");

            // Assert
            var okResult      = Assert.IsType <OkObjectResult>(result);
            var returnService = Assert.IsType <ServiceDTO>(okResult.Value);

            Assert.Equal("Test One", returnService.Name);
        }
        public void FromDTO_ReturnsListServiceDTO_GivenListService()
        {
            // Arrange
            var mockRepo = new Mock <IServiceService <Service> >();

            mockRepo.Setup(x => x.CurrentUserName()).Returns("moqUser");

            var controller = new ServicesController(mockRepo.Object);

            // Act
            var result = controller.ToDTO(GetServicesSync(CodeServiceUsersControllerTests.GetListSync()));

            // Assert
            Assert.IsType <List <ServiceDTO> >(result);
            Assert.Equal(3, result.Count);
            Assert.Equal("Test One", result.First().Name);
            Assert.Equal("Test Three", result[1].Name);
            Assert.Equal("Test Two", result.Last().Name);
        }
        public async Task FilterByNameInfiniteScroll_ReturnsServiceDTO_GivenService()
        {
            // Arrange
            var mockRepo = new Mock <IServiceService <Service> >();
            var dbMock   = GetServices(CodeServiceUsersControllerTests.GetListSync());

            mockRepo.Setup(x => x.FilterByNameInfiniteScroll(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>())).Returns(dbMock);

            var controller = new ServicesController(mockRepo.Object);

            // Act
            var result = await controller.FilterByNameInfiniteScroll("Test", 1, 3);

            // Assert
            var okResult      = Assert.IsType <OkObjectResult>(result);
            var returnService = Assert.IsType <List <ServiceDTO> >(okResult.Value);

            Assert.Equal(3, returnService.Count);
            Assert.Equal("Test One", returnService.First().Name);
        }
        public async Task Post_ReturnsServiceDTO_GivenServiceDTO()
        {
            // Arrange
            var mockRepo = new Mock <IServiceService <Service> >();
            var dbMock   = GetService(CodeServiceUsersControllerTests.GetListSync());

            mockRepo.Setup(x => x.Post(It.IsAny <Service>()))
            .Returns(dbMock).Verifiable();

            var controller = new ServicesController(mockRepo.Object);

            // Act
            var result = await controller.Post(new ServiceDTO(0, "Test One", "Description One"));

            // Assert
            mockRepo.VerifyAll();
            var okResult      = Assert.IsType <OkObjectResult>(result);
            var returnService = Assert.IsType <ServiceDTO>(okResult.Value);

            Assert.Equal("Test One", returnService.Name);
        }
        public async Task Get_ReturnsListServiceDTO_GivenListService()
        {
            // Arrange
            var mockRepo = new Mock <IServiceService <Service> >();
            var dbMock   = GetServices(CodeServiceUsersControllerTests.GetListSync());

            mockRepo.Setup(x => x.Get()).Returns(dbMock);

            var controller = new ServicesController(mockRepo.Object);

            // Act
            var result = await controller.Get();

            // Assert
            var okResult       = Assert.IsType <OkObjectResult>(result);
            var returnServices = Assert.IsType <List <ServiceDTO> >(okResult.Value);

            Assert.Equal(3, returnServices.Count);
            Assert.Equal("Test One", returnServices.First().Name);
            Assert.Equal("Test Three", returnServices[1].Name);
            Assert.Equal("Test Two", returnServices.Last().Name);
        }