private void PopulateSelectListsToModel(BindingViewModel viewModel, IBinding binding)
        {
            if (viewModel != null)
            {
                if (viewModel.SelectedWebsiteId > 0)
                {
                    binding.Website = WebsiteService.GetById(viewModel.SelectedWebsiteId);
                }

                if (viewModel.SelectedServerIds.Any())
                {
                    if (binding.Servers == null)
                    {
                        binding.Servers = new HashSet <IServer>();
                    }
                    foreach (long selectedServerId in viewModel.SelectedServerIds)
                    {
                        binding.Servers.Add(ServerService.GetById(selectedServerId));
                    }
                }
                if (viewModel.SelectedEnvironmentIds.Any())
                {
                    if (binding.Environments == null)
                    {
                        binding.Environments = new HashSet <IEnvironment>();
                    }
                    foreach (long selectedEnvironmentId in viewModel.SelectedEnvironmentIds)
                    {
                        binding.Environments.Add(EnvironmentService.GetById(selectedEnvironmentId));
                    }
                }
            }
        }
        public void Should_Update_Existing_Environment(int id)
        {
            var fakeContext = new FakeContext("UpdateEnvironment");

            fakeContext.FillWith <Environment>();

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var repository        = new EnvironmentRepository(context);
                var validator         = new EnvironmentValidator();
                var service           = new EnvironmentService(repository, validator);
                var curretEnvironment = service.GetById(id);

                curretEnvironment.Name = "Testing";
                service.Update(curretEnvironment);
                Assert.Equal("Testing", service.GetById(id).Name);
                repository.Dispose();
            }
        }
        private HashSet <IEnvironment> PopulateEnvironments(ServerViewModel viewModel, IServer server)
        {
            var environments = new HashSet <IEnvironment>();

            foreach (long selectedEnvironmentId in viewModel.SelectedEnvironmentIds)
            {
                environments.Add(EnvironmentService.GetById(selectedEnvironmentId));
            }
            server.Environments = environments;
            return(environments);
        }
        public ActionResult Delete(int id, int?page)
        {
            var environment = EnvironmentService.GetById(id);

            if (environment != null)
            {
                EnvironmentService.Delete(environment);
            }

            return(RedirectToAction("Index", new { page }));
        }
        public void Should_Return_Right_Environment_When_Find_By_Id(int id)
        {
            var fakeContext = new FakeContext("EnvironmentById");

            fakeContext.FillWith <Environment>();

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var expected = fakeContext.GetFakeData <Environment>().Find(x => x.Id == id);

                var repository = new EnvironmentRepository(context);
                var validator  = new EnvironmentValidator();
                var service    = new EnvironmentService(repository, validator);
                var actual     = service.GetById(id);

                Assert.Equal(expected, actual, new EnvironmentIdComparer());
                repository.Dispose();
            }
        }
Exemple #6
0
        public void Should_Create_Correct_EnvironmentDTO_Object(int id)
        {
            var fakeContext = new FakeContext("EnvironmentDTOTest");

            fakeContext.FillWithAll();

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var repository = new EnvironmentRepository(context);
                var validator  = new EnvironmentValidator();
                var service    = new EnvironmentService(repository, validator);
                var mockMapper = new MapperConfiguration(cfg =>
                {
                    cfg.AddProfile <AutoMapperProfile>();;
                });
                var mapper = mockMapper.CreateMapper();

                var testEnv = service.GetById(id);
                var envDTO  = mapper.Map <Environment, EnvironmentDTO>(testEnv);

                Assert.IsType <EnvironmentDTO>(envDTO);
                Assert.Equal(testEnv.Name, envDTO.Name);
            }
        }
        public ActionResult Edit(long?id, int?page)
        {
            if (id.HasValue)
            {
                var viewModel = AutoMapper.Mapper.Map <IEnvironment, EnvironmentViewModel>(EnvironmentService.GetById(id.Value));
                viewModel.Products = ProductService.GetAll().ToList();
                if (viewModel.Product != null)
                {
                    viewModel.SelectedProductId = viewModel.Product.Id;
                }

                return(View(viewModel));
            }
            return(RedirectToAction("Create"));
        }