コード例 #1
0
        public void GetAllEnvironments_ShouldCallService_AndReturn200WithDtos()
        {
            var expectedReturnFromService = new List <Environment>()
            {
                new Environment()
                {
                    Id = 1, Phase = "Teste"
                },
                new Environment()
                {
                    Id = 2, Phase = "T"
                }
            }.AsQueryable();

            _serviceMock.Setup(x => x.List()).Returns(expectedReturnFromService);

            var result = _controller.GetAllEnvironments();

            _serviceMock.Verify(x => x.List(), Times.Once);

            var objectResult = Assert.IsType <OkObjectResult>(result.Result);

            Assert.Equal(200, objectResult.StatusCode);

            var dtos = Assert.IsType <List <EnvironmentDTO> >(objectResult.Value);

            Assert.NotEmpty(dtos);
            Assert.Equal(expectedReturnFromService.Count(), dtos.Count());
        }
コード例 #2
0
        public void GetAllEnvironments_Invalid_TenantId()
        {
            //Given
            int tenantId = 0;

            //When
            var controller = new EnvironmentController(logger.Object, environmentServiceMoq.Object);
            var response   = controller.GetAllEnvironments(tenantId) as NotFoundObjectResult;

            //Then
            Assert.IsType <NotFoundObjectResult>(response);
            Assert.Equal($"Invalid tenantId : {tenantId}", response.Value);
        }
コード例 #3
0
        public void GetAllEnvironments_Successfull()
        {
            //Given
            int tenantId    = 1;
            var environment = new Environments()
            {
                Environment = "Devlopment", EnvId = 1
            };
            var envs = new List <Environments>()
            {
                environment
            };

            environmentServiceMoq.Setup(e => e.GetAllEnvironments(tenantId)).Returns(envs);

            //When
            var controller = new EnvironmentController(logger.Object, environmentServiceMoq.Object);
            var response   = controller.GetAllEnvironments(tenantId) as OkObjectResult;

            //Then
            Assert.IsType <OkObjectResult>(response);
            Assert.NotNull(response.Value);
            environmentServiceMoq.Verify(e => e.GetAllEnvironments(tenantId), Times.Once);
        }