public void GetByID_OneItem_ReturnsPCObjectVisibility() { // Arrange var id = Guid.NewGuid(); PCObjectVisibility entity = new PCObjectVisibility { ID = id }; // Act MessageHub.Instance.Publish(new OnCacheObjectSet <PCObjectVisibility>(entity)); // Assert Assert.AreNotSame(entity, _cache.GetByID(id)); }
public void AdjustVisibility(NWPlayer player, NWObject target, bool isVisible) { if (!player.IsPlayer) { return; } if (target.IsPlayer || target.IsDM) { return; } string visibilityObjectID = target.GetLocalString("VISIBILITY_OBJECT_ID"); if (string.IsNullOrWhiteSpace(visibilityObjectID)) { target.AssignCommand(() => { _.SpeakString("Unable to locate VISIBILITY_OBJECT_ID variable. Need this in order to adjust visibility. Notify an admin if you see this message."); }); return; } var visibility = _data.SingleOrDefault <PCObjectVisibility>(x => x.PlayerID == player.GlobalID && x.VisibilityObjectID == visibilityObjectID); DatabaseActionType action = DatabaseActionType.Update; if (visibility == null) { visibility = new PCObjectVisibility { PlayerID = player.GlobalID, VisibilityObjectID = visibilityObjectID }; action = DatabaseActionType.Insert; } visibility.IsVisible = isVisible; _data.SubmitDataChange(visibility, action); if (visibility.IsVisible) { _nwnxPlayer.SetVisibilityOverride(player, target, (int)PlayerVisibilityType.Visible); } else { _nwnxPlayer.SetVisibilityOverride(player, target, (int)PlayerVisibilityType.Hidden); } }
public void GetByID_TwoItems_ReturnsCorrectObject() { // Arrange var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); PCObjectVisibility entity1 = new PCObjectVisibility { ID = id1 }; PCObjectVisibility entity2 = new PCObjectVisibility { ID = id2 }; // Act MessageHub.Instance.Publish(new OnCacheObjectSet <PCObjectVisibility>(entity1)); MessageHub.Instance.Publish(new OnCacheObjectSet <PCObjectVisibility>(entity2)); // Assert Assert.AreNotSame(entity1, _cache.GetByID(id1)); Assert.AreNotSame(entity2, _cache.GetByID(id2)); }
public void GetByID_RemovedItem_ReturnsCorrectObject() { // Arrange var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); PCObjectVisibility entity1 = new PCObjectVisibility { ID = id1 }; PCObjectVisibility entity2 = new PCObjectVisibility { ID = id2 }; // Act MessageHub.Instance.Publish(new OnCacheObjectSet <PCObjectVisibility>(entity1)); MessageHub.Instance.Publish(new OnCacheObjectSet <PCObjectVisibility>(entity2)); MessageHub.Instance.Publish(new OnCacheObjectDeleted <PCObjectVisibility>(entity1)); // Assert Assert.Throws <KeyNotFoundException>(() => { _cache.GetByID(id1); }); Assert.AreNotSame(entity2, _cache.GetByID(id2)); }