public void TestClientsForProject() { // This test will ensure that when subscription is added, only events for that subscription get sent to it var state = new InMemoryAssetStatusState() as IAssetStatusState; Assert.NotNull(state); const string clientId1 = "AF284FC0-4D38-4337-A782-564ABD65D5CC"; const string clientId2 = "C670850B-BF18-4AA3-963F-9820C47481C8"; var projectUid1 = Guid.Parse("59436FBE-909F-4ED9-A038-9403CAA5782D"); var projectUid2 = Guid.Parse("860706B6-E1B9-4E33-B74A-B2691430A0D7"); var customerUid1 = Guid.Parse("67543B02-FF2A-4AE4-96DF-826BD29E3942"); var customerUid2 = Guid.Parse("E59522CD-C0E3-4475-AD16-9C0C3035932B"); // First test the same customer uid, different project uid state.AddSubscription(clientId1, new AssetUpdateSubscriptionModel() { CustomerUid = customerUid1, ProjectUid = projectUid1 }); state.AddSubscription(clientId2, new AssetUpdateSubscriptionModel() { CustomerUid = customerUid1, ProjectUid = projectUid2 }); // Now we should only get one clientid back { var clients = state.GetClientsForProject(customerUid1, projectUid1).Result; Assert.True(clients.Count == 1, $"Expected a single client but got ${clients.Count}"); Assert.Equal(clientId1, clients[0]); } // Now same project UID but different customer UID (also this should replace the existing subscription) state.AddSubscription(clientId1, new AssetUpdateSubscriptionModel() { CustomerUid = customerUid1, ProjectUid = projectUid2 }); state.AddSubscription(clientId2, new AssetUpdateSubscriptionModel() { CustomerUid = customerUid2, ProjectUid = projectUid2 }); // We should have 2 subscriptions, but only one for the project / customer { var subs = state.GetSubscriptions().Result; var clients = state.GetClientsForProject(customerUid2, projectUid2).Result; Assert.True(subs.Count == 2, $"Subs don't match, expected two got ${subs.Count}"); Assert.True(clients.Count == 1, $"Expected a single client but got ${clients.Count}"); Assert.Equal(clientId2, clients[0]); } // Now update the subscriptions to be the same state.AddSubscription(clientId1, new AssetUpdateSubscriptionModel() { CustomerUid = customerUid1, ProjectUid = projectUid1 }); state.AddSubscription(clientId2, new AssetUpdateSubscriptionModel() { CustomerUid = customerUid1, ProjectUid = projectUid1 }); // We should have 2 subscriptions, both for the same proejct / customer { var subs = state.GetSubscriptions().Result; var clients = state.GetClientsForProject(customerUid1, projectUid1).Result; Assert.True(subs.Count == 2, $"Subs don't match, expected two got ${subs.Count}"); Assert.True(clients.Count == 2, $"Expected two clients but got ${clients.Count}"); Assert.Contains(clientId1, clients); Assert.Contains(clientId2, clients); } // Now test a combo that returns no results { var clients = state.GetClientsForProject(customerUid2, projectUid2).Result; Assert.True(clients.Count == 0, $"Expected no clients but got ${clients.Count}"); } }