public override void SetUp() { base.SetUp(); _feedPreNormalize = FeedTest.CreateTestFeed(); _feedPostNormalize = _feedPreNormalize.Clone(); _feedPostNormalize.Normalize(_feedPreNormalize.Uri); }
public FeedManagerTest() { _feedCacheMock = CreateMock <IFeedCache>(); _trustManagerMock = CreateMock <ITrustManager>(); _feedManager = new FeedManager(_config, _feedCacheMock.Object, _trustManagerMock.Object, new SilentTaskHandler()); _feedPreNormalize = FeedTest.CreateTestFeed(); _feedPostNormalize = _feedPreNormalize.Clone(); _feedPostNormalize.Normalize(_feedPreNormalize.Uri); }
public void Test_Feed_Clone() { var feed = new Feed { Name = "TestName", Type = "TestType", SettingsGroup = "TestSettingsGroup", Settings = { { "Key1", "Value1" }, { "Key2", "Value2" }, { "Key3", "Value3" } } }; var sut = feed.Clone(); Assert.Equal(feed.Name, sut.Name); Assert.Equal(feed.Type, sut.Type); Assert.Equal(feed.SettingsGroup, sut.SettingsGroup); Assert.Equal(feed.Settings, sut.Settings); }
public void FeedCloneTest() { Feed feed1 = new Feed(); feed1.Url = RssBotTestHelpers.TestUrl1; feed1.RefreshInterval = TimeSpan.MaxValue; feed1.AddChannel(TestHelpers.GetTestIrcConfig().Channels[0]); Feed clonedFeed = feed1.Clone(); Assert.AreNotSame(feed1, clonedFeed); Assert.AreEqual(feed1.Url, clonedFeed.Url); Assert.AreEqual(feed1.RefreshInterval, clonedFeed.RefreshInterval); Assert.AreNotSame(feed1.Channels, clonedFeed.Channels); Assert.AreEqual(feed1.Channels[0], clonedFeed.Channels[0]); feed1.AddChannel("#SomeChannel"); Assert.AreNotEqual(feed1.Channels.Count, clonedFeed.Channels.Count); }
public void TestFindByShortName() { var appA = new Feed { Uri = FeedTest.Test1Uri, Name = "AppA", EntryPoints = {new EntryPoint {Command = Command.NameRun, BinaryName = "BinaryA"}} }; var appB = new Feed { Uri = FeedTest.Test2Uri, Name = "AppB", EntryPoints = {new EntryPoint {Command = Command.NameRun, BinaryName = "BinaryB"}} }; var catalog = new Catalog {Feeds = {appA, appA.Clone(), appB, appB.Clone()}}; Assert.IsNull(catalog.FindByShortName("")); Assert.AreSame(expected: appA, actual: catalog.FindByShortName("AppA")); Assert.AreSame(expected: appA, actual: catalog.FindByShortName("BinaryA")); Assert.AreSame(expected: appB, actual: catalog.FindByShortName("AppB")); Assert.AreSame(expected: appB, actual: catalog.FindByShortName("BinaryB")); }
/// <summary> /// Method for notifying all subscribers that feed has arrived. /// </summary> /// <param name="symbolId">Id of the symbol for which feed has arrived</param> /// <param name="fd">Feed</param> private void Notify(int symbolId, Feed fd) { lock (_lockSubscription) { if (notifyList.ContainsKey(symbolId)) { foreach (OnFeedReceived hndl in notifyList[symbolId]) { try { //send a copy hndl((Feed)fd.Clone()); } catch { //ignore... } } } } }
/// <summary> /// Method for generating fake data /// </summary> private void UpdateData() { // Method to change the values of all the stocks randomly in a fixed range List <StockModel.Symbol> symbols = InMemoryObjects.ExchangeSymbolList.SingleOrDefault(x => x.Exchange == Exchange.FAKE_NASDAQ).Symbols; Feed[] feedsArray = new Feed[symbols.Count]; List <SymbolFeeds> symbolFeeds = new List <SymbolFeeds>(); while (true) { Thread.Sleep(updateDurationTime); Parallel.ForEach(symbols, (symbol) => { SymbolFeeds feeds = new SymbolFeeds(); feeds.SymbolId = symbol.Id; double changePercent = random.NextDouble() * (Constants.MAX_CHANGE_PERC - Constants.MIN_CHANGE_PERC) + Constants.MIN_CHANGE_PERC; symbol.DefaultVal = symbol.DefaultVal + symbol.DefaultVal * changePercent / 100; Feed feed = new Feed(); feed.SymbolId = symbol.Id; feed.LTP = symbol.DefaultVal; feed.TimeStamp = Convert.ToInt64((DateTime.Now - epoch).TotalMilliseconds); if (FeedArrived != null) { FeedArrived((Feed)feed.Clone()); } //notify subscribers - later to be changed to only notify if there is any new data Notify(symbol.Id, feed); }); } }
/// <summary> /// Method for getting latest data /// against the configured symbols for the selected exchange /// </summary> private void UpdateData() { // Method to generate feeds and update the in memory objects List <StockModel.Symbol> symbols = InMemoryObjects.ExchangeSymbolList.SingleOrDefault (x => x.Exchange == _exchange).Symbols; while (true) { Thread.Sleep(_refreshInterval); Parallel.ForEach(symbols, (symbol) => { Feed feed = GetFeed(symbol.SymbolCode, symbol.Id, _exchange.ToString()); if (FeedArrived != null) { FeedArrived((Feed)feed.Clone()); } //notify subscribers - later to be changed to only notify if there is any new data Notify(symbol.Id, feed); }); } }
public void TestFindByShortName() { var appA = new Feed { Uri = FeedTest.Test1Uri, Name = "AppA", EntryPoints = {new EntryPoint {Command = Command.NameRun, BinaryName = "BinaryA"}} }; var appB = new Feed { Uri = FeedTest.Test2Uri, Name = "AppB", EntryPoints = {new EntryPoint {Command = Command.NameRun, BinaryName = "BinaryB"}} }; var catalog = new Catalog {Feeds = {appA, appA.Clone(), appB, appB.Clone()}}; catalog.FindByShortName("").Should().BeNull(); catalog.FindByShortName("AppA").Should().BeSameAs(appA); catalog.FindByShortName("BinaryA").Should().BeSameAs(appA); catalog.FindByShortName("AppB").Should().BeSameAs(appB); catalog.FindByShortName("BinaryB").Should().BeSameAs(appB); }