private static NativeLuaTable CreateMenuTable(IEntitySelection selection) { var menuTable = new NativeLuaTable(); Table.insert(menuTable, GenerateTitleMenuTableEntry()); foreach (var entityCategory in selection) { Table.insert(menuTable, GenerateEntryForEntityType(entityCategory.Key, entityCategory.Value)); } return(menuTable); }
public void ViewShowsEntitySelection() { IFrame shownAnchor = null; IEntitySelection shownSelection = null; this.entitySelectionDropdownHandlerMock.Setup(es => es.Show(It.IsAny <IFrame>(), It.IsAny <IEntitySelection>())) .Callback((IFrame anchor, IEntitySelection selection) => { shownAnchor = anchor; shownSelection = selection; }); var viewUnderTest = new View(this.entitySelectionDropdownHandlerMock.Object, this.wrapperMock.Object); var entitySelectionMock = new Mock <IEntitySelection>(); viewUnderTest.ShowEntitySelection(entitySelectionMock.Object); this.entitySelectionDropdownHandlerMock.Verify(es => es.Show(It.IsAny <IFrame>(), It.IsAny <IEntitySelection>()), Times.Once()); Assert.AreEqual(this.frameMock.Object.TrackButton, shownAnchor); Assert.AreEqual(entitySelectionMock.Object, shownSelection); }
public void PresenterProvidesHandlesTrackClickAndTrackableEntitySelection() { this.modelMock.Setup(model => model.LoadTrackedEntities()).Returns(new List <IEntity>()); var item1 = CreateMockEntity(EntityType.Item, 43, "Test item 1", "The item icon 1"); var item2 = CreateMockEntity(EntityType.Item, 45, "Test item 2", "The item icon 2"); var currency = CreateMockEntity(EntityType.Currency, 20, "Test currency", "The currency icon"); this.modelMock.Setup(model => model.GetAvailableEntities(EntityType.Item)).Returns(new List <IEntity>() { item1, item2 }); this.modelMock.Setup(model => model.GetAvailableEntities(EntityType.Currency)).Returns(new List <IEntity>() { currency }); this.modelMock.Setup(model => model.GetCurrentSample(EntityType.Item, 45)).Returns(CreateMockSample(200000, 10)); Action track = null; Action update = null; this.viewMock.Setup(view => view.SetTrackButtonOnClick(It.IsAny <Action>())) .Callback((Action trackClick) => track = trackClick); this.viewMock.Setup(view => view.SetUpdateAction(It.IsAny <Action>())) .Callback((Action updateAction) => update = updateAction); var presenter = new Presenter(this.modelMock.Object, this.viewMock.Object); Assert.IsTrue(track != null, "Track click function not set."); this.viewMock.Verify(view => view.ShowEntitySelection(It.IsAny <IEntitySelection>()), Times.Never); IEntitySelection entitySelection = null; this.viewMock.Setup(view => view.ShowEntitySelection(It.IsAny <IEntitySelection>())) .Callback((IEntitySelection selection) => entitySelection = selection); track(); this.viewMock.Verify(view => view.ShowEntitySelection(It.IsAny <IEntitySelection>()), Times.Once); Assert.IsTrue(entitySelection != null, "Entity selection not provided."); Assert.AreEqual(2, entitySelection.Count); var itemsString = "Items"; var currenciesString = "Currencies"; Assert.IsTrue(entitySelection.ContainsKey(itemsString)); Assert.IsTrue(entitySelection.ContainsKey(currenciesString)); Assert.AreEqual(2, entitySelection[itemsString].Count); Assert.AreEqual(1, entitySelection[itemsString].Count(item => item.Name.Equals(item1.Name) && item.IconPath.Equals(item1.IconPath))); Assert.AreEqual(1, entitySelection[itemsString].Count(item => item.Name.Equals(item2.Name) && item.IconPath.Equals(item2.IconPath))); Assert.AreEqual(1, entitySelection[currenciesString].Count); Assert.AreEqual(1, entitySelection[currenciesString].Count(c => c.Name.Equals(currency.Name) && c.IconPath.Equals(currency.IconPath))); this.viewMock.Verify(view => view.AddTrackingEntity(It.IsAny <IEntityId>(), It.IsAny <string>(), It.IsAny <string>()), Times.Never); this.modelMock.Verify(model => model.SaveEntityTrackingFlag(It.IsAny <EntityType>(), It.IsAny <int>(), It.IsAny <bool>()), Times.Never); entitySelection[itemsString][1].OnSelect(); this.viewMock.Verify(view => view.AddTrackingEntity(It.IsAny <IEntityId>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once); this.viewMock.Verify(view => view.AddTrackingEntity(It.Is <IEntityId>(entityId => entityId.Id.Equals(item2.Id) && entityId.Type.Equals(item2.Type)), item2.Name, item2.IconPath), Times.Once); this.modelMock.Verify(model => model.SaveEntityTrackingFlag(It.IsAny <EntityType>(), It.IsAny <int>(), It.IsAny <bool>()), Times.Once); this.modelMock.Verify(model => model.SaveEntityTrackingFlag(item2.Type, item2.Id, true), Times.Once); this.viewMock.Verify(view => view.UpdateTrackingEntityVelocity(It.IsAny <IEntityId>(), It.IsAny <int>(), It.IsAny <double>()), Times.Once); this.viewMock.Verify(view => view.UpdateTrackingEntityVelocity(It.Is <IEntityId>(entityId => entityId.Id.Equals(item2.Id) && entityId.Type.Equals(item2.Type)), 10, 0), Times.Once); Core.mockTime = Core.time() + 1; update(); this.viewMock.Verify(view => view.UpdateTrackingEntityVelocity(It.Is <IEntityId>(entityId => entityId.Id.Equals(item2.Id) && entityId.Type.Equals(item2.Type)), 10, 0), Times.Exactly(2)); }
public void ShowEntitySelection(IEntitySelection selection) { this.entitySelectionDropdownHandler.Show(this.frame.TrackButton, selection); }
public void Show(IFrame anchor, IEntitySelection selection) { var menuTable = CreateMenuTable(selection); Global.FrameProvider.EasyMenu(menuTable, this.menuFrame, anchor, 0, 0, "MENU"); }