public void Index()
        {
            // Arrange
            Guid stackId       = Guid.NewGuid();
            Guid instanceIdOne = Guid.NewGuid();
            var  instanceOne   = new Instance {
                Name = "InstanceOne"
            };

            Guid instanceIdTwo = Guid.NewGuid();
            var  instanceTwo   = new Instance {
                Name = "InstanceTwo"
            };
            var instanceIds = new List <Guid> {
                instanceIdOne, instanceIdTwo
            };
            var stack = new Stack
            {
                Id          = stackId,
                Name        = "hoojey",
                InstanceIds = instanceIds
            };

            StackRepositoryMock.Setup(x => x.Find(stackId)).Returns(stack);
            InstanceRepositoryMock.Setup(x => x.Find(instanceIdOne)).Returns(instanceOne);
            InstanceRepositoryMock.Setup(x => x.Find(instanceIdTwo)).Returns(instanceTwo);

            var instanceModels = new List <InstanceOverviewViewModel>
            {
                new InstanceOverviewViewModel {
                    Name = instanceOne.Name
                },
                new InstanceOverviewViewModel {
                    Name = instanceTwo.Name
                }
            };

            var expectedModel = new StackInstancesViewModel
            {
                StackName = stack.Name,
                Instances = instanceModels
            };

            MappingEngineMock.Setup(engine => engine
                                    .Map <Instance, InstanceOverviewViewModel>(instanceOne))
            .Returns(instanceModels[0]);

            MappingEngineMock.Setup(engine => engine
                                    .Map <Instance, InstanceOverviewViewModel>(instanceTwo))
            .Returns(instanceModels[1]);

            // Act
            var actionResult = Controller.Index(stack.Id) as ViewResultBase;

            // Assert
            (actionResult.Model as StackInstancesViewModel).ShouldBeEquivalentTo(expectedModel, options => options.Excluding(vm => vm.StackRecordId));
        }
예제 #2
0
        public StackInstancesViewModel CreateStackInstancesViewModel(Stack stack)
        {
            var instances = GetInstances(stack);

            var model = new StackInstancesViewModel
            {
                StackName     = stack.Name,
                StackRecordId = stack.Id,
                Instances     = instances.Select(x => new InstanceOverviewViewModel {
                    State = x.State
                })
            };

            return(model);
        }
        public ActionResult Index(Guid id)
        {
            Stack stack = _stackRepository.Find(id);
            IEnumerable <Instance> instances = stack.InstanceIds.Select(x => _instanceRepository.Find(x)).Where(x => x != null).ToList();
            var instanceViewModels           = new List <InstanceOverviewViewModel>();

            var model = new StackInstancesViewModel
            {
                StackName           = stack.Name,
                StackRecordId       = id,
                StackPowerViewModel = _stackViewModelHelper.CreateStackPowerViewModel(stack)
            };

            foreach (var instance in instances)
            {
                var instanceOverviewViewModel = _mapper.Map <Instance, InstanceOverviewViewModel>(instance);
                if (instance.Role != null)
                {
                    var baseImageId = instance.Role.BaseImageId;
                    var baseImage   = _baseImageRepository.Find(baseImageId);

                    instanceOverviewViewModel.Image    = baseImage.Name;
                    instanceOverviewViewModel.Platform = baseImage.Platform;

                    var httpPort = instance.Role.Ports.FirstOrDefault(x => x.PortNumber == 80 || x.PortNumber == 443);
                    if (httpPort != null)
                    {
                        instanceOverviewViewModel.HttpAccessability = httpPort.PortNumber == 80
                                                        ? HttpAccessibility.Http
                                                        : HttpAccessibility.Https;
                    }
                }

                instanceViewModels.Add(instanceOverviewViewModel);
            }

            model.Instances = instanceViewModels;

            return(View(model));
        }