public void GroupedAndZeroTestResults()
            {
                var utcNow = DateTime.UtcNow;

                var suiteDto = new SuiteDto {
                    SuiteID = 1, ApplicationId = 3, EnvironmentId = 4
                };
                var suiteDtos = new List <SuiteDto> {
                    suiteDto,
                    new SuiteDto {
                        SuiteID = 5, EnvironmentId = 3, ApplicationId = 4
                    }
                };
                var mockSuiteService = new Mock <ISuiteService>();

                mockSuiteService.Setup(s => s.Get(1)).Returns(suiteDto);
                mockSuiteService.Setup(s => s.GetAll()).Returns(suiteDtos);

                var latestTestResultDtos         = new List <LatestTestResultDto>();
                var mockLatestTestResultsService = new Mock <ILatestTestResultService>();

                mockLatestTestResultsService.Setup(s => s.Get(new int[] { 1 })).Returns(latestTestResultDtos);

                var mockTestFailureDurationService = new Mock <ITestFailureDurationService>();

                mockTestFailureDurationService.Setup(f => f.GetAll()).Returns(new List <TestFailureDurationDto>());

                var testResultService = new TestResultService(new Mock <IDbContext>().Object, mockLatestTestResultsService.Object,
                                                              mockTestFailureDurationService.Object, mockSuiteService.Object);
                var actualLatestTestResults = testResultService.GetLatestGrouped(1).ToList();

                Assert.AreEqual(0, actualLatestTestResults.Count);
            }
            public void GroupsMultipleSuites()
            {
                var utcNow = DateTime.UtcNow;

                var suiteDto = new SuiteDto {
                    SuiteID = 1, ApplicationId = 4, EnvironmentId = 3
                };
                var suiteDtos = new List <SuiteDto> {
                    suiteDto,
                    new SuiteDto {
                        SuiteID = 5, ApplicationId = 4, EnvironmentId = 3
                    }
                };
                var mockSuiteService = new Mock <ISuiteService>();

                mockSuiteService.Setup(s => s.Get(1)).Returns(suiteDto);
                mockSuiteService.Setup(s => s.GetAll()).Returns(suiteDtos);

                var latestTestResultDtos = new List <LatestTestResultDto> {
                    new LatestTestResultDto {
                        SuiteId         = 1,
                        TestResultID    = 2,
                        TestName        = "test1",
                        PassingFromDate = utcNow,
                    },
                    new LatestTestResultDto {
                        SuiteId         = 5,
                        TestResultID    = 6,
                        TestName        = "test2",
                        FailingFromDate = utcNow,
                    }
                };
                var mockLatestTestResultsService = new Mock <ILatestTestResultService>();

                mockLatestTestResultsService.Setup(s => s.Get(new int[] { 1, 5 })).Returns(latestTestResultDtos);

                var mockTestFailureDurationService = new Mock <ITestFailureDurationService>();

                mockTestFailureDurationService.Setup(f => f.GetAll()).Returns(new List <TestFailureDurationDto>());

                var testResultService = new TestResultService(new Mock <IDbContext>().Object, mockLatestTestResultsService.Object,
                                                              mockTestFailureDurationService.Object, mockSuiteService.Object);
                var actualLatestTestResults = testResultService.GetLatestGrouped(1).OrderBy(l => l.TestResultID).ToList();

                Assert.AreEqual(2, actualLatestTestResults.Count);

                Assert.AreEqual(2, actualLatestTestResults[0].TestResultID);
                Assert.AreEqual("test1", actualLatestTestResults[0].TestName);
                Assert.AreEqual(utcNow, actualLatestTestResults[0].PassingFromDate);
                Assert.IsNull(actualLatestTestResults[0].FailingFromDate);
                Assert.AreEqual(0, actualLatestTestResults[0].TestFailureDurations.ToList().Count);

                Assert.AreEqual(6, actualLatestTestResults[1].TestResultID);
                Assert.AreEqual("test2", actualLatestTestResults[1].TestName);
                Assert.AreEqual(utcNow, actualLatestTestResults[1].FailingFromDate);
                Assert.IsNull(actualLatestTestResults[1].PassingFromDate);
                Assert.AreEqual(0, actualLatestTestResults[1].TestFailureDurations.ToList().Count);
            }
        public IActionResult Put(int id, [FromBody] SuiteDto suiteRequest)
        {
            var suite           = MapearDtoParaDominio(suiteRequest);
            var suiteCadastrada = suiteRepository.AtualizarSuite(id, suite);

            var mensagem = suiteService.Validar(suiteCadastrada);

            if (mensagem.Any())
            {
                return(BadRequest(mensagem));
            }

            contexto.SaveChanges();
            return(Ok());
        }
        public IActionResult Post([FromBody] SuiteDto suiteRequest)
        {
            var suite           = MapearDtoParaDominio(suiteRequest);
            var suiteCadastrada = suiteRepository.SalvarSuite(suite);

            var mensagem = suiteService.Validar(suiteCadastrada);

            if (mensagem.Any())
            {
                return(BadRequest(mensagem));
            }

            contexto.SaveChanges();
            return(CreatedAtRoute("GetSuite", new { id = suite.Id }, suite));
        }
 private Suite MapearDtoParaDominio(SuiteDto suiteRequest)
 {
     return(new Suite(suiteRequest.Nome, suiteRequest.Descricao, suiteRequest.Capacidade, suiteRequest.ValorDiaria));
 }