public void GetLatestData() { // create fakes var logger = A.Fake<ILog>(); var marketDataProvider = A.Fake<IMarketDataProvider>(); var stockListProvider = A.Fake<IStockListProvider>(); var marketDataRepositoryFactory = A.Fake<IMarketDataRepositoryFactory>(); var marketDataRepository = A.Fake<IMarketDataRepository>(); A.CallTo(() => marketDataRepositoryFactory.CreateRepository()).Returns(marketDataRepository); var stockQuoteSet = A.Fake<IDbSet<StockQuote>>(); marketDataRepository.StockQuotes = stockQuoteSet; // create subscriptionData var stocks = new List<Stock>(); var updateIntervalTime = TimeSpan.FromMilliseconds(int.MaxValue); var subscription = new Subscription { UpdateInterval = new DateTime(1900, 1, 1, updateIntervalTime.Hours, updateIntervalTime.Minutes, updateIntervalTime.Seconds), TimeOfDayStart = new DateTime(1900, 1, 1, 0, 0, 0), TimeOfDayEnd = new DateTime(1900, 1, 1, 23, 59, 59, 999) }; // create fake return value var stockQuotes = new List<StockQuote> { new StockQuote { AskPrice = 1.0m, BidPrice = 1.2m, Change = 0.01m, OpenPrice = 0.9m, QuoteDateTime = DateTime.Now, Symbol = "TST1" }, new StockQuote { AskPrice = 2.0m, BidPrice = 2.2m, Change = 0.02m, OpenPrice = 1.0m, QuoteDateTime = DateTime.Now, Symbol = "TST2" }, new StockQuote { AskPrice = 3.0m, BidPrice = 3.2m, Change = 0.03m, OpenPrice = 1.1m, QuoteDateTime = DateTime.Now, Symbol = "TST3" } }; // hold onto list of quotes added to repository var repositoryQuotes = new List<StockQuote>(); // handle calls to fakes A.CallTo(() => stockListProvider.GetStocks(subscription)).Returns(stocks); A.CallTo(() => marketDataProvider.GetQuotes(stocks)).Returns(stockQuotes); A.CallTo(() => stockQuoteSet.Add(A<StockQuote>.Ignored)) .Invokes((StockQuote quote) => repositoryQuotes.Add(quote)); // create subscriptionData var marketDataSubscription = new MarketDataSubscription(logger, marketDataRepositoryFactory, marketDataProvider, stockListProvider, null, subscription); // call get latest data marketDataSubscription.InvokeMethod("GetLatestQuotes"); // ensure call to get data was made A.CallTo(() => marketDataProvider.GetQuotes(stocks)).MustHaveHappened(); // ensure call to store data was made A.CallTo(() => stockQuoteSet.Add(A<StockQuote>.Ignored)).MustHaveHappened(Repeated.Exactly.Times(3)); // check that quotes were added to the repository repositoryQuotes.Should().HaveCount(3); repositoryQuotes.Should().OnlyContain(q => stockQuotes.Contains(q)); }
public void ShortIntegrationTestToValidateEntryShouldBeRead() { var odataEntry = new ODataEntry() { Id = new Uri("http://services.odata.org/OData/OData.svc/Customers(0)") }; odataEntry.Properties = new ODataProperty[] { new ODataProperty() { Name = "ID", Value = 0 }, new ODataProperty() { Name = "Description", Value = "Simple Stuff" } }; var clientEdmModel = new ClientEdmModel(ODataProtocolVersion.V4); var context = new DataServiceContext(); MaterializerEntry.CreateEntry(odataEntry, ODataFormat.Atom, true, clientEdmModel); var materializerContext = new TestMaterializerContext() {Model = clientEdmModel, Context = context}; var adapter = new EntityTrackingAdapter(new TestEntityTracker(), MergeOption.OverwriteChanges, clientEdmModel, context); QueryComponents components = new QueryComponents(new Uri("http://foo.com/Service"), new Version(4, 0), typeof(Customer), null, new Dictionary<Expression, Expression>()); var entriesMaterializer = new ODataEntriesEntityMaterializer(new ODataEntry[] { odataEntry }, materializerContext, adapter, components, typeof(Customer), null, ODataFormat.Atom); var customersRead = new List<Customer>(); // This line will call ODataEntityMaterializer.ReadImplementation() which will reconstruct the entity, and will get non-public setter called. while (entriesMaterializer.Read()) { customersRead.Add(entriesMaterializer.CurrentValue as Customer); } customersRead.Should().HaveCount(1); customersRead[0].ID.Should().Be(0); customersRead[0].Description.Should().Be("Simple Stuff"); }
public void EndToEndShortIntegrationWriteEntryEventTest() { List<KeyValuePair<string, object>> eventArgsCalled = new List<KeyValuePair<string, object>>(); var dataServiceContext = new DataServiceContext(new Uri("http://www.odata.org/Service.svc")); dataServiceContext.Configurations.RequestPipeline.OnEntityReferenceLink((args) => eventArgsCalled.Add(new KeyValuePair<string, object>("OnEntityReferenceLink", args))); dataServiceContext.Configurations.RequestPipeline.OnEntryEnding((args) => eventArgsCalled.Add(new KeyValuePair<string, object>("OnEntryEnded", args))); dataServiceContext.Configurations.RequestPipeline.OnEntryStarting((args) => eventArgsCalled.Add(new KeyValuePair<string, object>("OnEntryStarted", args))); dataServiceContext.Configurations.RequestPipeline.OnNavigationLinkEnding((args) => eventArgsCalled.Add(new KeyValuePair<string, object>("OnNavigationLinkEnded", args))); dataServiceContext.Configurations.RequestPipeline.OnNavigationLinkStarting((args) => eventArgsCalled.Add(new KeyValuePair<string, object>("OnNavigationLinkStarted", args))); Person person = SetupSerializerAndCallWriteEntry(dataServiceContext); eventArgsCalled.Should().HaveCount(8); eventArgsCalled[0].Key.Should().Be("OnEntryStarted"); eventArgsCalled[0].Value.Should().BeOfType<WritingEntryArgs>(); eventArgsCalled[0].Value.As<WritingEntryArgs>().Entity.Should().BeSameAs(person); eventArgsCalled[1].Key.Should().Be("OnNavigationLinkStarted"); eventArgsCalled[1].Value.Should().BeOfType<WritingNavigationLinkArgs>(); eventArgsCalled[2].Key.Should().Be("OnEntityReferenceLink"); eventArgsCalled[2].Value.Should().BeOfType<WritingEntityReferenceLinkArgs>(); eventArgsCalled[3].Key.Should().Be("OnNavigationLinkEnded"); eventArgsCalled[3].Value.Should().BeOfType<WritingNavigationLinkArgs>(); eventArgsCalled[4].Key.Should().Be("OnNavigationLinkStarted"); eventArgsCalled[4].Value.Should().BeOfType<WritingNavigationLinkArgs>(); eventArgsCalled[5].Key.Should().Be("OnEntityReferenceLink"); eventArgsCalled[5].Value.Should().BeOfType<WritingEntityReferenceLinkArgs>(); eventArgsCalled[6].Key.Should().Be("OnNavigationLinkEnded"); eventArgsCalled[6].Value.Should().BeOfType<WritingNavigationLinkArgs>(); eventArgsCalled[7].Key.Should().Be("OnEntryEnded"); eventArgsCalled[7].Value.Should().BeOfType<WritingEntryArgs>(); eventArgsCalled[7].Value.As<WritingEntryArgs>().Entity.Should().BeSameAs(person); }
public void ShouldContainAll() { var listA = new List<int> { 1, 2, 3, 4 }; var listB = new List<int> { 1, 2, 3, 4 }; listA.Should().Contain().All(listB); }
public void NewValidationRulesShouldBeInTheRuleSetExceptBaselinedExceptionRules() { var validationRules = new Dictionary<object, string>(); var items = typeof(ValidationRules).GetFields().Select(f=> new KeyValuePair<object, string>(f.GetValue(null), f.Name)); foreach (var item in items) { validationRules.Add(item.Key, item.Value); } var unFoundValidationRules = new List<object>(); foreach(var ruleSet in ValidationRuleSet.GetEdmModelRuleSet(new Version(4, 0))) { if (validationRules.ContainsKey(ruleSet)) { validationRules.Remove(ruleSet); } else { unFoundValidationRules.Add(validationRules); } } unFoundValidationRules.Should().HaveCount(0); // The 4 remaining rules are deprecated: // ComplexTypeMustContainProperties // OnlyEntityTypesCanBeOpen // ComplexTypeInvalidPolymorphicComplexType // ComplexTypeInvalidAbstractComplexType validationRules.ToList().Should().HaveCount(4); }
public void CheckOnChangedAction() { var changed = new List<string>(); var changing = new List<string>(); var notifyViewModel = new NotifyViewModel(changed, changing); const string PropertyName = "Property"; var dependent = new Dictionary<string, string[]>(); Action<string, string[]> addToDependent = dependent.Add; var property = new ViewModelProperty<int>(notifyViewModel, addToDependent, PropertyName); var viewModelProperty = (IViewModelProperty<int>)property; var values = new List<int>(); viewModelProperty.OnChanged(values.Add); const int Value = 10; property.SetValue(Value, false).Should().Be.True(); property.Changed(() => Value); changing.Should().Have.SameSequenceAs(PropertyName); changed.Should().Have.SameSequenceAs(PropertyName); values.Should().Have.SameSequenceAs(Value); }
public void Customer_CRUD_operations_basics() { var customer = new Customer() { Name = "Foo Bar", Address = "Los Angeles, CA" }; var customers = new List<Customer>(); var mockSet = EntityFrameworkMoqHelper.CreateMockForDbSet<Customer>() .SetupForQueryOn(customers) .WithAdd(customers, "CustomerID")//overwritten to simulate behavior of auto-increment database .WithFind(customers, "CustomerID") .WithRemove(customers); var mockContext = EntityFrameworkMoqHelper.CreateMockForDbContext<DemoContext, Customer>(mockSet); var customerService = new CustomerService(mockContext.Object); customerService.Insert(customer); customers.Should().Contain(x => x.CustomerID == customer.CustomerID); //Testing GetByID (and DbSet.Find) method customerService.GetByID(customer.CustomerID).Should().NotBeNull(); //Testing Remove method customerService.Remove(customer); customerService.GetByID(customer.CustomerID).Should().BeNull(); }
public void DefaultDatabaseTest() { IDatabase actual; actual = Mongo.DefaultDatabase; actual.Should().NotBeNull(); List<Uri> names = new List<Uri>(actual.GetCollectionNames()); names.Should().Contain(Constants.CollectionNames.Cmd); //Todo:get the actual name for the command collection }
public void Random_42_liefert_immer_folgende_Werte() { var random = new Random(42); var result = new List<int>(); for (var i = 0; i < 10; i++) { result.Add(random.Next(1, 6 + 1)); } result.Should().Equal(5, 1, 1, 4, 2, 2, 5, 4, 2, 5); }
public void AtEndOfFirstToken() { var completionCalls = new List<Tuple<string[], int>>(); var set = TokenCompletionSet.Create("a b", 1, GetHandler(completionCalls)); completionCalls.Should().HaveCount(1); completionCalls[0].Item1.Should().ContainInOrder("a", "b"); completionCalls[0].Item2.Should().Be(0); }
public void listExtensions_sync_using_empty_lists_should_not_fail() { var source = new List<Object>(); var to = new List<Object>(); source.Sync( to ); to.Should().Have.SameSequenceAs( source ); }
public void SpaceOnlyString() { var completionCalls = new List<Tuple<string[], int>>(); var set = TokenCompletionSet.Create(" ", 0, GetHandler(completionCalls)); completionCalls.Should().HaveCount(1); completionCalls[0].Item1.Should().BeEmpty(); completionCalls[0].Item2.Should().Be(0); }
public void TestActivityThenForceLogThenIdleThenActivityThenIdleLoggingInEmptyLog() { // | Activity, Force Log, Idle, Activity, Idle var settings = GetActivityTrackingSettingsFake(); var activitiesRepository = GetActivitiesRepositoryFake(); var userInputTracker = GetUserInputTrackerFake(); var records = new List<ActivityRecord>(); var activityRecordsRepository = GetActivityRecordsRepositoryFake(records); var tracker = new UserActivityTracker( activityRecordsRepository, activitiesRepository, settings, userInputTracker); tracker.Start(); DateTime timeStamp = DateTime.Now; userInputTracker.RaiseUserInputDetectedEvent(timeStamp); userInputTracker.RaiseUserInputDetectedEvent(ref timeStamp, settings.MinimumActivityDuration); tracker.LogUserActivity(false, true, timeStamp); userInputTracker.RaiseUserInputDetectedEvent(ref timeStamp, settings.MinimumIdleDuration); userInputTracker.RaiseUserInputDetectedEvent(ref timeStamp, settings.MinimumActivityDuration); userInputTracker.RaiseUserInputDetectedEvent(ref timeStamp, settings.MinimumIdleDuration); records.Should().HaveCount(4); ActivityRecord activityRecord = records[0]; activityRecord.Idle.Should().Be(false); activityRecord.Duration.Should().Be(settings.MinimumActivityDuration); activityRecord.Activity.Should().Be(WorkActivity); ActivityRecord idleRecord = records[1]; idleRecord.Idle.Should().Be(true); idleRecord.Duration.Should().Be(settings.MinimumIdleDuration); idleRecord.Activity.Should().Be(BreakActivity); idleRecord.StartTime.Should().Be(activityRecord.EndTime); activityRecord = records[2]; activityRecord.Idle.Should().Be(false); activityRecord.Duration.Should().Be(settings.MinimumActivityDuration); activityRecord.Activity.Should().Be(WorkActivity); activityRecord.StartTime.Should().Be(idleRecord.EndTime); idleRecord = records[3]; idleRecord.Idle.Should().Be(true); idleRecord.Duration.Should().Be(settings.MinimumIdleDuration); idleRecord.Activity.Should().Be(BreakActivity); idleRecord.StartTime.Should().Be(activityRecord.EndTime); tracker.Stop(); }
public void listExtensions_sync_using_empty_source_but_non_empty_to_should_sync_as_expected() { var source = new List<Object>(); var to = new List<Object>() { new Object(), new Object() }; source.Sync( to ); to.Should().Have.SameSequenceAs( source ); }
public void ShouldObservePathTypes() { var a = PathUtility.CreateTemporaryPath(PathType.File); var pathTypes = new List<PathType>(); a.ObservePathType().Subscribe(pathTypes.Add); a.Delete(); Thread.Sleep(200); a.Create(PathType.Folder); Thread.Sleep(200); a.RenameTo(PathUtility.CreateTemporaryPath(PathType.None)); Thread.Sleep(200); pathTypes.Should().BeEquivalentTo(PathType.File, PathType.None, PathType.Folder, PathType.None); }
public void ForEach_ListWithAction_ActionPerformedOnEachItemOfList() { // Arrange var toAdd = new Random().Next().ToString(); var list = new List<string> { "some", "random", "string", "items", "for", "test" }; var enumerable = list.AsEnumerable(); // Act var final = new List<string>(); enumerable.ForEach(x => final.Add(x + toAdd)); // Assert list.ForEach(x => final.Should().Contain(x + toAdd)); }
public void TraverseReferences() { var parent = Category.CreateHierarchy(); var actionReferences = new List<string>(); var references = ObjectTree.Traverse( parent, x => { Normalizer.TrimProperties(x); actionReferences.Add(((Category)x).Name); }); var names = new[] { "Root", "Root 1", "Root 1.1", "Root 2" }; actionReferences.Should().Have.SameSequenceAs(names); references.Cast<Category>().Select(x => x.Name).Should().Have.SameSequenceAs(names); }
public void ShouldTrackRenamings() { var a = PathUtility.CreateTemporaryPath(PathType.File); var renamings = a.Renamings(); var subsequentPaths = new List<PathSpec>(); using (renamings.Subscribe(renaming => subsequentPaths.Add(renaming))) { var b = PathUtility.CreateTemporaryPath(PathType.None); var c = PathUtility.CreateTemporaryPath(PathType.None); var d = PathUtility.CreateTemporaryPath(PathType.None); a.RenameTo(b); Thread.Sleep(200); b.RenameTo(c); Thread.Sleep(200); c.RenameTo(d); Thread.Sleep(200); subsequentPaths.Should().BeEquivalentTo(b, c, d); } }
public void it_should_iterate_through_keys_and_values_correctly() { var expected = new List<KeyValuePair<string, string>>() { new KeyValuePair<string, string>("key1", "value1"), new KeyValuePair<string, string>("key1", "value2"), new KeyValuePair<string, string>("key2", "value1"), new KeyValuePair<string, string>("key2", "value2") }; foreach (var entry in expected) { _parameters.AddValue(entry.Key, entry.Value); } int iteratedEntries = 0; foreach (var entry in _parameters) { expected.Should().Contain(entry); iteratedEntries++; } iteratedEntries.Should().Be(expected.Count); }
public void AtEndOfClosedQuotedToken() { var text = "here " + '"' + @"c:\program files" + '"'; var completionCalls = new List<Tuple<string[], int>>(); var set = TokenCompletionSet.Create(text, text.Length, GetHandler(completionCalls)); completionCalls.Should().HaveCount(1); completionCalls[0].Item1.Should().ContainInOrder("here", @"c:\program files"); completionCalls[0].Item2.Should().Be(1); }
public void When_a_collection_contains_only_items_matching_a_predicate_it_should_not_throw() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var collection = new List<int> { 2, 9, 3, 8, 2}; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => collection.Should().OnlyContain(i => i <= 10); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- act.ShouldNotThrow(); ; }
public void When_any_item_does_not_match_according_to_a_predicate_it_should_throw() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var actual = new List<string> { "ONE", "TWO", "THREE", "FOUR" }; var expected = new List<string> { "One", "Two", "Three", "Five" }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action action = () => actual.Should().Equal(expected, (a, e) => string.Equals(a, e, StringComparison.CurrentCultureIgnoreCase)); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- action .ShouldThrow<AssertFailedException>() .WithMessage("Expected*equal to*, but*differs at index 3."); }
public void listExtensions_sync_using_source_and_to_with_a_shared_item_in_different_position_should_sync_as_expected() { var same = new Object(); var source = new List<Object>() { same, new Object() }; var to = new List<Object>() { new Object(), same, new Object() }; source.Sync( to ); to.Should().Have.SameSequenceAs( source ); }
public void When_all_items_match_according_to_a_predicate_it_should_succeed() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var actual = new List<string> { "ONE", "TWO", "THREE", "FOUR" }; var expected = new List<string> { "One", "Two", "Three", "Four" }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action action = () => actual.Should().Equal(expected, (a, e) => string.Equals(a, e, StringComparison.CurrentCultureIgnoreCase)); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- action.ShouldNotThrow(); }
public void When_two_collections_containing_nulls_are_equal_it_should_not_throw() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var subject = new List<string> { "aaa", null }; var expected = new List<string> { "aaa", null }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action action = () => subject.Should().Equal(expected); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- action.ShouldNotThrow(); }
public void InInterstitialSpace() { var completionCalls = new List<Tuple<string[], int>>(); var set = TokenCompletionSet.Create("a b c", 6, GetHandler(completionCalls)); completionCalls.Should().HaveCount(1); completionCalls[0].Item1.Should().ContainInOrder("a", "b", string.Empty, "c"); completionCalls[0].Item2.Should().Be(2); }
public void When_a_collection_contains_items_not_matching_a_predicate_it_should_throw() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var collection = new List<int> { 2, 12, 3, 11, 2 }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => collection.Should().OnlyContain(i => i <= 10, "10 is the maximum"); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- act.ShouldThrow<AssertFailedException>().WithMessage( "Expected collection to contain only items matching (i <= 10) because 10 is the maximum, but {12, 11} do(es) not match."); }
public void JustBeforeEndOfClosedQuotedToken() { var completionCalls = new List<Tuple<string[], int>>(); var set = TokenCompletionSet.Create("a \"b \"", 4, GetHandler(completionCalls)); completionCalls.Should().HaveCount(1); completionCalls[0].Item1.Should().ContainInOrder("a", "b "); completionCalls[0].Item2.Should().Be(1); }
public void When_a_collection_does_not_contain_the_combination_of_a_collection_and_a_single_item_it_should_throw() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- var strings = new List<string> { "string1", "string2" }; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action act = () => strings.Should().Contain(strings, "string3"); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- act.ShouldThrow<AssertFailedException>().WithMessage( "Expected collection {\"string1\", \"string2\"} to contain {\"string1\", \"string2\", \"string3\"}, but could not find {\"string3\"}."); }
public void and_permission_info_extractor_returns_correct_info_for_subjects() { store.AddRight(n1, s2, MANAGE, true); var expected = new List<IPermissionInfo> { new Context.Permissions.PermissionInfo { DisplayName = n1.ToString(), Spec = READ, Inherit = false, InheritedFrom = null, }, new Context.Permissions.PermissionInfo { DisplayName = n1_2.ToString(), Spec = WRITE, Inherit = false, InheritedFrom = null, }, }; var guids = new Guid[] { n1, n1_1, n1_2, n1_1_1, special, n1_2_1, n1_2_2, n1_2_3 }; foreach (var g in guids) { expected.Add(new Context.Permissions.PermissionInfo { DisplayName = g.ToString(), Spec = MANAGE, Inherit = true, InheritedFrom = g != n1 ? n1.ToString() : null, }); } var nameResolver = new DefaultNameResolver(""); var infoExtractor = new PermissionInfoExtractor(store, nameResolver); var actual = infoExtractor.GetPermissionInfoForSubject(s2).ToList(); actual.Should().NotBeNull(); actual.Count().Should().Be(expected.Count); foreach (var ex in expected) { actual.Should().Contain(ex); } foreach (var ac in actual) { expected.Should().Contain(ac); } }