当前位置: 首页>>代码示例>>C#>>正文


C# List.SingleOrDefault方法代码示例

本文整理汇总了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());
     }
 }
开发者ID:JWroe,项目名称:CompendiumImport,代码行数:11,代码来源:CreatureConverterTest.Tools.cs

示例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());
     }
 }
开发者ID:JWroe,项目名称:CompendiumImport,代码行数:12,代码来源:CreatureConverterTest.Tools.cs

示例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));
        }
开发者ID:Goblinftw,项目名称:Upteka,代码行数:20,代码来源:ServiceTest.cs

示例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;
        }
开发者ID:hoonzis,项目名称:PexMolesAndFakes,代码行数:22,代码来源:AccountServiceTest.cs

示例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);
        }
开发者ID:MGTSr,项目名称:StockExchange,代码行数:22,代码来源:UserStocksControllerTests.cs

示例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;
        }
开发者ID:juaqaai,项目名称:CompanyGroup.ServiceLayers,代码行数:14,代码来源:ProductRepositoryTest.cs

示例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);
            }
        }
开发者ID:kusl,项目名称:rudymq,代码行数:66,代码来源:PersistedAndTransactionalMessagesTests.cs

示例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());
        }
开发者ID:MGTSr,项目名称:StockExchange,代码行数:21,代码来源:UserStocksControllerTests.cs

示例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));
        }
开发者ID:MGTSr,项目名称:StockExchange,代码行数:19,代码来源:UserStocksControllerTests.cs

示例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));
        }
开发者ID:javafun,项目名称:Quicksilver,代码行数:16,代码来源:PromotionServiceTests.cs

示例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));
        }
开发者ID:javafun,项目名称:Quicksilver,代码行数:25,代码来源:PromotionServiceTests.cs

示例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);
            }
        }
开发者ID:jlinqer,项目名称:jLinqer,代码行数:16,代码来源:EnumerableAbnormalTest.cs

示例13: ListExtensions_SingleOrDefault_ReturnsSingleItemInList

        public void ListExtensions_SingleOrDefault_ReturnsSingleItemInList()
        {
            var list = new List<Int32>() { 4 };

            var result = list.SingleOrDefault();

            TheResultingValue(result).ShouldBe(4);
        }
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:8,代码来源:ListExtensionsTest.cs

示例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);
        }
开发者ID:craigshaw,项目名称:SoldOut,代码行数:6,代码来源:ConditionExtensionTests.cs

示例15: ListExtensions_SingleOrDefault_ReturnsDefaultValueIfListIsEmpty

        public void ListExtensions_SingleOrDefault_ReturnsDefaultValueIfListIsEmpty()
        {
            var list = new List<Int32>();

            var result = list.SingleOrDefault();

            TheResultingValue(result).ShouldBe(default(Int32));
        }
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:8,代码来源:ListExtensionsTest.cs


注:本文中的Microsoft.VisualStudio.TestTools.UnitTesting.List.SingleOrDefault方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。