本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.SingleOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# List.SingleOrDefault方法的具体用法?C# List.SingleOrDefault怎么用?C# List.SingleOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.SingleOrDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AreAurasEqual
private void AreAurasEqual(List<Aura> mp, List<Aura> ddi)
{
Assert.AreEqual(mp.Count, ddi.Count);
foreach (Aura aMP in mp)
{
Aura aDDI = ddi.SingleOrDefault(x => x.Name == aMP.Name.Trim());
Assert.IsNotNull(aDDI);
Assert.AreEqual(aMP.Keywords, aDDI.Keywords,String.Format("Different Keyword for aura {0}",aMP.Name));
Assert.AreEqual(aMP.ToString(), aDDI.ToString());
}
}
示例2: AreDamageEqual
private void AreDamageEqual(List<DamageModifier> mp, List<DamageModifier> ddi)
{
Assert.AreEqual(mp.Count, ddi.Count);
foreach (DamageModifier dMP in mp)
{
DamageModifier dDDI = ddi.SingleOrDefault(x => x.Type == dMP.Type);
Assert.IsNotNull(dDDI);
Assert.AreEqual(dMP.Value, dDDI.Value);
Assert.AreEqual(dMP.Type, dDDI.Type);
Assert.AreEqual(dMP.ToString(), dDDI.ToString());
}
}
示例3: DeleteProduct
public void DeleteProduct()
{
var data = new List<Product>
{
new Product {Name = "BBB", BarCode = "112115", InStock = 15, Id = 1},
new Product {Name = "ZZZ", BarCode = "112116", InStock = 23, Id = 2},
new Product {Name = "AAA", BarCode = "112116", InStock = 30, Id = 3}
};
var mockSet = new Mock<DbSet<Product>>()
.SetupData(data, objects => data.SingleOrDefault(d => d.Id == (int)objects.First()));
var mockContext = new Mock<DAL.IDbContext>();
mockContext.Setup(m => m.Set<Product>()).Returns(mockSet.Object);
var service = new ProductService(mockContext.Object);
service.Delete(1);
Assert.IsNull(data.Find(x => x.Id == 1));
}
示例4: GetOperationsForAccount
public List<Operation> GetOperationsForAccount(int accountID)
{
List<Operation> operations1 = new List<Operation>();
operations1.Add(new Operation { Amount = 100, Direction = Domain.Direction.Credit });
operations1.Add(new Operation { Amount = 200, Direction = Domain.Direction.Debit });
List<Account> accounts = new List<Account>();
accounts.Add(new Account { Balance = 300, Operations = operations1, AutorizeOverdraft = true, Id = 1 });
accounts.Add(new Account { Balance = 0, Operations = null, AutorizeOverdraft = false, Id = 2 });
SIAccountRepository accountRepository = new SIAccountRepository();
accountRepository.GetAccountInt32 = (x) =>
{
return accounts.SingleOrDefault(a => a.Id == x);
};
SIOperationRepository operationRepository = new SIOperationRepository();
AccountService service = new AccountService(accountRepository, operationRepository);
List<Operation> result = service.GetOperationsForAccount(accountID);
return result;
}
示例5: GetUserStock_with_id_must_return_stock_from_context
public async Task GetUserStock_with_id_must_return_stock_from_context()
{
var data = new List<UserStock>
{
new UserStock {ID = 0, Name = "DAX"},
new UserStock {ID = 1, Name = "NYSE"}
}.AsQueryable();
var mockSet = new Mock<DbSet<UserStock>>();
mockSet.Setup(m => m.FindAsync(It.IsAny<object[]>())).Returns<object[]>((key) => Task.FromResult(data.SingleOrDefault(us => us.ID == (int)key[0])));
var mockContext = new Mock<IStockExchangeDbContext>();
mockContext.Setup(c => c.UserStocks).Returns(mockSet.Object);
var service = new UserStocksController(mockContext.Object);
var result = await service.GetUserStock(0);
Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<UserStock>));
var conResult = result as OkNegotiatedContentResult<UserStock>;
Assert.IsNotNull(conResult);
Assert.AreEqual(data.Single(us => us.ID == 0), conResult.Content);
}
示例6: GetStock
/// <summary>
///
/// </summary>
/// <param name="dataAreaId">hrp, bsc, ser</param>
/// <param name="inventLocation">hrp: BELSO, KULSO, HASZNALT|bsc: 7000, 1000, 2100|ser: SER</param>
/// <param name="productId"></param>
/// <param name="stocks"></param>
/// <returns></returns>
private int GetStock(string dataAreaId, string inventLocation, string productId, List<CompanyGroup.Domain.MaintainModule.Stock> stocks)
{
CompanyGroup.Domain.MaintainModule.Stock stock = stocks.SingleOrDefault(x => x.DataAreaId.ToLower().Equals(dataAreaId.ToLower()) && x.InventLocationId.ToUpper().Equals(inventLocation.ToUpper()) && x.ProductId.ToLower().Equals(productId.ToLower()));
return (stock != null) ? stock.Quantity : 0;
}
示例7: Persisted_Messages_Survive_Service_Restart
public void Persisted_Messages_Survive_Service_Restart()
{
var sentMessages = new List<TestMessage1>();
var receivedMessages = new List<TestMessage1>();
var random = new Random();
var texts = ((DayOfWeek[])Enum.GetValues(typeof(DayOfWeek))).Select(x => x.ToString()).ToArray();
var initialTicks = DateTime.Now.AddYears(-20).Ticks;
var finalTicks = DateTime.Now.Ticks;
for (var i = 0; i < 20; i++)
{
sentMessages.Add(new TestMessage1
{
Id = Guid.NewGuid(),
Field1 = texts[random.Next((int) DayOfWeek.Sunday, (int) DayOfWeek.Saturday)],
Field2 = random.Next(1, 100),
Field3 = new DateTime(initialTicks + random.Next(0, (int) (finalTicks - initialTicks)))
});
}
var hostName = Config.Get("hostName", "localhost");
var port = Config.Get("port", 8377);
var baseAddress = Config.Get("baseAddress", "");
var conn = MessageQueue.Connect(hostName, port, baseAddress);
const string queueName = "PersistedQueue1";
using (var host = GetQueueHost(hostName, port, baseAddress))
{
host.Open();
TryCreateQueue(conn, queueName, true, false);
var queue = conn.Get(queueName);
foreach (var message in sentMessages)
queue.Send(message);
}
Thread.Sleep(1000);
using (var host = GetQueueHost(hostName, port, baseAddress))
{
host.Open();
var queue = conn.Get(queueName);
using (var op = queue.StartReceiving<TestMessage1>(100,
receivedMessages.Add, e => { throw e; }))
{
Thread.Sleep(5000);
op.Stop();
Assert.IsFalse(op.Exceptions.Any());
}
}
Assert.AreEqual(sentMessages.Count, receivedMessages.Count);
foreach (var receivedMessage in sentMessages
.Select(x => receivedMessages.SingleOrDefault(y => y.Equals(x))))
{
Assert.IsNotNull(receivedMessage);
}
}
示例8: DeleteUserStock_must_remove_userstock_from_set
public async Task DeleteUserStock_must_remove_userstock_from_set()
{
var data = new List<UserStock>
{
new UserStock {ID = 0, Name = "DAX", User = @"ALIS-PC\Ali"},
new UserStock {ID = 1, Name = "NYSE", User = @"ALIS-PC\Ali"}
}.AsQueryable();
var mockSet = new Mock<DbSet<UserStock>>();
mockSet.Setup(m => m.FindAsync(It.IsAny<object[]>())).Returns<object[]>((key) => Task.FromResult(data.SingleOrDefault(us => us.ID == (int)key[0])));
var mockContext = new Mock<IStockExchangeDbContext>();
mockContext.Setup(m => m.UserStocks).Returns(mockSet.Object);
var service = new UserStocksController(mockContext.Object);
var result = await service.DeleteUserStock(0);
Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<UserStock>));
mockSet.Verify(m => m.Remove(It.IsAny<UserStock>()), Times.Once());
mockContext.Verify(m => m.SaveChangesAsync(), Times.Once());
}
示例9: DeleteUserStock_must_return_Notound_when_count_not_found_userstock_with_provided_id
public async Task DeleteUserStock_must_return_Notound_when_count_not_found_userstock_with_provided_id()
{
var data = new List<UserStock>
{
new UserStock {ID = 0, Name = "DAX"},
new UserStock {ID = 1, Name = "NYSE"}
}.AsQueryable();
var mockSet = new Mock<DbSet<UserStock>>();
mockSet.Setup(m => m.FindAsync(It.IsAny<object[]>())).Returns<object[]>((key) => Task.FromResult(data.SingleOrDefault(us => us.ID == (int)key[0])));
var mockContext = new Mock<IStockExchangeDbContext>();
mockContext.Setup(m => m.UserStocks).Returns(mockSet.Object);
var service = new UserStocksController(mockContext.Object);
var result = await service.DeleteUserStock(3);
Assert.IsInstanceOfType(result, typeof(NotFoundResult));
}
示例10: SetupMarkets
private void SetupMarkets()
{
_USMarketMock = new Mock<IMarket>();
_USMarketMock.Setup(x => x.MarketId).Returns(new MarketId("US"));
_USMarketMock.Setup(x => x.DefaultCurrency).Returns(new Currency("USD"));
_SEKMarketMock = new Mock<IMarket>();
_SEKMarketMock.Setup(x => x.MarketId).Returns(new MarketId("SE"));
_SEKMarketMock.Setup(x => x.DefaultCurrency).Returns(new Currency("SEK"));
var markets = new List<IMarket> {_USMarketMock.Object, _SEKMarketMock.Object};
_marketServiceMock = new Mock<IMarketService>();
_marketServiceMock.Setup(x => x.GetMarket(It.IsAny<MarketId>()))
.Returns((MarketId marketId) => markets.SingleOrDefault(x => x.MarketId == marketId));
}
示例11: SetupContent
private void SetupContent()
{
_variation1 = new VariationContent
{
Code = "code1",
ContentLink = new ContentReference(1),
Categories = new Categories {ContentLink = new ContentReference(11)}
};
_variation2 = new VariationContent
{
Code = "code2",
ContentLink = new ContentReference(2),
Categories = new Categories { ContentLink = new ContentReference(11) }
};
_variations = new List<VariationContent>
{
_variation1, _variation2
};
_contentLoaderMock = new Mock<IContentLoader>();
_contentLoaderMock.Setup(x => x.Get<EntryContentBase>(It.IsAny<ContentReference>()))
.Returns((ContentReference contentReference) => _variations.SingleOrDefault(x => x.ContentLink == contentReference));
}
示例12: SingleOrDefault_abnormal
public void SingleOrDefault_abnormal()
{
// arrange
List<int> list = new List<int>() { 1 };
// act and assert
try
{
list.SingleOrDefault(null);
Assert.Fail();
}
catch (Exception e)
{
Assert.IsTrue(e is ArgumentNullException);
}
}
示例13: ListExtensions_SingleOrDefault_ReturnsSingleItemInList
public void ListExtensions_SingleOrDefault_ReturnsSingleItemInList()
{
var list = new List<Int32>() { 4 };
var result = list.SingleOrDefault();
TheResultingValue(result).ShouldBe(4);
}
示例14: ConditionSingleOrDefaultThrowsInvalidOperationExceptionIfNoMatches
public void ConditionSingleOrDefaultThrowsInvalidOperationExceptionIfNoMatches()
{
IList<Condition> conditions = new List<Condition>() { new Condition() { ConditionId = 1, Description = "New", eBayConditionId = 1000 } };
var result = conditions.SingleOrDefault(c => c.eBayConditionId == 2999);
}
示例15: ListExtensions_SingleOrDefault_ReturnsDefaultValueIfListIsEmpty
public void ListExtensions_SingleOrDefault_ReturnsDefaultValueIfListIsEmpty()
{
var list = new List<Int32>();
var result = list.SingleOrDefault();
TheResultingValue(result).ShouldBe(default(Int32));
}