本文整理汇总了C#中NUnit.Framework.List.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# List.FirstOrDefault方法的具体用法?C# List.FirstOrDefault怎么用?C# List.FirstOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NUnit.Framework.List
的用法示例。
在下文中一共展示了List.FirstOrDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: When_Search_Then_map_returned_entities_to_dtos
public void When_Search_Then_map_returned_entities_to_dtos()
{
//given
var actions = new List<BusinessSafe.Domain.Entities.Action>()
{
new BusinessSafe.Domain.Entities.Action()
{
Id = 123123,
Title = "test title",
AreaOfNonCompliance = "area not compliant",
ActionRequired = "action required test",
TargetTimescale = "do this now",
AssignedTo = new Employee(){Id = Guid.NewGuid(), Forename = "Fred", Surname = "Flintstone"},
DueDate = DateTime.Now.AddDays(10),
Reference = "The Reference",
Category = ActionCategory.Action
}
};
var target = GetTarget();
_actionRepository.Setup(x => x.GetAll()).Returns(actions);
//when
SearchActionRequest request = new SearchActionRequest()
{
ActionPlanId = 123123L
};
var result = target.Search(request);
//then
Assert.That(result.FirstOrDefault().Id, Is.EqualTo(actions.FirstOrDefault().Id));
Assert.That(result.FirstOrDefault().Title, Is.EqualTo(actions.FirstOrDefault().Title));
}
示例2: TestInit
public void TestInit()
{
#region User members
_members = new List<User>
{
new User
{
UserId = 1,
UserName = "lorem"
},
new User
{
UserId = 2,
UserName = "ipsum"
},
new User
{
UserId = 3,
UserName = "dolor"
}
};
#endregion
#region Communities
_communities = new List<Community>
{
new Community
{
Id = 1,
LeaderUserId = 1,
Leader = _members.FirstOrDefault(a => a.UserId == 1),
Members = _members.ToList()
},
new Community
{
Id = 2,
LeaderUserId = 2,
Leader = _members.FirstOrDefault(a => a.UserId == 2),
Members = _members.ToList()
},
new Community
{
Id = 3,
LeaderUserId = 3,
Leader = _members.FirstOrDefault(a => a.UserId == 3),
Members = _members.ToList()
},
};
#endregion
}
示例3: Delete_Group_ReturnsBadRequestResult_Negative
public void Delete_Group_ReturnsBadRequestResult_Negative()
{
int groupId = 1;
List<Enrollment> initialEnrollments = new List<Enrollment>
{
new Enrollment
{
Id = 1,
GroupId = groupId,
UserId = 1,
Date = DateTime.Now
},
new Enrollment
{
Id = 2,
GroupId = groupId,
UserId = 2,
Date = DateTime.Now
},
new Enrollment
{
Id = 3,
GroupId = groupId,
UserId = 3,
Date = DateTime.Now
}
};
GenerateData("1", new[] { "NoRoles" });
Mock<IGroupForListingMapper> groupForListingMapper = new Mock<IGroupForListingMapper>();
Mock<IGroupService> groupService = new Mock<IGroupService>();
Mock<IEnrollmentService> enrollmentService = new Mock<IEnrollmentService>();
Mock<IWordProgressService> wordProgressService = new Mock<IWordProgressService>();
Mock<IWordSuiteService> wordsuiteService = new Mock<IWordSuiteService>();
Mock<ICourseService> courseService = new Mock<ICourseService>();
Mock<ICourseForGroupMapper> courseMapper = new Mock<ICourseForGroupMapper>();
Mock<IGroupMapper> groupMapper = new Mock<IGroupMapper>();
GroupController groupController = new GroupController(groupService.Object, groupForListingMapper.Object,
enrollmentService.Object, wordProgressService.Object, wordsuiteService.Object, courseService.Object,
courseMapper.Object, groupMapper.Object);
enrollmentService.Setup(x => x.GetByGroupId(groupId)).Returns(initialEnrollments);
wordProgressService.Setup(x => x.RemoveProgressesForEnrollment(
It.Is<int>(id => initialEnrollments.FirstOrDefault(e => e.Id == id) != null))).Returns(true);
wordsuiteService.Setup(x => x.RemoveWordSuitesForEnrollment(
It.Is<int>(id => initialEnrollments.FirstOrDefault(e => e.Id == id) != null))).Returns(true);
groupService.Setup(x => x.DeleteById(groupId)).Returns(false);
var actual = groupController.Delete(groupId);
Assert.IsInstanceOf(typeof(BadRequestErrorMessageResult), actual);
}
示例4: GetFindPackageResult
private static string GetFindPackageResult(string url, List<Package> packages, bool latestVersion)
{
string apiUri = url.Replace("&", "&");
Uri uri = new Uri(apiUri);
DateTime updated = packages.Any()
? packages.OrderByDescending(p => p.DateUpdated).First().DateUpdated
: DateTime.UtcNow;
entry[] entries = latestVersion
? new[] { PackageDetails.GetPackageEntry(packages.FirstOrDefault(p => p.LatestVersion), uri) }
: packages.Select(p => PackageDetails.GetPackageEntry(p, uri)).ToArray();
feed feed = new feed
{
@base = InvokeUrl + "/",
id = WebUtility.HtmlDecode(uri.ToString()),
title = new feedTitle("FindPackagesById"),
updated = updated,
link = new feedLink("FindPackagesById", "FindPackagesById"),
entry = entries
};
XmlSerializer serializer = new XmlSerializer(typeof(feed));
MemoryStream ms = new MemoryStream();
serializer.Serialize(ms, feed);
ms.Position = 0;
return new StreamReader(ms).ReadToEnd();
}
示例5: b_deck_after_Shuffle_has_52_card_unordered
public void b_deck_after_Shuffle_has_52_card_unordered()
{
_deck.Shuffle();
_cards = _deck.Cards;
_cards.FirstOrDefault().Value.Should().Not.Be.EqualTo( new Value(SuitEnum.Hearts, RankEnum.Ace));
_cards.LastOrDefault().Value.Should().Not.Be.EqualTo(new Value(SuitEnum.Clubs, RankEnum.King));
}
示例6: GetAllSheetsTest
public void GetAllSheetsTest()
{
var repo = new TimeTrackerRepository();
List<Timesheet> timesheets = new List<Timesheet>();
timesheets = repo.GetAllTimeSheets(6);
var timesheet = timesheets.FirstOrDefault(x=>x.TimesheetId==22);
Assert.AreEqual(timesheet.EntryType, "Timesheet");
Assert.AreEqual(4, timesheets.Count);
}
示例7: GetMessageDetailTest
public void GetMessageDetailTest()
{
var quote = new Quote("SPPI");
var listQuotes = new List<Quote>();
listQuotes.Add(quote);
Stock.StockFetcher.YahooStockEngine.Fetch(listQuotes);
var result = MessageDetail.GetMessageDetail(listQuotes.FirstOrDefault());
Messaging.SendEmailGmail("Stock alert", result);
//Assert.Fail();
}
示例8: ShouldCreateTaskbarIcon
public void ShouldCreateTaskbarIcon()
{
// Arrange
var icon = new Icon(FlowMate.TrayIconFileName);
var trayIcons = new List<TaskbarIcon>();
var systemTray = new SystemTray(trayIcons);
// Act
systemTray.Add(icon);
// Assert
Assert.AreEqual(icon, trayIcons.FirstOrDefault().Icon);
}
示例9: First_or_default_returns_the_default_value_of_the_type_if_the_collection_is_empty
public void First_or_default_returns_the_default_value_of_the_type_if_the_collection_is_empty()
{
var strings = new List<string>();
var firstString = strings.FirstOrDefault();
var ints = new List<int>();
var firstInt = ints.FirstOrDefault();
Assert.AreEqual(0, firstInt);
Assert.AreEqual(default(int), firstInt);
Assert.IsNull(firstString);
Assert.AreEqual(default(string), firstString);
}
示例10: Can_remove_duplicatedQuantities
public void Can_remove_duplicatedQuantities()
{
var tierPrices = new List<TierPrice>();
tierPrices.Add(new TierPrice
{
//will be removed
Id = 1,
Price = 150,
Quantity = 1
});
tierPrices.Add(new TierPrice
{
//will stay
Id = 2,
Price = 100,
Quantity = 1
});
tierPrices.Add(new TierPrice
{
//will stay
Id = 3,
Price = 200,
Quantity = 3
});
tierPrices.Add(new TierPrice
{
//will stay
Id = 4,
Price = 250,
Quantity = 4
});
tierPrices.Add(new TierPrice
{
//will be removed
Id = 5,
Price = 300,
Quantity = 4
});
tierPrices.Add(new TierPrice
{
//will stay
Id = 6,
Price = 350,
Quantity = 5
});
tierPrices.RemoveDuplicatedQuantities();
tierPrices.FirstOrDefault(x => x.Id == 1).ShouldBeNull();
tierPrices.FirstOrDefault(x => x.Id == 2).ShouldNotBeNull();
tierPrices.FirstOrDefault(x => x.Id == 3).ShouldNotBeNull();
tierPrices.FirstOrDefault(x => x.Id == 4).ShouldNotBeNull();
tierPrices.FirstOrDefault(x => x.Id == 5).ShouldBeNull();
tierPrices.FirstOrDefault(x => x.Id == 6).ShouldNotBeNull();
}
示例11: CreatesNewListOfTournamentEvents
public void CreatesNewListOfTournamentEvents()
{
//Arrange
persistedTournaments = new List<Tournament>();
persistedTournamentEvents = new List<TournamentEvent>();
this.webRepository = BuildWebRepository.Create()
.HasSingleAPITennisTourCalendar();
this.webRepositoryProvider = BuildWebRepositoryProvider.Create()
.ReturnsSpecificWebRepository(webRepository.Object);
this.fixtureRepository = BuildFixtureRepository.Create()
.HasNoPersistedTournamentEvent()
.HasAPersistedCompetition()
.CanAddTournamentEvent(persistedTournamentEvents)
.CanAddTournament(persistedTournaments);
//Act
var fixtureStategy = new TestableTennisFixtureStrategy(this.fixtureRepository,
this.storedProcRepository, this.webRepositoryProvider);
var tournamentEvents = fixtureStategy.UpdateTournamentEvents();
var tournamentEvent = tournamentEvents.FirstOrDefault();
var persistedTournament = persistedTournaments.FirstOrDefault();
var persistedTournamentEvent = persistedTournamentEvents.FirstOrDefault();
//Assert
//Returned tournament event
Assert.AreEqual(1, tournamentEvents.Count());
Assert.AreEqual("Tóurnament Name (2013)", tournamentEvent.EventName);
Assert.AreEqual(new DateTime(2012, 12, 31), tournamentEvent.StartDate);
Assert.AreEqual(new DateTime(2013, 01, 06), tournamentEvent.EndDate);
Assert.IsTrue(tournamentEvent.TournamentInProgress);
Assert.IsFalse(tournamentEvent.TournamentCompleted);
//Persisted tournament event
Assert.AreEqual(1, persistedTournamentEvents.Count());
Assert.AreSame(tournamentEvent, persistedTournamentEvent);
//Persisted tournament
Assert.AreEqual(1, persistedTournaments.Count());
Assert.AreEqual("Tóurnament Name", persistedTournament.TournamentName);
Assert.AreEqual("tournament-name", persistedTournament.Slug);
}
示例12: CanMoveTo
/// <summary>
/// 駒の各移動先に対して、その手が指せるのかどうかをチェックします。
/// </summary>
private void CanMoveTo(Board board, BoardMove move,
List<Tuple<Square, bool>> availables)
{
for (var file = 1; file <= Board.BoardSize; ++file)
{
for (var rank = 1; rank <= Board.BoardSize; ++rank)
{
var sq = new Square(file, rank);
var avail = availables.FirstOrDefault(_ => _.Item1 == sq);
move.DstSquare = sq;
if (avail != null)
{
if (avail.Item2)
{
// 成りが必須の場合
move.IsPromote = false;
Assert.False(board.CanMove(move));
move.IsPromote = true;
Assert.True(board.CanMove(move));
}
else
{
// 成りが必須でない場合
move.IsPromote = false;
Assert.True(board.CanMove(move));
move.IsPromote = true;
Assert.AreEqual(Board.CanPromote(move), board.CanMove(move));
}
}
else
{
// そもそも移動できる場所ではない
move.IsPromote = false;
Assert.False(board.CanMove(move));
move.IsPromote = true;
Assert.False(board.CanMove(move));
}
}
}
}
示例13: RecalculateProjectByWeightTest
public void RecalculateProjectByWeightTest()
{
var draws = new List<Drawing>
{
new Drawing {Id = 1, Count = 1, CountAll = 1, Weight = 1, WeightAll = 1},
new Drawing {Id = 2, Count = 1, CountAll = 1, Weight = 1, WeightAll = 2},
new Drawing {Id = 3, Count = 1, CountAll = 1, Weight = 7, WeightAll = 7},
new Drawing {Id = 4, ParentId = 3, Count = 2, CountAll = 2, Weight = 2, WeightAll = 4},
new Drawing {Id = 5, ParentId = 4, Count = 1, CountAll = 2, Weight = 1, WeightAll = 2},
new Drawing {Id = 6, ParentId = 4, Count = 2, CountAll = 4, Weight = 5, WeightAll = 20},
new Drawing {Id = 7, ParentId = 3, Count = 2, CountAll = 2, Weight = 5, WeightAll = 10},
};
var dm = new Mock<IClassDataManager<Drawing>>();
dm.Setup(x => x.GetListCollection()).Returns(draws);
dm.Setup(x => x.GetListCollection(It.IsAny<Func<Drawing, bool>>())).Returns<Func<Drawing, bool>>(x => draws.Where(x).ToList());
dm.Setup(x => x.GetDocument(It.IsAny<int?>())).Returns<int?>(x => draws.FirstOrDefault(y => y.Id == x));
var hellper = new DrawingsCalculateHelper();
draws[4].Weight = 7;
Assert.DoesNotThrow(() => hellper.RecalculateProjectByWeight(draws[4], dm.Object));
Assert.AreEqual(44, draws[2].WeightAll);
Assert.AreEqual(1, draws[0].WeightAll);
Assert.AreEqual(34, draws[3].WeightAll);
}
示例14: Index_GivenAllUsersReturnedFromRepository_ShouldReturnViewWithMapModel
public void Index_GivenAllUsersReturnedFromRepository_ShouldReturnViewWithMapModel()
{
//---------------Set up test pack-------------------
var borrowersItem = new BorrowerItemBuilder()
.WithRandomProps()
.WithDateReturnedAsNull()
.Build();
var borrowersItems = new List<BorrowersItem>() { borrowersItem };
var repository = Substitute.For<IBorrowerItemRepository>();
repository.GetAll().Returns(borrowersItems);
var borrowerItemRowViewModels = new List<BorrowerItemRowViewModel> { new BorrowerItemRowViewModel() };
var mappingEngine =Substitute.For<IMappingEngine>();
mappingEngine.Map<IEnumerable<BorrowerItemRowViewModel>>(borrowersItems)
.Returns(borrowerItemRowViewModels);
var borrowerItemRowViewModel = borrowerItemRowViewModels.FirstOrDefault();
borrowerItemRowViewModel.Id = borrowersItem.Id;
borrowerItemRowViewModel.BorrowerId = borrowersItem.BorrowerId;
borrowerItemRowViewModel.ItemDescription = borrowersItem.Item.Description;
borrowerItemRowViewModel.DateBorrowed = borrowersItem.DateBorrowed;
borrowerItemRowViewModel.DateReturned = borrowersItem.DateReturned;
var controller = CreateBuilder()
.WithBorrowerItemRepository(repository)
.WithMappingEngine(mappingEngine)
.Build();
//---------------Assert Precondition----------------
//---------------Execute Test ----------------------
var result = controller.Index() as ViewResult;
//---------------Test Result -----------------------
Assert.IsNotNull(result);
var viewModels = result.Model as IEnumerable<BorrowerItemRowViewModel>;
CollectionAssert.AreEqual(borrowerItemRowViewModels, viewModels);
}
示例15: LoadObject_With_IEnumerableProperty
public void LoadObject_With_IEnumerableProperty()
{
var @object = new ClassWithSimpleClassList();
@object.Id = 1;
@object.Objects = new List<SimpleClass>
{
new SimpleClass { Id = 1, Name = "object 1" },
new SimpleClass { Id = 2, Name = "object 2" },
new SimpleClass { Id = 3, Name = "object 3" },
};
var newList = new List<SimpleClass>
{
new SimpleClass { Id = 1, Name = "object 1 new" },
new SimpleClass { Id = 2, Name = "object 2 new" },
new SimpleClass { Id = 3, Name = "object 3 new" },
};
_objectInspector.LoadObject(@object, (value) =>
{
var result = value;
var item = value as SimpleClass;
if (item != null)
{
result = newList.FirstOrDefault(p => p.Id == item.Id);
}
return result;
});
Assert.AreSame(newList[0], @object.Objects[0]);
Assert.AreSame(newList[1], @object.Objects[1]);
Assert.AreSame(newList[2], @object.Objects[2]);
}