本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.Should方法的典型用法代码示例。如果您正苦于以下问题:C# List.Should方法的具体用法?C# List.Should怎么用?C# List.Should使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.Should方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetLatestData
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));
}
示例2: ShortIntegrationTestToValidateEntryShouldBeRead
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");
}
示例3: EndToEndShortIntegrationWriteEntryEventTest
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);
}
示例4: ShouldContainAll
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);
}
示例5: NewValidationRulesShouldBeInTheRuleSetExceptBaselinedExceptionRules
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);
}
示例6: CheckOnChangedAction
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);
}
示例7: Customer_CRUD_operations_basics
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();
}
示例8: DefaultDatabaseTest
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
}
示例9: Random_42_liefert_immer_folgende_Werte
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);
}
示例10: AtEndOfFirstToken
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);
}
示例11: listExtensions_sync_using_empty_lists_should_not_fail
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 );
}
示例12: SpaceOnlyString
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);
}
示例13: TestActivityThenForceLogThenIdleThenActivityThenIdleLoggingInEmptyLog
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();
}
示例14: listExtensions_sync_using_empty_source_but_non_empty_to_should_sync_as_expected
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 );
}
示例15: ShouldObservePathTypes
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);
}