本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.AsQueryable方法的典型用法代码示例。如果您正苦于以下问题:C# List.AsQueryable方法的具体用法?C# List.AsQueryable怎么用?C# List.AsQueryable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.AsQueryable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StudentControllerGetSingleRecordTest
public void StudentControllerGetSingleRecordTest()
{
//arrange
var mockRepository = Mock.Create<IRepository<Student>>();
var studentToAdd = new Student()
{
Age = 10,
Grade = 4,
FirstName = "Nikolay",
LastName = "Kostadinov",
};
IList<Student> studentEntities = new List<Student>();
studentEntities.Add(studentToAdd);
Mock.Arrange(() => mockRepository.All())
.Returns(() => studentEntities.AsQueryable());
var studentController = new StudentController(mockRepository);
var studentModels = studentEntities.AsQueryable().Select(StudentDetailedModel.FormStudent).First();
var expected = studentModels;
//act
var actual = studentController.Get(0);
// assert
Assert.AreEqual(expected.FirstName, actual.FirstName);
}
示例2: ExecuteDynamicQueryObject
public void ExecuteDynamicQueryObject()
{
var source = new List<Product>
{
new Product {Name = "NPatterns", Version = 1.2},
new Product {Name = "NPatterns.Messaging.IoC",Version = 1.1},
new Product {Name = "NPatterns.ObjectRelational.EF",Version = 1.0},
new Product {Name = null,Version = 0}
};
var query = new QueryObject(new DynamicQueryObjectExecutor());
query.Add(new Criteria { Field = "Name", Operator = CriteriaOperator.IsNotNull });
var criteriaGroup = new CriteriaGroup { Operator = CriteriaGroupOperator.Or };
criteriaGroup.Criterias.Add(new Criteria { Field = "Name", Operator = CriteriaOperator.IsEqualTo, Value = "npatterns" });
criteriaGroup.Criterias.Add(new Criteria { Field = "Name", Operator = CriteriaOperator.EndsWith, Value = "ioc" });
query.Add(criteriaGroup);
query.Add(new SortDescription { Field = "Version", Direction = SortDirection.Ascending });
var result = query.Execute(source.AsQueryable()).ToList();
Assert.AreEqual(2, result.Count);
Assert.IsTrue(result[0].Version < result[1].Version);
query.Add(new Criteria { Field = "Version", Operator = CriteriaOperator.IsEqualTo, Value = 1.0 }, CriteriaGroupOperator.Or);
var result2 = query.Execute(source.AsQueryable()).ToList();
Assert.AreEqual(3, result2.Count);
}
示例3: TestPatientsAndAppointments
/// <summary>
/// Tests patient and appointment lists.
/// </summary>
/// <param name="appts">List of appointments to substitute in our mockup.</param>
/// <param name="patients">List of patients to substitute in our mockup.</param>
/// <param name="compare_date">The date to compare in our mockup.</param>
/// <returns></returns>
private static IEnumerable<Transaction> TestPatientsAndAppointments(
List<appointment_data> appts,
List<patient_data> patients,
DateTime compare_date)
{
var mock_appts = new Mock<DbSet<appointment_data>>();
mock_appts.As<IQueryable<appointment_data>>().Setup(m => m.Provider)
.Returns(appts.AsQueryable<appointment_data>().Provider);
mock_appts.As<IQueryable<appointment_data>>().Setup(m => m.Expression)
.Returns(appts.AsQueryable<appointment_data>().Expression);
mock_appts.As<IQueryable<appointment_data>>().Setup(m => m.ElementType)
.Returns(appts.AsQueryable<appointment_data>().ElementType);
mock_appts.As<IQueryable<appointment_data>>().Setup(m => m.GetEnumerator())
.Returns(appts.AsQueryable<appointment_data>().GetEnumerator());
var mock_patients = new Mock<DbSet<patient_data>>();
mock_patients.As<IQueryable<patient_data>>().Setup(m => m.Provider)
.Returns(patients.AsQueryable<patient_data>().Provider);
mock_patients.As<IQueryable<patient_data>>().Setup(m => m.Expression)
.Returns(patients.AsQueryable<patient_data>().Expression);
mock_patients.As<IQueryable<patient_data>>().Setup(m => m.ElementType)
.Returns(patients.AsQueryable<patient_data>().ElementType);
mock_patients.As<IQueryable<patient_data>>().Setup(m => m.GetEnumerator())
.Returns(patients.AsQueryable<patient_data>().GetEnumerator());
var fake_entities = new Mock<broadlyEntities>();
fake_entities.Setup(c => c.appointment_data).Returns(mock_appts.Object);
fake_entities.Setup(c => c.patient_data).Returns(mock_patients.Object);
IEnumerable<Transaction> transactions = DataSource.GetTransactions(compare_date, fake_entities.Object);
Assert.IsNotNull(transactions);
Assert.IsTrue(transactions is IQueryable);
Assert.IsTrue(transactions is IQueryable<Transaction>);
foreach (Transaction transaction in transactions)
{
// There is an email
Assert.IsTrue(!string.IsNullOrEmpty(transaction.PatientEmail));
// The appoinment time matches
Assert.IsTrue(transaction.AppointmentTime == compare_date);
// There is a transaction with this Id
appointment_data appt = appts.Find(x => x.appointment_id == transaction.AppointmentId);
Assert.IsNotNull(appt);
// There is a patient with the appt's Id
patient_data patient = patients.Find(x => x.patient_id == appt.patient_id);
Assert.IsNotNull(patient);
// Check content
Assert.IsTrue(transaction.AppointmentId == appt.appointment_id);
Assert.IsTrue(transaction.AppointmentTime == appt.scheduled);
Assert.IsTrue(appt.status == "completed");
Assert.IsTrue(transaction.PatientFirstName == patient.first_name);
Assert.IsTrue(transaction.PatientLastName == patient.last_name);
Assert.IsTrue(transaction.PatientId == patient.patient_id);
Assert.IsTrue(transaction.PatientPhone == patient.phone);
}
return transactions;
}
示例4: EnsureICanDeleteLessonTest
public void EnsureICanDeleteLessonTest()
{
//Arrange
List<Lesson> my_list = new List<Lesson>();
Mock<CContext> mock_context = new Mock<CContext>();
Mock<DbSet<Teacher>> mock_teacher = new Mock<DbSet<Teacher>>();
Mock<DbSet<Student>> mock_student = new Mock<DbSet<Student>>();
Mock<DbSet<Payment>> mock_payment = new Mock<DbSet<Payment>>();
Mock<DbSet<Lesson>> mock_lesson = new Mock<DbSet<Lesson>>();
var data = my_list.AsQueryable();
mock_lesson.As<IQueryable<Lesson>>().Setup(m => m.Provider).Returns(data.Provider);
mock_lesson.As<IQueryable<Lesson>>().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());
mock_lesson.As<IQueryable<Lesson>>().Setup(m => m.ElementType).Returns(data.ElementType);
mock_lesson.As<IQueryable<Lesson>>().Setup(m => m.Expression).Returns(data.Expression);
mock_lesson.Setup(m => m.Add(It.IsAny<Lesson>())).Callback((Lesson b) => my_list.Add(b));
mock_lesson.Setup(m => m.Remove(It.IsAny<Lesson>())).Callback((Lesson b) => my_list.Remove(b));
mock_context.Setup(m => m.Lessons).Returns(mock_lesson.Object);
Repository Repo = new Repository(mock_context.Object);
my_list.Add(new Lesson { LessonId = 1, Title = "Private" });
//Act
bool Success = Repo.DeleteLesson(1);
//Assert
Assert.AreEqual(0, Repo.Context.Lessons.Count());
}
示例5: DeleteMethodShouldReturnProperAnswerModel
public void DeleteMethodShouldReturnProperAnswerModel()
{
var user3 = new ApplicationUser() { Id = "3asdfasdfgahasre", UserName = "UserName3" };
var cat = new Category() { CategoryId = 10, AgeRating=AgeRating.Mature, Name="Category 1" };
List<ApplicationUser> users = new List<ApplicationUser> { new ApplicationUser() { Id = "1asdfasdfgahasre" } };
var quest = new Question() { QuestionId = 10, Creator = user3, Category = cat, Title = "Q Title", Text = "Q Text", IsApproved = true, DateAsked = DateTime.Now };
var list = new List<Answer>();
for (int i = 1; i < 6; i++)
{
list.Add(new Answer()
{
AnswerId = i,
Comment = "Comment" + i,
User = new ApplicationUser() { Id = "1asdfasdfgahasre", UserName = "UserName1" },
DateAnswered = DateTime.Now,
Question = quest,
IsRead = true, IsReported=true, IsVoted=false,
});
}
var ansRepoMock = new Mock<IRepository<Answer>>();
ansRepoMock.Setup(ur => ur.All()).Returns(list.AsQueryable());
var uofMock = new Mock<IUowData>();
uofMock.Setup(x => x.Answers).Returns(() => { return ansRepoMock.Object; });
var controller = new AnswersController(uofMock.Object);
var viewResult = controller.Delete(2) as ViewResult;
var model = viewResult.Model;
var modelAsAM = model as AnswerView;
Assert.IsNotNull(modelAsAM, "Delete action returns null.");
Assert.IsNotNull(model, "The model is null.");
}
示例6: ToGoogleDataTable
public void ToGoogleDataTable()
{
var list = new List<Custom1>();
list.Add(new Custom1()
{
Property1 = "foo1",
Property2 = 7
});
list.Add(new Custom1()
{
Property1 = "foo2",
Property2 = 14
});
list.Add(new Custom1()
{
Property1 = "foo3",
Property2 = 21
});
var table = list.AsQueryable().ToGoogleDataTable();
Assert.IsNotNull(table);
Assert.AreEqual(3, table.Rows.Count);
Assert.AreEqual(2, table.Columns.Count);
var firstCol = table.Columns.First();
Assert.AreEqual("Property1", firstCol.Id);
Assert.AreEqual(ColumnDataType.String, firstCol.DataType);
var firstRow = table.Rows.First();
Assert.AreEqual(2, firstRow.Cells.Count);
Assert.AreEqual("foo1", firstRow.Cells.First().Value);
}
示例7: Before_Each_Test
public void Before_Each_Test()
{
console = MockRepository.GenerateMock<IConsoleFacade>();
repository = MockRepository.GenerateMock<IRepository<GameObject>>();
player = MockRepository.GenerateMock<IPlayer>();
dbPlayer = new GameObject() { GameObjectId = 3, Location = dbHallway, Location_Id = 8, Description = "Just some dude." };
player.Stub(qq => qq.Id).Return(3);
dbHallway = new GameObject() { Name = "Hallway", Description = " It's a hallway", GameObjectId = 8 };
dbBall = new GameObject() { Name = "Ball", Description = "A shiny rubber ball", Location = dbPlayer, Location_Id = 3 };
dbRing = new GameObject() { Name = "Ring", Description = "A simple gold ring", Location = dbHallway, Location_Id = 8 };
dbExit = new GameObject() {Name = "Exit", Description ="", Location= dbHallway, Location_Id = 8, GameObjectId = 16, Type = "Exit", Destination = 8 };
dbPlayer.Inventory.Add(dbBall);
dbHallway.Inventory.Add(dbPlayer);
dbHallway.Inventory.Add(dbRing);
dbHallway.Inventory.Add(dbExit);
dbList = new List<GameObject>() { dbPlayer, dbBall, dbRing, dbExit, dbHallway };
repository.Stub(qq => qq.AsQueryable()).Return(dbList.AsQueryable());
exit = new ExitAlias() { AliasId = 2, ExitId = 16, Alais = "North" };
exit2 = new ExitAlias() { AliasId = 2, ExitId = 16, Alais = "Hall" };
dbExit.ExitAliases.Add(exit);
dbExit.ExitAliases.Add(exit2);
aliasList = new List<ExitAlias> { exit, exit2 };
}
示例8: AddWhenAssignmentIsValidShouldAddAssignment
public void AddWhenAssignmentIsValidShouldAddAssignment()
{
var repository = Mock.Create<ITwsData>();
var assignmentEntity = Entities.GetValidAssignment();
var teamWorkEntity = Entities.GetValidTeamWork();
teamWorkEntity.Assignments.Add(assignmentEntity);
IList<TeamWork> teamworkEntities = new List<TeamWork>();
teamworkEntities.Add(teamWorkEntity);
IList<Assignment> assignmentEntities = new List<Assignment>();
assignmentEntities.Add(assignmentEntity);
Mock.Arrange(() => repository.Assignments.All())
.Returns(() => assignmentEntities.AsQueryable());
Mock.Arrange(() => repository.TeamWorks.All())
.Returns(() => teamworkEntities.AsQueryable());
var controller = new AssignmentController(repository);
var assignmentModels = controller.ByTeamwork(0);
var negotiatedResult = assignmentModels as OkNegotiatedContentResult<IQueryable<AssignmentModel>>;
Assert.IsNotNull(negotiatedResult);
Assert.AreEqual<string>(assignmentEntity.Name, negotiatedResult.Content.FirstOrDefault().Name);
}
示例9: Can_Get_Details
public void Can_Get_Details()
{
// Arrange
// - create the mock repository
Mock<IEventStore> mock = new Mock<IEventStore>();
var allEvents = new List<IEvent<IIdentity>>()
{
new ProductAddedToOrder() {Id = new OrderId(777), Date = DateTime.Now, Version = 1},
new ProductAddedToOrder() {Id = new OrderId(777), Date = DateTime.Now, Version = 3},
new ProductAddedToOrder() {Id = new OrderId(777), Date = DateTime.Now, Version = 5}
};
mock.Setup(m => m.GetEventsForAggregate<IIdentity>(It.IsAny<IIdentity>())).Returns(allEvents.AsQueryable());
// create instance of a controller
EventViewerController controller = new EventViewerController(mock.Object);
// Action: try to find event with Version = 3
string result = (string)((ViewResultBase)controller.Details("777", 3)).ViewData["EventDetails"];
// Assert
Assert.IsTrue(result.Length > 0);
Assert.IsTrue(result.Contains("\"Version\": 3,"));
}
示例10: AddBug_WhenBugTextIsValid_ShouldBeAddedToRepoWithLogDateAndStatusPending
public void AddBug_WhenBugTextIsValid_ShouldBeAddedToRepoWithLogDateAndStatusPending()
{
var bugs = new List<Bug>();
var bug = new BugModel()
{
Text = "NEW TEST BUG"
};
var data = Mock.Create<IBugLoggerData>();
Mock.Arrange(() => data.Bugs.All())
.Returns(() => bugs.AsQueryable());
Mock.Arrange(() => data.SaveChanges())
.DoInstead(() => bugs.Add(new Bug() { Text = "NEW TEST BUG" }));
var controller = new BugsController(data);
this.SetupController(controller);
//act
controller.PostBug(bug);
//assert
Assert.AreEqual(data.Bugs.All().Count(), 1);
var bugInDb = data.Bugs.All().FirstOrDefault();
Assert.AreEqual(bug.Text, bugInDb.Text);
Assert.IsNotNull(bugInDb.LogDate);
Assert.AreEqual(Status.Pending, bugInDb.Status);
}
示例11: Notification_On_Event_Cancelled
public void Notification_On_Event_Cancelled()
{
//Arrange
var theHost = new Person { PersonId = 3, FirstName = "Matt", LastName = "Harmin" };
var peopleList = new List<Person>
{
new Person {PersonId = 1, FirstName = "Joe", LastName = "Smith" },
new Person {PersonId = 2, FirstName = "Sally", LastName = "Hardy" },
};
var theEvent = new Event
{
EventId = 1,
Title = "My Test Event",
StartDate = DateTime.Now,
Coordinator = theHost,
RegisteredInvites = peopleList
};
A.CallTo(() => EventRepo.GetAll()).Returns(new List<Event> { theEvent }.AsQueryable());
A.CallTo(() => PersonRepo.GetAll()).Returns(peopleList.AsQueryable());
A.CallTo(() => InvitationRepo.GetAll()).Returns(new List<PendingInvitation>().AsQueryable());
//Act
var notification = NotifyService.GetNotificationForEventCancelled(theEvent.EventId, 1, 0);
//Assert
string hostName = string.Format("{0} {1}", theHost.FirstName, theHost.LastName);
string expectedMessage = string.Format(Constants.MESSAGE_CANCELLED_TEMPLATE, theEvent.Title,
hostName);
Assert.AreEqual(notification.Title, Constants.MESSAGE_CANCELLED_TITLE);
Assert.AreEqual(notification.Message, expectedMessage);
}
示例12: Notification_On_Attendee_Removed
public void Notification_On_Attendee_Removed()
{
//Arrange
var theHost = new Person { PersonId = 3, FirstName = "Matt", LastName = "Harmin" };
var thePerson = new Person{PersonId = 1, FirstName = "Joe", LastName = "Smith", NotifyWithFacebook = true, NotifyWithEmail = false};
var theEvent = new Event { EventId = 1, Title = "My Test Event", StartDate = DateTime.Now, Coordinator = theHost };
var personList = new List<Person>{thePerson};
var eventList = new List<Event>{theEvent};
A.CallTo(() => PersonRepo.GetAll()).Returns(personList.AsQueryable());
A.CallTo(() => EventRepo.GetAll()).Returns(eventList.AsQueryable());
A.CallTo(() => InvitationRepo.GetAll()).Returns(new List<PendingInvitation>().AsQueryable());
//Act
var notification = NotifyService.GetPersonRemovedFromEventNotification(theEvent.EventId, thePerson.PersonId, 0);
//Assert
string hostName = string.Format("{0} {1}", theHost.FirstName, theHost.LastName);
string expectedMessage = string.Format(Constants.MESSAGE_REMOVE_TEMPLATE, hostName,
theEvent.Title, theEvent.StartDate.ToShortDateString(),
theEvent.StartDate.ToShortTimeString());
Assert.AreEqual(notification.SendToEmail, personList[0].NotifyWithEmail);
Assert.AreEqual(notification.SendToFacebook, personList[0].NotifyWithFacebook);
Assert.AreEqual(notification.Title, Constants.MESSAGE_REMOVE_TITLE);
Assert.AreEqual(notification.Message, expectedMessage);
}
示例13: HasPermission_AuthorAccessingControllerPermissionExplicitlyDenied_False
public void HasPermission_AuthorAccessingControllerPermissionExplicitlyDenied_False()
{
// ARRANGE
List<RolePermission> rolePermissions = new List<RolePermission>
{
new RolePermission
{
Controller = "LookupTypes",
Action = string.Empty,
Role = "Author",
IsAllowed = false
},
new RolePermission
{
Controller = "Assets",
Action = "Delete",
Role = "Viewer",
IsAllowed = true
},
};
PermissionHelper permissionHelper = new PermissionHelper(rolePermissions.AsQueryable());
// ACT
bool hasPermission = permissionHelper.HasPermission(EnumHelper.Roles.Author, "LookupTypes", "Delete");
// ASSERT
Assert.IsFalse(hasPermission);
}
示例14: HasPermission_Admin_True
public void HasPermission_Admin_True()
{
// ARRANGE
List<RolePermission> rolePermissions = new List<RolePermission>
{
new RolePermission
{
Controller = "LookupTypes",
Action = "Index",
Role = "Admin"
},
new RolePermission
{
Controller = "LookupTypes",
Action = "Detail",
Role = "Admin"
}
};
PermissionHelper permissionHelper = new PermissionHelper(rolePermissions.AsQueryable());
// ACT
bool hasPermission = permissionHelper.HasPermission(EnumHelper.Roles.Admin, "LookupTypes", "Index");
// ASSERT
Assert.IsTrue(hasPermission);
}
示例15: UserSpecTests
public UserSpecTests()
{
var users = new List<User>();
users.Add(new User("andrebaltieri", "andrebaltieri"));
_users = users.AsQueryable();
}