/// <summary> /// Handles adding any missing PCGuildPoint records for a player to the database. /// </summary> private static void OnModuleEnter() { NWPlayer player = GetEnteringObject(); if (!player.IsPlayer) { return; } // If player is missing any entries for guild points, add them now. foreach (var guild in DataService.GetAll <Guild>()) { var pcGP = DataService.SingleOrDefault <PCGuildPoint>(x => x.GuildID == guild.ID && x.PlayerID == player.GlobalID); // No GP entry found. Add one now. if (pcGP == null) { pcGP = new PCGuildPoint { GuildID = guild.ID, PlayerID = player.GlobalID, Points = 0, Rank = 0 }; DataService.SubmitDataChange(pcGP, DatabaseActionType.Insert); } } }
public void GetByID_OneItem_ReturnsPCGuildPoint() { // Arrange var id = Guid.NewGuid(); PCGuildPoint entity = new PCGuildPoint { ID = id }; // Act MessageHub.Instance.Publish(new OnCacheObjectSet <PCGuildPoint>(entity)); // Assert Assert.AreNotSame(entity, _cache.GetByID(id)); }
public void GetByID_TwoItems_ReturnsCorrectObject() { // Arrange var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); PCGuildPoint entity1 = new PCGuildPoint { ID = id1 }; PCGuildPoint entity2 = new PCGuildPoint { ID = id2 }; // Act MessageHub.Instance.Publish(new OnCacheObjectSet <PCGuildPoint>(entity1)); MessageHub.Instance.Publish(new OnCacheObjectSet <PCGuildPoint>(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(); PCGuildPoint entity1 = new PCGuildPoint { ID = id1 }; PCGuildPoint entity2 = new PCGuildPoint { ID = id2 }; // Act MessageHub.Instance.Publish(new OnCacheObjectSet <PCGuildPoint>(entity1)); MessageHub.Instance.Publish(new OnCacheObjectSet <PCGuildPoint>(entity2)); MessageHub.Instance.Publish(new OnCacheObjectDeleted <PCGuildPoint>(entity1)); // Assert Assert.Throws <KeyNotFoundException>(() => { _cache.GetByID(id1); }); Assert.AreNotSame(entity2, _cache.GetByID(id2)); }