public ActionResult Create(SpaceViewModel svm, HttpPostedFileBase upload)
        {
            string userid = this.Session["LogedUserid"].ToString();

            try
            {
                // TODO: Add insert logic here


                if (ModelState.IsValid)
                {
                    ShowroomdbContext ctx = new ShowroomdbContext();
                    space             s   = new space();
                    s.adress      = svm.Adress;
                    s.rentalPrice = svm.Prix;
                    s.description = svm.Description;
                    s.owner_id    = Int32.Parse(userid);
                    if (upload != null && upload.ContentLength > 0)
                    {
                        s.pic = Guid.NewGuid().ToString() + Path.GetFileName(upload.FileName);
                        upload.SaveAs(Path.Combine(Server.MapPath("~/Content/SpaceImages"), s.pic));
                    }
                    ctx.spaces.Add(s);
                    ctx.SaveChanges();
                    //service.Add(s);
                    //service.Commit();
                    return(RedirectToAction("Index"));
                }
                return(View());
            }
            catch
            {
                return(View());
            }
        }
        public async Task FetchChildren_ReturnsListOfApps_WithoutUpdatingChildren()
        {
            var receivedEvents = new List <string>();
            var fakeSpace      = new CloudFoundrySpace("junk", null, null);

            svm = new SpaceViewModel(fakeSpace, services);

            svm.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                receivedEvents.Add(e.PropertyName);
            };

            mockCloudFoundryService.Setup(mock => mock.GetAppsForSpaceAsync(fakeSpace))
            .ReturnsAsync(new List <CloudFoundryApp>
            {
                new CloudFoundryApp("fake app name 1", "fake app id 1", fakeSpace),
                new CloudFoundryApp("fake app name 2", "fake app id 2", fakeSpace)
            });

            var apps = await svm.FetchChildren();

            Assert.AreEqual(2, apps.Count);

            Assert.AreEqual(1, svm.Children.Count);
            Assert.IsNull(svm.Children[0]);

            // property changed events should not be raised
            Assert.AreEqual(0, receivedEvents.Count);

            mockCloudFoundryService.VerifyAll();
        }
Example #3
0
        public async Task RefreshChildren_AddsPlaceholder_WhenAllSpacesAreRemoved()
        {
            var fakeInitialSpace = new CloudFoundrySpace("fake space name", "fake space id", _sut.Org);
            var svm = new SpaceViewModel(fakeInitialSpace, null, null, Services);

            var fakeNoSpacesResult = new DetailedResult <List <CloudFoundrySpace> >(
                succeeded: true,
                content: new List <CloudFoundrySpace>(), // simulate org having lost all spaces before refresh
                explanation: null,
                cmdDetails: FakeSuccessCmdResult);

            MockCloudFoundryService.Setup(mock => mock.
                                          GetSpacesForOrgAsync(_sut.Org, true, It.IsAny <int>()))
            .ReturnsAsync(fakeNoSpacesResult);

            _sut.Children = new ObservableCollection <TreeViewItemViewModel> {
                svm
            };                                                                       // simulate org initially having 1 space child

            Assert.AreEqual(1, _sut.Children.Count);
            Assert.AreEqual(typeof(SpaceViewModel), _sut.Children[0].GetType());

            await _sut.RefreshChildren();

            Assert.AreEqual(1, _sut.Children.Count);
            Assert.AreEqual(typeof(PlaceholderViewModel), _sut.Children[0].GetType());
            Assert.AreEqual(OrgViewModel._emptySpacesPlaceholderMsg, _sut.Children[0].DisplayText);
        }
        public void LoadChildren_UpdatesAllSpaces()
        {
            var initialAppsList = new System.Collections.ObjectModel.ObservableCollection <TreeViewItemViewModel>
            {
                new AppViewModel(new CloudFoundryApp("initial app 1", null, null), services),
                new AppViewModel(new CloudFoundryApp("initial app 2", null, null), services),
                new AppViewModel(new CloudFoundryApp("initial app 3", null, null), services),
            };

            svm = new SpaceViewModel(new CloudFoundrySpace("fake space", null, null), services)
            {
                Children = initialAppsList
            };

            var newAppsList = new List <CloudFoundryApp>
            {
                new CloudFoundryApp("initial app 1", null, null),
                new CloudFoundryApp("initial app 2", null, null)
            };

            mockCloudFoundryService.Setup(mock => mock.GetAppsForSpaceAsync(It.IsAny <CloudFoundrySpace>()))
            .ReturnsAsync(newAppsList);

            Assert.AreEqual(initialAppsList.Count, svm.Children.Count);

            svm.IsExpanded = true;

            Assert.AreEqual(newAppsList.Count, svm.Children.Count);
            mockCloudFoundryService.VerifyAll();
        }
        public ActionResult Delete(Guid id)
        {
            CacheHelper.SetPreviousPage(_cache, Request.Headers["Referer"].ToString());
            SpaceViewModel model = new SpaceViewModel(_cache, id);

            return(View(model));
        }
        public async Task <ActionResult> Delete(SpaceViewModel model, string updateButton)
        {
            if (updateButton.Equals("Cancel"))
            {
                return(Redirect(CacheHelper.GetPreviousPage(_cache)));
            }

            try
            {
                if (await DigitalTwinsHelper.DeleteSpaceAsync(model.SelectedSpaceItem, _cache, Loggers.SilentLogger))
                {
                    return(Redirect(CacheHelper.GetPreviousPage(_cache)));
                }
                else
                {
                    model = new SpaceViewModel(_cache, model.SelectedSpaceItem.Id);

                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                await FeedbackHelper.Channel.SendMessageAsync(ex.InnerException.ToString(), MessageType.Info);

                return(View());
            }
        }
        public void Constructor_SetsDisplayTextToSpaceName()
        {
            string spaceName = "junk";
            string spaceId   = "junk";
            var    fakeSpace = new CloudFoundrySpace(spaceName, spaceId, null);

            svm = new SpaceViewModel(fakeSpace, services);

            Assert.AreEqual(spaceName, svm.DisplayText);
        }
 public SpaceViewModelTests()
 {
     _localDBServiceMock.Setup(dp => dp.GetRandomPoint()).Returns(SpaceNavigationMockData.Center());
     _localDBServiceMock.Setup(dp => dp.GetLocalSubjects(It.IsAny <SpaceNavigation>(), true))
     .Returns(PanoptesServiceMockData.TableSubjects());
     _localDBServiceMock.Setup(dp => dp.GetLocalSubjects(It.IsAny <SpaceNavigation>(), false))
     .Returns(PanoptesServiceMockData.TableSubjects());
     _cutoutServiceMock.Setup(dp => dp.GetSpaceCutout(It.IsAny <SpaceNavigation>())).ReturnsAsync(CutoutServiceMockData.SpaceCutout());
     _viewModel = new SpaceViewModel(_localDBServiceMock.Object, _cutoutServiceMock.Object);
 }
        public ActionResult Create(Guid parentId)
        {
            CacheHelper.SetPreviousPage(_cache, Request.Headers["Referer"].ToString());
            SpaceViewModel model = new SpaceViewModel(_cache);

            if (parentId != Guid.Empty)
            {
                model.SelectedSpaceItem.ParentSpaceId = parentId;
            }

            return(View(model));
        }
        public void LoadChildren_SetsSpecialDisplayText_WhenThereAreNoApps()
        {
            svm = new SpaceViewModel(new CloudFoundrySpace("fake space", null, null), services);
            List <CloudFoundryApp> emptyAppsList = new List <CloudFoundryApp>();

            mockCloudFoundryService.Setup(mock => mock.GetAppsForSpaceAsync(It.IsAny <CloudFoundrySpace>()))
            .ReturnsAsync(emptyAppsList);

            svm.IsExpanded = true;

            Assert.IsTrue(svm.DisplayText.Contains(" (no apps)"));
        }
        public ActionResult Edit(int id, SpaceViewModel svm)
        {
            space s = service.GetById(id);

            s.id          = svm.Id;
            s.adress      = svm.Adress;
            s.description = svm.Description;
            s.rentalPrice = svm.Prix;
            s.pic         = svm.Urlimage;
            service.Update(s);
            service.Commit();
            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Create(SpaceViewModel model, string createButton)
        {
            string previousPage = CacheHelper.GetPreviousPage(_cache);

            if (createButton.Equals("Cancel"))
            {
                return(Redirect(previousPage));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var spaceResult = await DigitalTwinsHelper.CreateSpaceAsync(model.SelectedSpaceItem, _cache, Loggers.SilentLogger);

                    switch (createButton)
                    {
                    case "Save & Close":
                        return(Redirect(previousPage));

                    case "Save & Create another":
                        return(RedirectToAction(nameof(Create)));

                    case "Save & Edit":
                        if (spaceResult.Id != Guid.Empty)
                        {
                            return(RedirectToAction(nameof(Edit), new { id = spaceResult.Id }));
                        }
                        else
                        {
                            return(Redirect(previousPage));
                        }

                    default:
                        return(RedirectToAction(nameof(List)));
                    }
                }
                catch (Exception ex)
                {
                    await FeedbackHelper.Channel.SendMessageAsync(ex.Message, MessageType.Info);

                    model = new SpaceViewModel(_cache);
                    return(View(model));
                }
            }
            else
            {
                return(View("Create"));
            }
        }
            public EmptyResultsAtNextTile()
            {
                _localDBServiceMock.Setup(dp => dp.FindNextAscendingDec(It.IsAny <double>())).Returns(new SpacePoint(0, 20));
                _localDBServiceMock.Setup(dp => dp.FindNextDescendingDec(It.IsAny <double>())).Returns(new SpacePoint(0, -20));
                _localDBServiceMock.Setup(dp => dp.FindNextAscendingRa(It.IsAny <double>())).Returns(new SpacePoint(20, 0));
                _localDBServiceMock.Setup(dp => dp.FindNextDescendingRa(It.IsAny <double>())).Returns(new SpacePoint(-20, 0));
                _localDBServiceMock.Setup(dp => dp.GetRandomPoint()).Returns(SpaceNavigationMockData.Center());
                _localDBServiceMock.Setup(dp => dp.GetLocalSubjects(It.IsAny <SpaceNavigation>(), true))
                .Returns(new List <TableSubject>());
                _localDBServiceMock.Setup(dp => dp.GetLocalSubjects(It.IsAny <SpaceNavigation>(), false))
                .Returns(new List <TableSubject>());
                _cutoutServiceMock.Setup(dp => dp.GetSpaceCutout(It.IsAny <SpaceNavigation>())).ReturnsAsync(new Lib.SpaceCutout());

                _viewModel = new SpaceViewModel(_localDBServiceMock.Object, _cutoutServiceMock.Object);
            }
        public async Task RefreshSpace_UpdatesChildrenOnSpaceViewModel()
        {
            var fakeSpace          = new CloudFoundrySpace("fake space name", "fake space id", null);
            var fakeSpaceViewModel = new SpaceViewModel(fakeSpace, services);

            var fakeAppName1 = "fake app 1";
            var fakeAppName2 = "fake app 2";
            var fakeAppName3 = "fake app 3";

            var fakeAppGuid1 = "fake app 1";
            var fakeAppGuid2 = "fake app 2";
            var fakeAppGuid3 = "fake app 3";

            fakeSpaceViewModel.Children = new ObservableCollection <TreeViewItemViewModel>
            {
                new AppViewModel(new CloudFoundryApp(fakeAppName1, fakeAppGuid1, fakeSpace), services)
            };

            fakeSpaceViewModel.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                receivedEvents.Add(e.PropertyName);
            };

            Assert.AreEqual(1, fakeSpaceViewModel.Children.Count);
            AppViewModel firstChildApp = (AppViewModel)fakeSpaceViewModel.Children[0];

            Assert.AreEqual(fakeAppName1, firstChildApp.App.AppName);

            mockCloudFoundryService.Setup(mock => mock.GetAppsForSpaceAsync(fakeSpace)).ReturnsAsync(new List <CloudFoundryApp>
            {
                new CloudFoundryApp(fakeAppName2, fakeAppGuid2, fakeSpace),
                new CloudFoundryApp(fakeAppName3, fakeAppGuid3, fakeSpace)
            });

            await vm.RefreshSpace(fakeSpaceViewModel);

            Assert.AreEqual(2, fakeSpaceViewModel.Children.Count);
            AppViewModel firstNewChildApp  = (AppViewModel)fakeSpaceViewModel.Children[0];
            AppViewModel secondNewChildApp = (AppViewModel)fakeSpaceViewModel.Children[1];

            Assert.AreEqual(fakeAppName2, firstNewChildApp.App.AppName);
            Assert.AreEqual(fakeAppName3, secondNewChildApp.App.AppName);

            // property changed events should not be raised
            Assert.AreEqual(0, receivedEvents.Count);

            mockCloudFoundryService.VerifyAll();
        }
        public async Task RefreshOrg_UpdatesChildrenOnOrgViewModel()
        {
            var fakeOrg          = new CloudFoundryOrganization("fake org name", "fake org id", null);
            var fakeOrgViewModel = new OrgViewModel(fakeOrg, services);

            var fakeSpaceName1 = "fake space 1";
            var fakeSpaceName2 = "fake space 2";
            var fakeSpaceName3 = "fake space 3";

            var fakeSpaceGuid1 = "fake space 1";
            var fakeSpaceGuid2 = "fake space 2";
            var fakeSpaceGuid3 = "fake space 3";

            fakeOrgViewModel.Children = new ObservableCollection <TreeViewItemViewModel>
            {
                new SpaceViewModel(new CloudFoundrySpace(fakeSpaceName1, fakeSpaceGuid1, fakeOrg), services)
            };

            fakeOrgViewModel.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                receivedEvents.Add(e.PropertyName);
            };

            Assert.AreEqual(1, fakeOrgViewModel.Children.Count);
            SpaceViewModel firstChildSpace = (SpaceViewModel)fakeOrgViewModel.Children[0];

            Assert.AreEqual(fakeSpaceName1, firstChildSpace.Space.SpaceName);

            mockCloudFoundryService.Setup(mock => mock.GetSpacesForOrgAsync(fakeOrg)).ReturnsAsync(new List <CloudFoundrySpace>
            {
                new CloudFoundrySpace(fakeSpaceName2, fakeSpaceGuid2, fakeOrg),
                new CloudFoundrySpace(fakeSpaceName3, fakeSpaceGuid3, fakeOrg)
            });

            await vm.RefreshOrg(fakeOrgViewModel);

            Assert.AreEqual(2, fakeOrgViewModel.Children.Count);
            SpaceViewModel firstNewChildSpace  = (SpaceViewModel)fakeOrgViewModel.Children[0];
            SpaceViewModel secondNewChildSpace = (SpaceViewModel)fakeOrgViewModel.Children[1];

            Assert.AreEqual(fakeSpaceName2, firstNewChildSpace.Space.SpaceName);
            Assert.AreEqual(fakeSpaceName3, secondNewChildSpace.Space.SpaceName);

            // property changed events should not be raised
            Assert.AreEqual(0, receivedEvents.Count);

            mockCloudFoundryService.VerifyAll();
        }
        public SpaceView()
        {
            InitializeComponent();
            ViewModel = DataContext as SpaceViewModel;
            ViewModel.AnimateMovement += AnimateCutoutMovement;

            GalaxyPulseTimer.Tick  += new EventHandler(PulseGalaxies);
            MoveMapPulseTimer.Tick += new EventHandler(PulseButtons);

            GalaxyPulseTimer.Interval  = new TimeSpan(0, 0, 10);
            MoveMapPulseTimer.Interval = new TimeSpan(0, 0, 10);
            GalaxyPulseTimer.Start();
            MoveMapPulseTimer.Start();

            Messenger.Default.Register <object>(this, OnNewUserGalaxyPulse, "New_User_Galaxy_Pulse");
        }
Example #17
0
        public async Task <IActionResult> Update(string id, SpaceViewModel spaceIn)
        {
            if (ModelState.IsValid)
            {
                var space = await _spaceService.Get(id);

                if (space == null)
                {
                    return(NotFound());
                }
                try
                {
                    if (spaceIn.assets.Any())
                    {
                        var assets = await _assetService.Get(spaceIn.assets);

                        space.assests = assets;
                    }
                    else
                    {
                        space.assests = new List <Asset>();
                    }
                    space.Capacity    = spaceIn.Capacity;
                    space.Name        = spaceIn.Name;
                    space.SpaceTypeId = spaceIn.SpaceTypeId;
                    space.Tags        = spaceIn.Tags;
                    await _spaceService.Update(space);
                }
                catch (RessourceTypeRepositoryException ex)
                {
                    ModelState.AddModelError(ex.Field, ex.Message);
                    return(BadRequest(new ValidationProblemDetails(ModelState)));
                }
                catch (SpaceRepositoryException ex)
                {
                    ModelState.AddModelError(ex.Field, ex.Message);
                    return(BadRequest(new ValidationProblemDetails(ModelState)));
                }
                catch (AssetRepositoryException ex)
                {
                    ModelState.AddModelError(ex.Field, ex.Message);
                    return(BadRequest(new ValidationProblemDetails(ModelState)));
                }
                return(CreatedAtRoute("GetSpace", new { id = space.Id.ToString() }, space));
            }
            return(BadRequest(new ValidationProblemDetails(ModelState)));
        }
        //public SpaceController()
        //{
        //    service = new SpaceService();
        //}
        // GET: Space
        public ActionResult Index()
        {
            IEnumerable <space>    ListSpace      = service.GetMany();
            IList <SpaceViewModel> ListSpaceModel = new List <SpaceViewModel>();

            foreach (space s in ListSpace)
            {
                SpaceViewModel svm = new SpaceViewModel();
                // svm.Id = s.id;
                svm.Adress      = s.adress;
                svm.Description = s.description;

                svm.Prix     = (int)s.rentalPrice;
                svm.Urlimage = s.pic;
                ListSpaceModel.Add(svm);
            }
            return(View(ListSpaceModel));
        }
Example #19
0
 /// <summary>
 /// if this space's data context is changed, subscribe/unsubscribe to events on the corresponding view model for dragging and dropping pieces into the space
 /// </summary>
 /// <param name="sender">source of data context change</param>
 /// <param name="e">property change details</param>
 private void GameSpace_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     if (e.NewValue is SpaceViewModel && !subscribed)
     {
         SpaceViewModel model = e.NewValue as SpaceViewModel;
         DragEnter += model.DragPieceIn;
         DragLeave += model.DragPieceOut;
         Drop      += model.DropPiece;
         subscribed = true;
     }
     else if (!(e.NewValue is SpaceViewModel) && subscribed)
     {
         SpaceViewModel model = e.OldValue as SpaceViewModel;
         DragEnter -= model.DragPieceIn;
         DragLeave -= model.DragPieceOut;
         Drop      -= model.DropPiece;
         subscribed = false;
     }
 }
Example #20
0
        public async Task <ActionResult <Space> > Create(SpaceViewModel spaceIn)
        {
            if (ModelState.IsValid)
            {
                var space = new Space
                {
                    Capacity    = spaceIn.Capacity,
                    Name        = spaceIn.Name,
                    SpaceTypeId = spaceIn.SpaceTypeId,
                    Tags        = spaceIn.Tags
                };
                try
                {
                    if (spaceIn.assets.Any())
                    {
                        var assets = await _assetService.Get(spaceIn.assets);

                        space.assests = assets;
                    }
                    var result = await _spaceService.Create(space);
                }
                catch (RessourceTypeRepositoryException ex)
                {
                    ModelState.AddModelError(ex.Field, ex.Message);
                    return(BadRequest(new ValidationProblemDetails(ModelState)));
                }
                catch (SpaceRepositoryException ex)
                {
                    ModelState.AddModelError(ex.Field, ex.Message);
                    return(BadRequest(new ValidationProblemDetails(ModelState)));
                }
                catch (AssetRepositoryException ex)
                {
                    ModelState.AddModelError(ex.Field, ex.Message);
                    return(BadRequest(new ValidationProblemDetails(ModelState)));
                }
                return(CreatedAtRoute("GetSpace", new { id = space.Id.ToString() }, space));
            }
            return(BadRequest(new ValidationProblemDetails(ModelState)));
        }
Example #21
0
        public void TestInit()
        {
            RenewMockServices();

            MockUiDispatcherService.Setup(mock => mock.
                                          RunOnUiThread(It.IsAny <Action>()))
            .Callback <Action>(action =>
            {
                // Run whatever method is passed to MockUiDispatcherService.RunOnUiThread; do not delegate to the UI Dispatcher
                action();
            });

            _fakeTasExplorerViewModel = new TasExplorerViewModel(Services);
            _fakeCfInstanceViewModel  = new CfInstanceViewModel(FakeCfInstance, _fakeTasExplorerViewModel, Services, expanded: true);
            _fakeOrgViewModel         = new OrgViewModel(FakeCfOrg, _fakeCfInstanceViewModel, _fakeTasExplorerViewModel, Services);
            _sut = new SpaceViewModel(FakeCfSpace, _fakeOrgViewModel, _fakeTasExplorerViewModel, Services);

            _receivedEvents       = new List <string>();
            _sut.PropertyChanged += (sender, e) =>
            {
                _receivedEvents.Add(e.PropertyName);
            };
        }
        // GET: Space/Edit/5
        public ActionResult Edit(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            space          s   = service.GetById(id);
            SpaceViewModel svm = new SpaceViewModel();

            if (s == null)
            {
                return(HttpNotFound());
            }
            else
            {
                svm.Id          = s.id;
                svm.Prix        = (int)s.rentalPrice;
                svm.Adress      = s.adress;
                svm.Description = s.description;
                svm.Urlimage    = s.pic;
                return(View(svm));
            }
        }
Example #23
0
        public SpaceGameView(
            MessageService_ToServer messageService,
            BackgroundManager background,
            BloomComponent bloom,
            Camera2D camera,
            ParticleManager particleManager,
            ProjectileManager projectileManager,
            ClientShipManager clientShipManager,
            SpaceManager spaceManager,
            SpaceObjectManager spaceObjectManager,
            SpriteBatch spriteBatch,
            UIConversionService uiConversionService,
            FloatyAreaObjectManager floatyAreaObjectManager,
            SpaceViewModel viewModel,
            GlobalGameUI globalGameUi
            )
        {
            _background              = background;
            _bloom                   = bloom;
            _particleManager         = particleManager;
            _projectileManager       = projectileManager;
            _clientShipManager       = clientShipManager;
            _spaceObjectManager      = spaceObjectManager;
            _spaceManager            = spaceManager;
            _spriteBatch             = spriteBatch;
            _uiConversionService     = uiConversionService;
            _spaceViewModel          = viewModel;
            _floatyAreaObjectManager = floatyAreaObjectManager;
            _messageService          = messageService;


            globalGameUi.RegisterCallbackVoid("ChangeZoom", ChangeZoom);

            Camera      = camera;
            Camera.Zoom = 1f;
        }
Example #24
0
        public async Task FetchChildren_SetsAuthenticationRequiredToTrue_WhenSpacesRequestFailsBecauseOfInvalidRefreshToken()
        {
            _sut = new SpaceViewModel(FakeCfSpace, _fakeOrgViewModel, _fakeTasExplorerViewModel, Services, expanded: true);

            var fakeFailedResult =
                new DetailedResult <List <CloudFoundryApp> >(succeeded: false, content: null, explanation: "junk", cmdDetails: FakeFailureCmdResult)
            {
                FailureType = FailureType.InvalidRefreshToken,
            };

            MockCloudFoundryService.Setup(mock => mock.
                                          GetAppsForSpaceAsync(_sut.Space, true, It.IsAny <int>()))
            .ReturnsAsync(fakeFailedResult);

            Assert.IsFalse(_sut.ParentTasExplorer.AuthenticationRequired);

            var result = await _sut.FetchChildren();

            Assert.IsTrue(_sut.ParentTasExplorer.AuthenticationRequired);

            MockErrorDialogService.Verify(mock => mock.
                                          DisplayErrorDialog(It.IsAny <string>(), It.IsAny <string>()),
                                          Times.Never);
        }
        public async Task RefreshAllCloudConnections_RefreshesEachTreeViewItemViewModel()
        {
            var eventsRaisedByCFIVM = new List <string>();
            var eventsRaisedByOVM   = new List <string>();
            var eventsRaisedBySVM   = new List <string>();
            var eventsRaisedByAVM   = new List <string>();

            var fakeCfInstance = new CloudFoundryInstance("fake cf name", "http://fake.api.address", "fake-token");

            mockCloudFoundryService.SetupGet(mock => mock.CloudFoundryInstances)
            .Returns(new Dictionary <string, CloudFoundryInstance> {
                { "fake cf name", fakeCfInstance }
            });

            var cfivm = new CfInstanceViewModel(fakeCfInstance, services);

            cfivm.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                eventsRaisedByCFIVM.Add(e.PropertyName);
            };

            var fakeOrg = new CloudFoundryOrganization("fake org name", "fake org id", fakeCfInstance);
            var ovm     = new OrgViewModel(fakeOrg, services);

            ovm.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                eventsRaisedByOVM.Add(e.PropertyName);
            };

            var fakeSpace = new CloudFoundrySpace("fake space name", "fake space id", fakeOrg);
            var svm       = new SpaceViewModel(fakeSpace, services);

            svm.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                eventsRaisedBySVM.Add(e.PropertyName);
            };

            var fakeApp = new CloudFoundryApp("fake app name", "fake app id", fakeSpace);
            var avm     = new AppViewModel(fakeApp, services);

            avm.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                eventsRaisedByAVM.Add(e.PropertyName);
            };

            mockCloudFoundryService.Setup(mock => mock.GetOrgsForCfInstanceAsync(fakeCfInstance)).ReturnsAsync(
                new List <CloudFoundryOrganization> {
                fakeOrg
            });

            mockCloudFoundryService.Setup(mock => mock.GetSpacesForOrgAsync(fakeOrg)).ReturnsAsync(
                new List <CloudFoundrySpace> {
                fakeSpace
            });

            mockCloudFoundryService.Setup(mock => mock.GetAppsForSpaceAsync(fakeSpace)).ReturnsAsync(
                new List <CloudFoundryApp> {
                fakeApp
            });

            cfivm.Children = new ObservableCollection <TreeViewItemViewModel> {
                ovm
            };

            ovm.Children = new ObservableCollection <TreeViewItemViewModel> {
                svm
            };

            svm.Children = new ObservableCollection <TreeViewItemViewModel> {
                avm
            };

            vm.CloudFoundryList = new List <CfInstanceViewModel> {
                cfivm
            };


            await vm.RefreshAllCloudConnections(null);

            Assert.AreEqual(1, cfivm.Children.Count);
            Assert.AreEqual(ovm, cfivm.Children[0]);
            Assert.AreEqual(1, eventsRaisedByCFIVM.Count);
            Assert.AreEqual("Children", eventsRaisedByCFIVM[0]);

            Assert.AreEqual(1, ovm.Children.Count);
            Assert.AreEqual(svm, ovm.Children[0]);
            Assert.AreEqual(1, eventsRaisedByOVM.Count);
            Assert.AreEqual("Children", eventsRaisedByOVM[0]);

            Assert.AreEqual(1, svm.Children.Count);
            Assert.AreEqual(avm, svm.Children[0]);
            Assert.AreEqual(1, eventsRaisedBySVM.Count);
            Assert.AreEqual("Children", eventsRaisedBySVM[0]);

            Assert.AreEqual(1, eventsRaisedByAVM.Count);
            Assert.AreEqual("IsStopped", eventsRaisedByAVM[0]);

            // ensure all view models issued queries for updated lists of children
            mockCloudFoundryService.VerifyAll();
        }
        public async Task RefreshAllCloudConnections_DoesNotThrowExceptions_WhenSpacesHaveNullChildren()
        {
            var fakeCfInstance = new CloudFoundryInstance("fake cf name", "http://fake.api.address", "fake-token");

            mockCloudFoundryService.SetupGet(mock => mock.CloudFoundryInstances)
            .Returns(new Dictionary <string, CloudFoundryInstance> {
                { "fake cf name", fakeCfInstance }
            });

            var cfivm = new CfInstanceViewModel(fakeCfInstance, services);

            var fakeOrg = new CloudFoundryOrganization("fake org name", "fake org id", fakeCfInstance);
            var ovm     = new OrgViewModel(fakeOrg, services);

            var fakeSpace = new CloudFoundrySpace("fake space name", "fake space id", fakeOrg);
            var svm       = new SpaceViewModel(fakeSpace, services);

            cfivm.Children = new ObservableCollection <TreeViewItemViewModel>
            {
                ovm
            };

            ovm.Children = new ObservableCollection <TreeViewItemViewModel>
            {
                svm
            };

            // check for presence of Dummy child (sanity check)
            Assert.AreEqual(1, svm.Children.Count);
            Assert.IsNull(svm.Children[0]);

            mockCloudFoundryService.Setup(mock => mock.GetOrgsForCfInstanceAsync(fakeCfInstance)).ReturnsAsync(new List <CloudFoundryOrganization>
            {
                fakeOrg
            });

            mockCloudFoundryService.Setup(mock => mock.GetSpacesForOrgAsync(fakeOrg)).ReturnsAsync(new List <CloudFoundrySpace>
            {
                fakeSpace
            });

            mockCloudFoundryService.Setup(mock => mock.GetAppsForSpaceAsync(fakeSpace)).ReturnsAsync(new List <CloudFoundryApp>());

            vm.CloudFoundryList = new List <CfInstanceViewModel>
            {
                cfivm
            };

            Exception shouldStayNull = null;

            try
            {
                await vm.RefreshAllCloudConnections(null);
            }
            catch (Exception e)
            {
                shouldStayNull = e;
            }

            Assert.IsNull(shouldStayNull);

            Assert.AreEqual(1, cfivm.Children.Count);
            Assert.AreEqual(ovm, cfivm.Children[0]);

            Assert.AreEqual(1, ovm.Children.Count);
            Assert.AreEqual(svm, ovm.Children[0]);

            Assert.AreEqual(1, svm.Children.Count);
            Assert.IsNull(svm.Children[0]);

            mockCloudFoundryService.VerifyAll();
        }
Example #27
0
        public async Task RefreshOrg_UpdatesChildrenOnOrgViewModel()
        {
            var fakeSpaceName1 = "fake space 1";
            var fakeSpaceName2 = "fake space 2";
            var fakeSpaceName3 = "fake space 3";
            var fakeSpaceName4 = "fake space 4";

            var fakeSpaceGuid1 = "fake space 1";
            var fakeSpaceGuid2 = "fake space 2";
            var fakeSpaceGuid3 = "fake space 3";
            var fakeSpaceGuid4 = "fake space 4";

            _sut.Children = new ObservableCollection <TreeViewItemViewModel>
            {
                // to be removed:
                new SpaceViewModel(new CloudFoundrySpace(fakeSpaceName1, fakeSpaceGuid1, _sut.Org), null, null, Services),
                // to stay:
                new SpaceViewModel(new CloudFoundrySpace(fakeSpaceName2, fakeSpaceGuid2, _sut.Org), null, null, Services, expanded: true),  // should stay expanded after refresh
                new SpaceViewModel(new CloudFoundrySpace(fakeSpaceName3, fakeSpaceGuid3, _sut.Org), null, null, Services, expanded: false), // should stay collapsed after refresh
            };

            var fakeSpacesList = new List <CloudFoundrySpace>
            {
                // original:
                new CloudFoundrySpace(fakeSpaceName2, fakeSpaceGuid2, _sut.Org),
                new CloudFoundrySpace(fakeSpaceName3, fakeSpaceGuid3, _sut.Org),
                // new:
                new CloudFoundrySpace(fakeSpaceName4, fakeSpaceGuid4, _sut.Org),
            };

            var fakeSuccessResult = new DetailedResult <List <CloudFoundrySpace> >(succeeded: true, content: fakeSpacesList);

            Assert.AreEqual(3, _sut.Children.Count);
            SpaceViewModel initialChildSpace1 = (SpaceViewModel)_sut.Children[0];
            SpaceViewModel initialChildSpace2 = (SpaceViewModel)_sut.Children[1];
            SpaceViewModel initialChildSpace3 = (SpaceViewModel)_sut.Children[2];

            Assert.AreEqual(fakeSpaceName1, initialChildSpace1.Space.SpaceName);
            Assert.AreEqual(fakeSpaceName2, initialChildSpace2.Space.SpaceName);
            Assert.AreEqual(fakeSpaceName3, initialChildSpace3.Space.SpaceName);
            Assert.IsFalse(initialChildSpace1.IsExpanded);
            Assert.IsTrue(initialChildSpace2.IsExpanded);
            Assert.IsFalse(initialChildSpace3.IsExpanded);

            MockCloudFoundryService.Setup(mock => mock.
                                          GetSpacesForOrgAsync(_sut.Org, true, It.IsAny <int>()))
            .ReturnsAsync(fakeSuccessResult);

            _receivedEvents.Clear();

            await _sut.RefreshChildren();

            Assert.AreEqual(3, _sut.Children.Count);
            SpaceViewModel refreshedChildSpace1 = (SpaceViewModel)_sut.Children[0];
            SpaceViewModel refreshedChildSpace2 = (SpaceViewModel)_sut.Children[1];
            SpaceViewModel refreshedChildSpace3 = (SpaceViewModel)_sut.Children[2];

            Assert.AreEqual(fakeSpaceName2, refreshedChildSpace1.Space.SpaceName);
            Assert.AreEqual(fakeSpaceName3, refreshedChildSpace2.Space.SpaceName);
            Assert.AreEqual(fakeSpaceName4, refreshedChildSpace3.Space.SpaceName);
            Assert.IsTrue(refreshedChildSpace1.IsExpanded);  // children that aren't new shouldn't change expansion
            Assert.IsFalse(refreshedChildSpace2.IsExpanded); // children that aren't new shouldn't change expansion
            Assert.IsFalse(refreshedChildSpace2.IsExpanded); // new children should start collapsed

            // property changed events should only be raised for "IsRefreshing" (1 to set as true, 1 to set as false)
            Assert.AreEqual(2, _receivedEvents.Count);
            Assert.AreEqual("IsRefreshing", _receivedEvents[0]);
            Assert.AreEqual("IsRefreshing", _receivedEvents[1]);

            MockCloudFoundryService.VerifyAll();
        }