public void NameUnitTest() { var mockRepo = new Moq.Mock <IRepository <Person> >(); mockRepo.Setup(aa => aa.AsQueryable()).Returns(PersonList().AsQueryable <Person>()); var controller = new RecordsController(mockRepo.Object); var result = controller.LastName(); Assert.That(result != null); Assert.That(CastIt(result) != null); Assert.That(CastIt(result).First().FirstName == "Bob"); Assert.That(CastIt(result).Last().FirstName == "Lucille"); }
public static void Test_that_ordering_is_correct( ) { var randomProvider = new Random( ); var person1 = PreferencesHelpers.GenerateRandomRecord(randomProvider); var person1A = new PersonColorPreferenceModel( ).PopulateFrom(person1); person1A.LastName = "person1A"; var person2 = PreferencesHelpers.GenerateRandomRecord(randomProvider); var person3 = PreferencesHelpers.GenerateRandomRecord(randomProvider); var person3A = new PersonColorPreferenceModel( ).PopulateFrom(person3); person3A.LastName = "person3A"; var newRecords = new List <PersonColorPreferenceModel> { person1, PreferencesHelpers.GenerateRandomRecord(randomProvider), person1, PreferencesHelpers.GenerateRandomRecord(randomProvider), person2, PreferencesHelpers.GenerateRandomRecord(randomProvider), person2, PreferencesHelpers.GenerateRandomRecord(randomProvider), PreferencesHelpers.GenerateRandomRecord(randomProvider), person3, PreferencesHelpers.GenerateRandomRecord(randomProvider), person3 }.ToSafeList( ); var target = new RecordsController( ); var model = RecordsApiModel.CurrentModel; newRecords.ForEach(newRecord => target.PostLine(UnitTestHelpers.GenerateLine(newRecord, '|'))); model.Add(newRecords); var added = model.PersonColorPreferences.ToSafeList( ); var byBirthDate = target.Birthdate( ).ToSafeList( ); var byGenderLastName = target.Gender( ).ToSafeList( ); var byLastNameDescending = target.LastName( ).ToSafeList( ); var byName = target.Name( ).ToSafeList( ); var byGet = target.Get( ).ToSafeList( ); added.Aggregate((arg1, arg2) => { Assert.True(arg1.Id < arg2.Id); return(arg2); }); byGet.Aggregate((arg1, arg2) => { Assert.True(arg1.Id < arg2.Id); return(arg2); }); byBirthDate.Aggregate((arg1, arg2) => { Assert.True(arg1.DateTimeBirth <= arg2.DateTimeBirth); return(arg2); }); byGenderLastName.Aggregate((arg1, arg2) => { var order = string.Compare(arg1.Gender, arg2.Gender, StringComparison.InvariantCulture); Assert.True(order <= 0); if (order == 0) { var order2 = string.Compare(arg1.LastNameUpper, arg2.LastNameUpper, StringComparison.InvariantCulture); Assert.True(order2 <= 0); } return(arg2); }); byLastNameDescending.Aggregate((arg1, arg2) => { Assert.True(string.Compare(arg1.LastNameUpper, arg2.LastNameUpper, StringComparison.InvariantCulture) >= 0); return(arg2); }); byName.Aggregate((arg1, arg2) => { var order = string.Compare(arg1.LastNameUpper, arg2.LastNameUpper, StringComparison.InvariantCulture); Assert.True(order <= 0); if (order == 0) { var order2 = string.Compare(arg1.FirstNameUpper, arg2.FirstNameUpper, StringComparison.InvariantCulture); Assert.True(order2 <= 0); } return(arg2); }); }