public async Task TestMethod_StoreUrl_AddRemoveEventHandler() { var store = _fixture.GetService <IUrlShortenerService>(); store.Should().NotBeNull(); var url = "https://github.com/P7CoreOrg/dotnetcore.urlshortener/tree/dev"; ShortenerEventArgs evt = null; var myHandler = new MyHandler(); store.AddListenter(myHandler.OnEvent); var(code, shortUrl) = await store.UpsertShortUrlAsync("1", new ShortUrl() { LongUrl = url, Expiration = DateTime.UtcNow.AddSeconds(2) }); code.Should().Be(HttpStatusCode.OK); myHandler.Evt.Should().NotBeNull(); myHandler.Evt.EventType.Should().Be(ShortenerEventType.Upsert); myHandler.Evt.ShortUrl.Should().NotBeNull(); myHandler.Evt.ShortUrl.LongUrl.Should().Match(url); myHandler.Evt.ShortUrl.Id.Should().NotBeNullOrEmpty(); shortUrl.LongUrl.Should().Match(url); shortUrl.Id.Should().NotBeNullOrEmpty(); myHandler.Evt = null; store.RemoveListenter(myHandler.OnEvent); var lookup = await store.GetShortUrlAsync(shortUrl.Id); myHandler.Evt.Should().BeNull(); }
public void OnEvent(object sender, ShortenerEventArgs e) { Evt = e; }