Exemplo n.º 1
0
        public void Returns_deployments_by_application_and_environment()
        {
            var criteria = new CriterionSet();

            criteria.AddCriterion(new Criterion(Deployment.APPLICATION, "SampleApp1"));
            criteria.AddCriterion(new Criterion(Deployment.ENVIRONMENT, "Environment"));
            criteria.OrderBy   = Deployment.DEPLOYED_ON;
            criteria.SortOrder = SortOrder.Descending;

            var foundDeployments = new Deployment[0];

            var mocks      = new MockRepository();
            var repository = mocks.CreateMock <IPersistentObjectRepository>();

            using (mocks.Record())
            {
                repository.ConfigurationFile = "deployer.hibernate.cfg.xml";
                Expect.Call(repository.FindAll <Deployment>(criteria)).Return(foundDeployments);
            }

            using (mocks.Playback())
            {
                IDeploymentRepository deploymentRepository = new DeploymentRepository(repository);

                var deployments = deploymentRepository.Find("SampleApp1", "Environment");

                Assert.That(deployments, Is.SameAs(foundDeployments));
            }

            mocks.VerifyAll();
        }
        public async void ShouldUpdateDeployment()
        {
            //Given
            var now         = DateTime.Now;
            var companyName = "New One";

            var calendar = await CalendarRepository.Add(now);

            await CompanyRepository.Add(new Company { Name = companyName }, true);

            var dbDeployment = new Deployment
            {
                Key          = 1,
                StartDateKey = calendar.Key,
                StartTime    = now.TimeOfDay,
                EndDateKey   = calendar.Key,
                EndTime      = now.TimeOfDay.Add(TimeSpan.FromHours(1))
            };

            await DeploymentRepository.Add(dbDeployment);

            // since we are modifying directly and not scoping, we'll need this
            Context.Entry(dbDeployment).State = EntityState.Detached;

            var controller = new DeploymentController(
                new Mock <ILogger <DeploymentController> >().Object,
                DeploymentRepository,
                CalendarRepository,
                CompanyRepository,
                VehicleRepository
                );

            var deploymentDTO = new DeploymentDTO
            {
                Key         = 1,
                StartTime   = now,
                EndTime     = now.AddHours(2),
                CompanyName = companyName
            };
            //When
            var result = await controller.Update(deploymentDTO.Key, deploymentDTO);

            dbDeployment = await DeploymentRepository.Find(1);

            //Then
            var viewResult = Assert.IsType <OkObjectResult>(result);
            var model      = Assert.IsType <DeploymentDTO>(viewResult.Value);

            Assert.NotNull(model);
            Assert.Equal(deploymentDTO.EndTime.Value.TimeOfDay, dbDeployment.EndTime);
        }